Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Merge prerelease into master #14

Merged
merged 13 commits into from
May 11, 2020
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Show your Discord friends what you're playing on Wiimmfi!
* Shows game art for popular games
* Support for 2-player games
* Shows Mario Kart Wii room info (if possible)
* Adaptive timeout logic allows for accurate presences while keeping bandwidth and server stress low

### Planned Features
1. Automatic updater
2. Dynamic timeout interval to save bandwidth (See [issue](https://github.com/DismissedGuy/wiimmfi-rpc/issues/10))

## Screenshots
See the [assets](assets) directory for screenshots!
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ branches:
configuration:
- Release

skip_commits:
message: /\[nobuild\]/

environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu1804
Expand Down
6 changes: 4 additions & 2 deletions data/preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"debug": true,
"rpc": {
"oauth_id": "444906848437665803",
"timeout": 15
"min_timeout": 10,
"max_timeout": 30,
"timeout_backoff": 5
},
"config": {
"updates": {
"auto_download": true,
"enable_updates": true,
"auto_install": false,
"release_type": "latest"
}
Expand Down
4 changes: 2 additions & 2 deletions data/version_info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.4.0a",
"release": "03-04-2020",
"version": "1.5.4a",
"release": "26-04-2020",
"git": {
"username": "DismissedGuy",
"repo": "wiimmfi-rpc",
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PyQt5==5.13.1
requests==2.22.0
PyQt5==5.14.2
requests==2.23.0
beautifulsoup4==4.8.1
pypresence==3.3.2
6 changes: 3 additions & 3 deletions rpcgui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import sys
import time
import traceback
from pathlib import Path

from PyQt5 import QtWidgets as Qw
Expand All @@ -10,10 +9,11 @@
import util

# set up logging and add our custom GUI handler
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
formatter = logging.Formatter('[%(asctime)s] %(threadName)s %(levelname)s: %(message)s',
'%H:%M:%S')
logging.getLogger('requests').setLevel(logging.WARNING)

gui_handler = util.GUILoggerHandler()
gui_handler.setLevel(logging.INFO)
Expand All @@ -33,7 +33,7 @@


def on_error(exc_type, exc_value, exc_traceback):
tb = traceback.format_tb(exc_traceback)
tb = exc_traceback.format()

log_path = file_handler.create_error_log(tb)
util.MsgBoxes.error('\n'.join(tb), path=log_path)
Expand Down
22 changes: 13 additions & 9 deletions tabs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ def __init__(self, parent, **params):
def create_update_groupbox(self):
self.update_group = Qw.QGroupBox('Update Settings')

auto_download_label = Qw.QLabel('Enable auto download:')
self.auto_download = Qw.QCheckBox()
self.auto_download.clicked.connect(lambda checked: self.modify_config('auto_download', checked))
enable_updates_label = Qw.QLabel('Auto update check:')
self.enable_updates = Qw.QCheckBox()
self.enable_updates.clicked.connect(lambda checked: self.modify_config('enable_updates', checked))

auto_install_label = Qw.QLabel('Enable auto install:')
auto_install_label = Qw.QLabel('Auto update install:')
self.auto_install = Qw.QCheckBox()
self.auto_install.clicked.connect(lambda checked: self.modify_config('auto_install', checked))

Expand All @@ -60,10 +60,14 @@ def create_update_groupbox(self):

self.release_type.currentTextChanged.connect(lambda text: self.modify_config('release', text))

self.check_updates = Qw.QPushButton('Check for updates now')
self.check_updates.clicked.connect(lambda: self.parent.updater.check_updates())

layout = Qw.QFormLayout()
layout.addRow(auto_download_label, self.auto_download)
layout.addRow(enable_updates_label, self.enable_updates)
layout.addRow(auto_install_label, self.auto_install)
layout.addRow(release_type_label, self.release_type)
layout.addRow(self.check_updates)
self.update_group.setLayout(layout)

def create_danger_groupbox(self):
Expand All @@ -88,12 +92,12 @@ def create_danger_groupbox(self):

def load_settings(self):
debug = bool(self.config.preferences['debug'])
auto_download = bool(self.config.preferences['config']['updates']['auto_download'])
enable_updates = bool(self.config.preferences['config']['updates']['enable_updates'])
auto_install = bool(self.config.preferences['config']['updates']['auto_install'])
release_type = self.config.preferences['config']['updates']['release_type']

self.debug.setChecked(debug)
self.auto_download.setChecked(auto_download)
self.enable_updates.setChecked(enable_updates)
self.auto_install.setChecked(auto_install)

try:
Expand All @@ -108,8 +112,8 @@ def modify_config(self, setting, value):
if setting == 'debug':
preferences['debug'] = value
MsgBoxes.info('You will need to restart the program for the changes to take effect.')
elif setting == 'auto_download':
preferences['config']['updates']['auto_download'] = value
elif setting == 'enable_updates':
preferences['config']['updates']['enable_updates'] = value
elif setting == 'auto_install':
preferences['config']['updates']['auto_install'] = value
elif setting == 'release':
Expand Down
8 changes: 8 additions & 0 deletions util/msgboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def info(msg):
box.setWindowTitle('Information')
box.exec_()

@staticmethod
def warn(msg):
box = Qw.QMessageBox()
box.setIcon(Qw.QMessageBox.Warning)
box.setText(msg)
box.setWindowTitle('Warning')
box.exec_()

@staticmethod
def promptyesno(msg):
box = Qw.QMessageBox()
Expand Down
15 changes: 10 additions & 5 deletions util/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ def __init__(self, thread_manager, config):
self.thread_manager = thread_manager
self.config = config

self.auto_download = config.preferences['config']['updates']['auto_download']
self.enable_updates = config.preferences['config']['updates']['enable_updates']
self.auto_install = config.preferences['config']['updates']['auto_install']
self.release_type = config.preferences['config']['updates']['release_type']

self.current_version = config.version_info['version']

def check_updates(self):
"""Check for and install updates."""
if not self.enable_updates:
return

update_zip = (data_dir / 'update.zip')
if update_zip.is_file(): # local update installed
with update_zip.open('r') as file:
Expand Down Expand Up @@ -91,8 +94,8 @@ def download_update(self):
self.thread_manager.add_thread(download_thread)

def download_available(self, new_version):
if not self.auto_download:
msg = 'A new update was found! Do you want to download it?\n\n'
if not self.auto_install:
msg = 'A new update was found! Do you want to install it?\n\n'
msg += f'New version: {new_version}\n'
msg += f'Current version: {self.current_version}'

Expand Down Expand Up @@ -182,7 +185,7 @@ def execute(self):
return

def download_latest_experimental(self):
url = f'https://api.github.com/repos/{self.github_user}/{self.repo}/zipball/wiimmfi-rpc'
url = f'https://api.github.com/repos/{self.github_user}/{self.repo}/zipball/prerelease'
resp = requests.get(url, headers=github_headers)

try:
Expand Down Expand Up @@ -230,7 +233,9 @@ def download_latest_release(self):
dl = 0
for chunk in resp.iter_content(chunk_size=1024):
if checks.is_bundled():
self.emit_progress(dl // size * 100)
self.emit_progress(round(dl / size * 100))

dl += len(chunk)
buf.write(chunk)

self.update_signals.download_finished.emit(buf)
34 changes: 30 additions & 4 deletions util/wiimmfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from PyQt5 import QtCore as Qc
from bs4 import BeautifulSoup

from .msgboxes import MsgBoxes
from .threading import Thread

game_info_base_url = 'https://wiimmfi.de/game/{game_id}'
Expand Down Expand Up @@ -132,19 +133,28 @@ def __init__(self, config):
super().__init__()

self.config = config
self.timeout_backoff = 0
self.last_player = None
self.run = True
self.assets = None

self.presence = pypresence.Presence(self.config.preferences['rpc']['oauth_id'])
self.presence.connect()
try:
self.presence = pypresence.Presence(self.config.preferences['rpc']['oauth_id'])
self.presence.connect()
except (pypresence.PyPresenceException, ConnectionRefusedError):
MsgBoxes.warn('It appears that your Discord client is not accepting requests. \n'
'Please try restarting it and then run this program again.')
sys.exit()

def execute(self):
self.assets = self.get_asset_list()

# download misc images
self.save_game_art('no_image')

# assign some time for the main thread to finish its things
time.sleep(1)

while True:
if not self.run:
time.sleep(1)
Expand Down Expand Up @@ -181,7 +191,7 @@ def execute(self):
self.last_player.set_mkw_info()
self.set_presence(self.last_player)

time.sleep(self.config.preferences['rpc']['timeout'])
time.sleep(self.config.preferences['rpc']['min_timeout'] + self.timeout_backoff)

def get_online_players(self, game_id):
headers = {
Expand Down Expand Up @@ -260,13 +270,29 @@ def save_game_art(self, game_id):
self.log(logging.INFO, f'Downloaded art for game: {game_id}')

def set_presence(self, player):
if self.timeout_backoff != 0:
self.timeout_backoff = 0

min_timeout = self.config.preferences['rpc']['min_timeout']
self.log(logging.INFO, f'Reverting timeout back to {min_timeout}')

self.presence.update(**player.presence_options(self.config))

def remove_presence(self):
self.presence.clear()

if self.last_player is None:
pass
backoff = self.config.preferences['rpc']['timeout_backoff']
min_timeout = self.config.preferences['rpc']['min_timeout']

current_timeout = min_timeout + self.timeout_backoff
if current_timeout >= self.config.preferences['rpc']['max_timeout']:
return

self.timeout_backoff += backoff
current_timeout = min_timeout + self.timeout_backoff

self.log(logging.INFO, f'Backing off timeout by {backoff}. Now set to {current_timeout}')
else:
self.log(logging.INFO, f'Stopped playing: {self.last_player.game_name}')

Expand Down