Skip to content

Commit 5c17beb

Browse files
committed
Async check for updates
1 parent 3b30aa6 commit 5c17beb

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

.vscode/settings.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// Maybe consider PyLint once all Flake8 linting is fixed
3434
"python.linting.pylintEnabled": false,
3535
"python.linting.flake8Enabled": true,
36-
"python.linting.mypyEnabled": true,
36+
"python.linting.mypyEnabled": false,
3737
// Flake8 is already a pycodestyle wrapper
3838
"python.linting.pycodestyleEnabled": false,
3939
"python.linting.pylintArgs": [
@@ -44,9 +44,6 @@
4444
"python.linting.flake8Args": [
4545
"--max-line-length=120"
4646
],
47-
"python.linting.mypyArgs": [
48-
"--max-line-length=120"
49-
],
5047
"python.formatting.autopep8Args": [
5148
"--max-line-length=120"
5249
],

scripts/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ packaging
2020
pyautogui
2121
PySide6
2222
flake8
23-
mypy
2423
requests
24+
types-requests
2525
#
2626
# Comment this out if you don't want to build AutoSplit.exe:
2727
PyInstaller

src/AutoSplit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import time
1616

1717
from menu_bar import about, VERSION, viewHelp, checkForUpdates
18-
from settings_file import auto_split_directory
18+
from settings_file import auto_split_directory, open_update_checker
1919
from split_parser import BELOW_FLAG, DUMMY_FLAG, PAUSE_FLAG
2020
import capture_windows
2121
import compare
@@ -52,6 +52,7 @@ class AutoSplit(QtWidgets.QMainWindow, design.Ui_MainWindow):
5252
undoSplitSignal = QtCore.pyqtSignal()
5353
pauseSignal = QtCore.pyqtSignal()
5454
afterSettingHotkeySignal = QtCore.pyqtSignal()
55+
updateCheckerWidgetSignal = QtCore.pyqtSignal(str, bool)
5556

5657
def __init__(self, parent=None):
5758
super(AutoSplit, self).__init__(parent)
@@ -167,6 +168,8 @@ def run(self):
167168
self.updateCurrentSplitImage.connect(self.updateSplitImageGUI)
168169
self.afterSettingHotkeySignal.connect(self.afterSettingHotkey)
169170
self.startAutoSplitterSignal.connect(self.autoSplitter)
171+
self.updateCheckerWidgetSignal.connect(lambda latest_version, check_on_open:
172+
open_update_checker(self, latest_version, check_on_open))
170173
self.resetSignal.connect(self.reset)
171174
self.skipSplitSignal.connect(self.skipSplit)
172175
self.undoSplitSignal.connect(self.undoSplit)

src/menu_bar.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
from AutoSplit import AutoSplit
55

66
import os
7-
from PyQt6 import QtWidgets
87

9-
import requests
108
from packaging import version
9+
from PyQt6 import QtWidgets
10+
from PyQt6.QtCore import QThread
11+
from requests.exceptions import RequestException
12+
from simplejson.errors import JSONDecodeError
13+
import requests
1114

1215
import about
1316
import design
@@ -17,11 +20,11 @@
1720
import update_checker
1821

1922
# AutoSplit Version number
20-
VERSION = "1.5.0"
23+
VERSION = "1.6.1"
2124

2225

2326
# About Window
24-
class AboutWidget(QtWidgets.QWidget, about.Ui_aboutAutoSplitWidget):
27+
class __AboutWidget(QtWidgets.QWidget, about.Ui_aboutAutoSplitWidget):
2528
def __init__(self):
2629
super().__init__()
2730
self.setupUi(self)
@@ -31,7 +34,11 @@ def __init__(self):
3134
self.show()
3235

3336

34-
class UpdateCheckerWidget(QtWidgets.QWidget, update_checker.Ui_UpdateChecker):
37+
def about(self: AutoSplit):
38+
self.AboutWidget = __AboutWidget()
39+
40+
41+
class __UpdateCheckerWidget(QtWidgets.QWidget, update_checker.Ui_UpdateChecker):
3542
def __init__(self, latest_version: str, design_window: design.Ui_MainWindow, check_on_open: bool = False):
3643
super().__init__()
3744
self.setupUi(self)
@@ -61,19 +68,30 @@ def doNotAskMeAgainStateChanged(self):
6168
self.checkBoxDoNotAskMeAgain.isChecked())
6269

6370

71+
def open_update_checker(autosplit: AutoSplit, latest_version: str, check_on_open: bool):
72+
autosplit.UpdateCheckerWidget = __UpdateCheckerWidget(latest_version, autosplit, check_on_open)
73+
74+
6475
def viewHelp():
6576
os.system("start \"\" https://github.com/Toufool/Auto-Split#tutorial")
6677

6778

68-
def about(self: AutoSplit):
69-
self.AboutWidget = AboutWidget()
79+
class __CheckForUpdatesThread(QThread):
80+
def __init__(self, autosplit: AutoSplit, check_on_open: bool):
81+
super().__init__()
82+
self.autosplit = autosplit
83+
self.check_on_open = check_on_open
84+
85+
def run(self):
86+
try:
87+
response = requests.get("https://api.github.com/repos/Toufool/Auto-Split/releases/latest")
88+
latest_version = response.json()["name"].split("v")[1]
89+
self.autosplit.updateCheckerWidgetSignal.emit(latest_version, self.check_on_open)
90+
except (RequestException, KeyError, JSONDecodeError):
91+
if not self.check_on_open:
92+
error_messages.checkForUpdatesError()
7093

7194

7295
def checkForUpdates(autosplit: AutoSplit, check_on_open: bool = False):
73-
try:
74-
response = requests.get("https://api.github.com/repos/Toufool/Auto-Split/releases/latest")
75-
latest_version = response.json()["name"].split("v")[1]
76-
autosplit.UpdateCheckerWidget = UpdateCheckerWidget(latest_version, autosplit, check_on_open)
77-
except:
78-
if not check_on_open:
79-
error_messages.checkForUpdatesError()
96+
autosplit.CheckForUpdatesThread = __CheckForUpdatesThread(autosplit, check_on_open)
97+
autosplit.CheckForUpdatesThread.start()

0 commit comments

Comments
 (0)