-
Notifications
You must be signed in to change notification settings - Fork 20
/
update.py
73 lines (54 loc) · 2.15 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import version
import logging
from theme_repo_manager import get_request
PchumLog = logging.getLogger("pchumLogger")
try:
from PyQt6 import QtCore
except ImportError:
PchumLog.debug("PyQt5 fallback (update.py)")
from PyQt5 import QtCore
# thank you mocha for putting up with my bs
# my contributions to this project would be nil if not for u
# i accidentally made a commit named "layout" and i'm NOT letting that be the name
# of the actual final commit for this PR
# I'm gonna change this to get version from the site instead
# so I can set it independently of what's on the repo - Shou
url_version = "https://www.pesterchum.xyz/version.txt"
url_changelog = (
"https://raw.githubusercontent.com/Dpeta/pesterchum-alt-servers/main/CHANGELOG.md"
)
class UpdateChecker(QtCore.QObject):
check_done = QtCore.pyqtSignal()
def __init__(self):
QtCore.QObject.__init__(self)
self.ver_latest = ""
self.ver_curr = ""
self.changelog = ""
self.update_available = False
self.reply_version = None
self.reply_changelog = None
def check(self):
PchumLog.info("Checking for updates...")
self.ver_latest = ""
self.changelog = ""
self.ver_curr = version.buildVersion
self.reply_version = get_request(url_version)
self.reply_changelog = get_request(url_changelog)
self.reply_version.finished.connect(self._on_version_reply)
self.reply_changelog.finished.connect(self._on_changelog_reply)
def _on_version_reply(self):
version_text = bytes(self.reply_version.readAll()).decode(
"utf-8", errors="replace"
)
self.ver_latest = version_text.strip()
buildLatest = self.ver_latest.replace("v", "").split(".")
buildCurrent = self.ver_curr.replace("v", "").split(".")
self.update_available = buildLatest > buildCurrent
if self.changelog:
self.check_done.emit()
def _on_changelog_reply(self):
self.changelog = bytes(self.reply_changelog.readAll()).decode(
"utf-8", errors="replace"
)
if self.ver_latest:
self.check_done.emit()