Skip to content

Commit 38f4c98

Browse files
committed
New update manager endpoints
1 parent 5eb2344 commit 38f4c98

4 files changed

Lines changed: 35 additions & 15 deletions

File tree

config/environments.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ def __init__(self):
1111

1212
DATA_PATH = os.getcwd()
1313
APP_ENV = os.environ.get("APP_ENV", "production")
14+
SOFTWARE_API_BASE = os.environ.get("SOFTWARE_API_BASE", "http://invi.go/api/software")

ui/windows/main_window.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3301,7 +3301,7 @@ def send_email_response(self, response: str):
33013301

33023302
def start_check_for_updates_thread(self):
33033303
check_for_updates_thread = CheckForUpdatesThread(self, __version__)
3304-
check_for_updates_thread.signal.connect(self.update_available_thread_response)
3304+
check_for_updates_thread.update_available.connect(self.update_available_thread_response)
33053305
self.threads.append(check_for_updates_thread)
33063306
check_for_updates_thread.start()
33073307

update_gui.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818
from PyQt6.QtGui import QColor, QPainter
1919
from PyQt6.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
20+
from config.environments import Environment
2021

2122

2223
class DownloadThread(QThread):
@@ -193,7 +194,7 @@ def __init__(self):
193194

194195
self.threads = []
195196

196-
download_thread = DownloadThread(url="http://10.0.0.10:5051/download")
197+
download_thread = DownloadThread(url=f"{Environment.SOFTWARE_API_BASE}/download")
197198
QApplication.setOverrideCursor(Qt.CursorShape.WaitCursor)
198199
self.start_thread(download_thread)
199200

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
import time
2-
32
import requests
43
from PyQt6.QtCore import QThread, pyqtSignal
54

5+
from config.environments import Environment
6+
67

78
class CheckForUpdatesThread(QThread):
8-
signal = pyqtSignal(object, object)
9+
update_available = pyqtSignal(dict)
910

1011
def __init__(self, parent, current_version: str):
11-
self.parent = parent
12+
super().__init__(parent)
1213
self.current_version = current_version
13-
QThread.__init__(self)
14+
self._running = True
15+
16+
def stop(self):
17+
self._running = False
1418

1519
def run(self):
16-
while True:
20+
while self._running:
1721
try:
18-
response_version = requests.get("http://10.0.0.10:5051/version", timeout=10)
19-
response_message = requests.get("http://10.0.0.10:5051/update_message", timeout=10)
20-
if response_version.status_code != 200 or response_message.status_code != 200:
22+
resp = requests.get(
23+
f"{Environment.SOFTWARE_API_BASE}/version",
24+
timeout=10,
25+
)
26+
27+
28+
if resp.status_code != 200:
29+
time.sleep(60)
2130
continue
22-
version = response_version.text
23-
message = response_message.text
24-
if version != self.current_version:
25-
self.signal.emit(version, message)
31+
32+
data = resp.json()
33+
latest_version = data.get("version")
34+
changelog = data.get("changelog")
35+
36+
if not latest_version:
37+
time.sleep(60)
38+
continue
39+
40+
if latest_version != self.current_version:
41+
self.update_available.emit(latest_version, changelog)
42+
2643
except Exception:
27-
continue
44+
pass
45+
2846
time.sleep(60)

0 commit comments

Comments
 (0)