diff --git a/imswitch/__init__.py b/imswitch/__init__.py index 2ff5837d0..f32aab1ee 100644 --- a/imswitch/__init__.py +++ b/imswitch/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.2.3' +__version__ = '1.2.0' # Copyright (C) 2020-2021 ImSwitch developers diff --git a/imswitch/imcommon/controller/CheckUpdatesController.py b/imswitch/imcommon/controller/CheckUpdatesController.py index 396cf0c0c..b09255898 100644 --- a/imswitch/imcommon/controller/CheckUpdatesController.py +++ b/imswitch/imcommon/controller/CheckUpdatesController.py @@ -5,7 +5,8 @@ from luddite import get_version_pypi from packaging import version import subprocess - +import urllib.request +import threading import imswitch from imswitch.imcommon.framework import Signal, Thread @@ -23,6 +24,7 @@ def __init__(self, *args, **kwargs): self.thread.sigNoUpdate.connect(self._widget.showNoUpdateAvailable) self.thread.sigNewVersionPyInstaller.connect(self._widget.showPyInstallerUpdate) self.thread.sigNewVersionPyPI.connect(self._widget.showPyPIUpdate) + self.thread.sigNewVersionShowInfo.connect(self._widget.showInfo) def __del__(self): self.thread.quit() @@ -46,7 +48,7 @@ class CheckUpdatesThread(Thread): sigNoUpdate = Signal() sigNewVersionPyInstaller = Signal(str) # (latestVersion) sigNewVersionPyPI = Signal(str) # (latestVersion) - + sigNewVersionShowInfo = Signal(str) # (someText) def __init__(self): super().__init__() self.__logger = initLogger(self, tryInheritParent=True) @@ -54,25 +56,54 @@ def __init__(self): def run(self): currentVersion = imswitch.__version__ try: - if 'IMSWITCH_IS_BUNDLE' in os.environ and os.environ['IMSWITCH_IS_BUNDLE'] == '1': + if True: #'IMSWITCH_IS_BUNDLE' in os.environ and os.environ['IMSWITCH_IS_BUNDLE'] == '1': # Installed from bundle - check GitHub + self.__logger.debug("We are checking for pre-built bundles on Github") releaseResponse = requests.get( 'https://api.github.com/repos/openUC2/ImSwitch/releases/latest' ) latestVersion = releaseResponse.json()['tag_name'].lstrip('v') latestVersionDate = releaseResponse.json()['published_at'].split('T')[0] - + if version.parse(latestVersion) > version.parse(currentVersion): self.sigNewVersionPyInstaller.emit(latestVersion) + + ## attempting to downloda the current ImSwitch version + downloadURL = releaseResponse.json()['assets'][0]['browser_download_url'] + self.__logger.debug("We are downloading the software from: "+downloadURL) + + ## inplace replacement won't work I guess? + def dlImSwitch(downloadURL, fileName): + resultDL = urllib.request.urlretrieve(downloadURL, fileName) + + self.sigNewVersionShowInfo.emit("Downloading and updating latest version...") + + + ImSwitchExeFilename = "ImSwitch.exe" + if os.path.isfile(ImSwitchExeFilename): + self.__logger.debug("Renaming old ImSwitch.exe file") + os.rename(ImSwitchExeFilename, ImSwitchExeFilename+"_BAK") + mThread = threading.Thread(target=dlImSwitch, args=(downloadURL, ImSwitchExeFilename)) + mThread.start() + mThread.join() + self.__logger.debug("Download successful!") + self.sigNewVersionShowInfo.emit("Download successful! Please restart ImSwitch. ") + + + else: self.sigNoUpdate.emit() else: # Not installed from bundle - check PyPI + self.__logger.debug("We are checking for latest versions on pypi") + latestVersion = get_version_pypi('ImSwitch') if version.parse(latestVersion) > version.parse(currentVersion): self.sigNewVersionPyPI.emit(latestVersion) else: self.sigNoUpdate.emit() + + except Exception: self.__logger.warning(traceback.format_exc()) self.sigFailed.emit() diff --git a/imswitch/imcommon/view/CheckUpdatesDialog.py b/imswitch/imcommon/view/CheckUpdatesDialog.py index 7727b944f..eb7ca549d 100644 --- a/imswitch/imcommon/view/CheckUpdatesDialog.py +++ b/imswitch/imcommon/view/CheckUpdatesDialog.py @@ -70,6 +70,12 @@ def showPyInstallerUpdate(self, newVersion): ) self.linkLabel.setVisible(True) + def showInfo(self, text): + self.informationLabel.setText(text) + self.linkLabel.setText("") + self.linkLabel.setVisible(False) + + def showPyPIUpdate(self, newVersion): self.informationLabel.setText( f'ImSwitch {newVersion} is now available. '