Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgOhneH committed Sep 18, 2023
1 parent a72b0c4 commit ab16cad
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
61 changes: 48 additions & 13 deletions gui/startup_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import core.utils
import gui
from core.constants import VERSION, IS_FROZEN
from core.constants import VERSION, PYU_VERSION, IS_FROZEN

logger = logging.getLogger(__name__)

Expand All @@ -19,13 +19,48 @@ def run_startup_tasks(download_settings):
behavior_settings = gui.Application.instance().behavior_settings

if behavior_settings.check_for_updates and IS_FROZEN:
check_for_update = Update()
mutex = QMutex()
cond = QWaitCondition()
check_for_update = Update(mutex=mutex, cond=cond)
QThreadPool.globalInstance().start(check_for_update)

check_for_update.signals.ask_for_permission.connect(
lambda latest_version: ask_update_pop_up(latest_version, check_for_update))


def ask_update_pop_up(latest_version, check_for_update):
try:
msg_box = QMessageBox()
msg_box.setIcon(QMessageBox.Question)
msg_box.setWindowTitle("A new Version is available")
msg_box.setText(f"Version {latest_version[1:]} is available. (Current: {VERSION})\n"
f"Go to {DOWNLOAD_RELEASE_URL} to download the new release?")
msg_box.addButton(QMessageBox.Cancel)
install_button = msg_box.addButton("Ok", QMessageBox.AcceptRole)

msg_box.setDefaultButton(install_button)

msg_box.exec()

if msg_box.clickedButton() != install_button:
return

check_for_update.allowed_download = True
finally:
check_for_update.cond.wakeAll()


class Signals(QObject):
ask_for_permission = pyqtSignal(str)


class Update(QRunnable):
def __init__(self, ):
signals = Signals()

def __init__(self, mutex, cond):
super().__init__()
self.mutex = mutex
self.cond = cond
self.allowed_download = False

def run(self):
Expand All @@ -38,17 +73,17 @@ def run(self):
if latest_version == VERSION:
return

msg_box = QMessageBox()
msg_box.setIcon(QMessageBox.Question)
msg_box.setWindowTitle("A new Version is available")
msg_box.setText(f"Version {latest_version[1:]} is available. (Current: {VERSION})\n"
f"Go to https://github.com/GeorgOhneH/ethz-document-fetcher/releases/latest?")
msg_box.addButton(QMessageBox.Cancel)
install_button = msg_box.addButton("Ok", QMessageBox.AcceptRole)
self.signals.ask_for_permission.emit(latest_version)

msg_box.setDefaultButton(install_button)
self.mutex.lock()
try:
self.cond.wait(self.mutex)
finally:
self.mutex.unlock()

msg_box.exec()
if not self.allowed_download:
logger.debug("Update declined")
return


class BackgroundTasks(QRunnable):
Expand All @@ -58,4 +93,4 @@ def __init__(self, name):

def run(self):
core.utils.remove_old_files()
core.utils.user_statistics(self.name)
core.utils.user_statistics(self.name)
2 changes: 1 addition & 1 deletion win.spec
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ a = Analysis([os.path.join(os.getcwd(), "main_gui.py")],
(os.path.join("gui", "assets"), os.path.join("gui", "assets")),
(os.path.join("core", "assets"), os.path.join("core", "assets")),
],
hiddenimports=["encodings.idna", "win32con", "win32com.shell.shell", "win32com.shell", "babel.numbers"] + collect_submodules("sites"),
hiddenimports=["encodings.idna", "win32con", "win32com.shell.shellcon", "win32com.shell.shell", "win32com.shell", "babel.numbers"] + collect_submodules("sites"),
hookspath=[],
runtime_hooks=[],
excludes=[],
Expand Down

0 comments on commit ab16cad

Please sign in to comment.