mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-10 19:52:50 -03:00
Merge branch '535_force_update_check_via_qthread' of https://github.com/mig5/onionshare into mig5-535_force_update_check_via_qthread
This commit is contained in:
commit
cedfd5deff
2 changed files with 49 additions and 18 deletions
|
@ -557,32 +557,44 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||||
self._disable_buttons()
|
self._disable_buttons()
|
||||||
self.qtapp.processEvents()
|
self.qtapp.processEvents()
|
||||||
|
|
||||||
# Check for updates
|
def update_timestamp():
|
||||||
def update_available(update_url, installed_version, latest_version):
|
|
||||||
Alert(strings._("update_available", True).format(update_url, installed_version, latest_version))
|
|
||||||
def update_not_available():
|
|
||||||
Alert(strings._('update_not_available', True))
|
|
||||||
|
|
||||||
u = UpdateChecker(self.onion)
|
|
||||||
u.update_available.connect(update_available)
|
|
||||||
u.update_not_available.connect(update_not_available)
|
|
||||||
|
|
||||||
try:
|
|
||||||
u.check(force=True)
|
|
||||||
except UpdateCheckerCheckError:
|
|
||||||
Alert(strings._('update_error_check_error', True), QtWidgets.QMessageBox.Warning)
|
|
||||||
except UpdateCheckerInvalidLatestVersion as e:
|
|
||||||
Alert(strings._('update_error_invalid_latest_version', True).format(e.latest_version), QtWidgets.QMessageBox.Warning)
|
|
||||||
|
|
||||||
# Enable buttons
|
|
||||||
self._enable_buttons()
|
|
||||||
|
|
||||||
# Update the last checked label
|
# Update the last checked label
|
||||||
settings = Settings(self.config)
|
settings = Settings(self.config)
|
||||||
settings.load()
|
settings.load()
|
||||||
autoupdate_timestamp = settings.get('autoupdate_timestamp')
|
autoupdate_timestamp = settings.get('autoupdate_timestamp')
|
||||||
self._update_autoupdate_timestamp(autoupdate_timestamp)
|
self._update_autoupdate_timestamp(autoupdate_timestamp)
|
||||||
|
|
||||||
|
def close_forced_update_thread():
|
||||||
|
forced_update_thread.quit()
|
||||||
|
# Enable buttons
|
||||||
|
self._enable_buttons()
|
||||||
|
# Update timestamp
|
||||||
|
update_timestamp()
|
||||||
|
|
||||||
|
# Check for updates
|
||||||
|
def update_available(update_url, installed_version, latest_version):
|
||||||
|
Alert(strings._("update_available", True).format(update_url, installed_version, latest_version))
|
||||||
|
close_forced_update_thread()
|
||||||
|
|
||||||
|
def update_not_available():
|
||||||
|
Alert(strings._('update_not_available', True))
|
||||||
|
close_forced_update_thread()
|
||||||
|
|
||||||
|
def update_error():
|
||||||
|
Alert(strings._('update_error_check_error', True), QtWidgets.QMessageBox.Warning)
|
||||||
|
close_forced_update_thread()
|
||||||
|
|
||||||
|
def update_invalid_version():
|
||||||
|
Alert(strings._('update_error_invalid_latest_version', True).format(e.latest_version), QtWidgets.QMessageBox.Warning)
|
||||||
|
close_forced_update_thread()
|
||||||
|
|
||||||
|
forced_update_thread = UpdateThread(self.onion, self.config, force=True)
|
||||||
|
forced_update_thread.update_available.connect(update_available)
|
||||||
|
forced_update_thread.update_not_available.connect(update_not_available)
|
||||||
|
forced_update_thread.update_error.connect(update_error)
|
||||||
|
forced_update_thread.update_invalid_version.connect(update_invalid_version)
|
||||||
|
forced_update_thread.start()
|
||||||
|
|
||||||
def save_clicked(self):
|
def save_clicked(self):
|
||||||
"""
|
"""
|
||||||
Save button clicked. Save current settings to disk.
|
Save button clicked. Save current settings to disk.
|
||||||
|
|
|
@ -51,6 +51,8 @@ class UpdateChecker(QtCore.QObject):
|
||||||
"""
|
"""
|
||||||
update_available = QtCore.pyqtSignal(str, str, str)
|
update_available = QtCore.pyqtSignal(str, str, str)
|
||||||
update_not_available = QtCore.pyqtSignal()
|
update_not_available = QtCore.pyqtSignal()
|
||||||
|
update_error = QtCore.pyqtSignal()
|
||||||
|
update_invalid_version = QtCore.pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, onion, config=False):
|
def __init__(self, onion, config=False):
|
||||||
super(UpdateChecker, self).__init__()
|
super(UpdateChecker, self).__init__()
|
||||||
|
@ -120,12 +122,14 @@ class UpdateChecker(QtCore.QObject):
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
common.log('UpdateChecker', 'check', '{}'.format(e))
|
common.log('UpdateChecker', 'check', '{}'.format(e))
|
||||||
|
self.update_error.emit()
|
||||||
raise UpdateCheckerCheckError
|
raise UpdateCheckerCheckError
|
||||||
|
|
||||||
# Validate that latest_version looks like a version string
|
# Validate that latest_version looks like a version string
|
||||||
# This regex is: 1-3 dot-separated numeric components
|
# This regex is: 1-3 dot-separated numeric components
|
||||||
version_re = r"^(\d+\.)?(\d+\.)?(\d+)$"
|
version_re = r"^(\d+\.)?(\d+\.)?(\d+)$"
|
||||||
if not re.match(version_re, latest_version):
|
if not re.match(version_re, latest_version):
|
||||||
|
self.update_invalid_version.emit()
|
||||||
raise UpdateCheckerInvalidLatestVersion(latest_version)
|
raise UpdateCheckerInvalidLatestVersion(latest_version)
|
||||||
|
|
||||||
# Update the last checked timestamp (dropping the seconds and milliseconds)
|
# Update the last checked timestamp (dropping the seconds and milliseconds)
|
||||||
|
@ -148,12 +152,15 @@ class UpdateChecker(QtCore.QObject):
|
||||||
class UpdateThread(QtCore.QThread):
|
class UpdateThread(QtCore.QThread):
|
||||||
update_available = QtCore.pyqtSignal(str, str, str)
|
update_available = QtCore.pyqtSignal(str, str, str)
|
||||||
update_not_available = QtCore.pyqtSignal()
|
update_not_available = QtCore.pyqtSignal()
|
||||||
|
update_error = QtCore.pyqtSignal()
|
||||||
|
update_invalid_version = QtCore.pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, onion, config=False):
|
def __init__(self, onion, config=False, force=False):
|
||||||
super(UpdateThread, self).__init__()
|
super(UpdateThread, self).__init__()
|
||||||
common.log('UpdateThread', '__init__')
|
common.log('UpdateThread', '__init__')
|
||||||
self.onion = onion
|
self.onion = onion
|
||||||
self.config = config
|
self.config = config
|
||||||
|
self.force = force
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
common.log('UpdateThread', 'run')
|
common.log('UpdateThread', 'run')
|
||||||
|
@ -161,9 +168,11 @@ class UpdateThread(QtCore.QThread):
|
||||||
u = UpdateChecker(self.onion, self.config)
|
u = UpdateChecker(self.onion, self.config)
|
||||||
u.update_available.connect(self._update_available)
|
u.update_available.connect(self._update_available)
|
||||||
u.update_not_available.connect(self._update_not_available)
|
u.update_not_available.connect(self._update_not_available)
|
||||||
|
u.update_error.connect(self._update_error)
|
||||||
|
u.update_invalid_version.connect(self._update_invalid_version)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
u.check(config=self.config)
|
u.check(config=self.config,force=self.force)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# If update check fails, silently ignore
|
# If update check fails, silently ignore
|
||||||
common.log('UpdateThread', 'run', '{}'.format(e))
|
common.log('UpdateThread', 'run', '{}'.format(e))
|
||||||
|
@ -178,3 +187,13 @@ class UpdateThread(QtCore.QThread):
|
||||||
common.log('UpdateThread', '_update_not_available')
|
common.log('UpdateThread', '_update_not_available')
|
||||||
self.active = False
|
self.active = False
|
||||||
self.update_not_available.emit()
|
self.update_not_available.emit()
|
||||||
|
|
||||||
|
def _update_error(self):
|
||||||
|
common.log('UpdateThread', '_update_error')
|
||||||
|
self.active = False
|
||||||
|
self.update_error.emit()
|
||||||
|
|
||||||
|
def _update_invalid_version(self):
|
||||||
|
common.log('UpdateThread', '_update_invalid_version')
|
||||||
|
self.active = False
|
||||||
|
self.update_invalid_version.emit()
|
||||||
|
|
Loading…
Reference in a new issue