mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Make UpdateChecker use the shared Onion object instead of creating a new one
This commit is contained in:
parent
58f70b1d9b
commit
a9e822b222
@ -26,8 +26,9 @@ class Menu(QtWidgets.QMenuBar):
|
||||
"""
|
||||
OnionShare's menu bar.
|
||||
"""
|
||||
def __init__(self, qtapp):
|
||||
def __init__(self, onion, qtapp):
|
||||
super(Menu, self).__init__()
|
||||
self.onion = onion
|
||||
self.qtapp = qtapp
|
||||
|
||||
file_menu = self.addMenu(strings._('gui_menu_file_menu', True))
|
||||
@ -41,7 +42,7 @@ class Menu(QtWidgets.QMenuBar):
|
||||
"""
|
||||
Settings action triggered.
|
||||
"""
|
||||
SettingsDialog(self.qtapp)
|
||||
SettingsDialog(self.onion, self.qtapp)
|
||||
|
||||
def quit(self):
|
||||
"""
|
||||
|
@ -64,7 +64,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
tor_con.start()
|
||||
|
||||
# Menu bar
|
||||
self.setMenuBar(Menu(self.qtapp))
|
||||
self.setMenuBar(Menu(self.onion, self.qtapp))
|
||||
|
||||
# Check for updates in a new thread, if enabled
|
||||
system = platform.system()
|
||||
@ -73,7 +73,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
def update_available(update_url, installed_version, latest_version):
|
||||
Alert(strings._("update_available", True).format(update_url, installed_version, latest_version))
|
||||
|
||||
t = UpdateThread()
|
||||
t = UpdateThread(self.onion)
|
||||
t.update_available.connect(update_available)
|
||||
t.start()
|
||||
|
||||
@ -156,7 +156,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
a.exec_()
|
||||
|
||||
if a.clickedButton() == settings_button:
|
||||
SettingsDialog(self.qtapp)
|
||||
SettingsDialog(self.onion, self.qtapp)
|
||||
else:
|
||||
self.qtapp.quit()
|
||||
|
||||
@ -168,7 +168,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
The TorConnectionDialog wants to open the Settings dialog
|
||||
"""
|
||||
def open_settings():
|
||||
SettingsDialog(self.qtapp)
|
||||
SettingsDialog(self.onion, self.qtapp)
|
||||
|
||||
# Wait 1ms for the event loop to finish closing the TorConnectionDialog
|
||||
QtCore.QTimer.singleShot(1, open_settings)
|
||||
|
@ -31,8 +31,9 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
"""
|
||||
Settings dialog.
|
||||
"""
|
||||
def __init__(self, qtapp):
|
||||
def __init__(self, onion, qtapp):
|
||||
super(SettingsDialog, self).__init__()
|
||||
self.onion = onion
|
||||
self.qtapp = qtapp
|
||||
|
||||
self.setModal(True)
|
||||
@ -373,8 +374,9 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
"""
|
||||
Check for Updates button clicked. Manually force an update check.
|
||||
"""
|
||||
settings = Settings()
|
||||
settings.load()
|
||||
# Disable buttons
|
||||
self._disable_buttons()
|
||||
self.qtapp.processEvents()
|
||||
|
||||
# Check for updates
|
||||
def update_available(update_url, installed_version, latest_version):
|
||||
@ -382,31 +384,22 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
def update_not_available():
|
||||
Alert(strings._('update_not_available', True))
|
||||
|
||||
u = UpdateChecker()
|
||||
u = UpdateChecker(self.onion)
|
||||
u.update_available.connect(update_available)
|
||||
u.update_not_available.connect(update_not_available)
|
||||
|
||||
# Show Tor connection status if connection type is bundled tor
|
||||
if settings.get('connection_type') == 'bundled':
|
||||
self.tor_status.show()
|
||||
self._disable_buttons()
|
||||
u.tor_status_update.connect(self._tor_status_update)
|
||||
|
||||
try:
|
||||
u.check(force=True)
|
||||
except UpdateCheckerTorError:
|
||||
Alert(strings._('update_error_tor', True), QtWidgets.QMessageBox.Warning)
|
||||
except UpdateCheckerSOCKSHTTPError:
|
||||
Alert(strings._('update_error_sockshttp', True), QtWidgets.QMessageBox.Warning)
|
||||
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)
|
||||
|
||||
# Clean up afterwards
|
||||
if settings.get('connection_type') == 'bundled':
|
||||
self.tor_status.hide()
|
||||
self._enable_buttons()
|
||||
# Enable buttons
|
||||
self._enable_buttons()
|
||||
|
||||
# Update the last checked label
|
||||
settings = Settings()
|
||||
settings.load()
|
||||
autoupdate_timestamp = settings.get('autoupdate_timestamp')
|
||||
self._update_autoupdate_timestamp(autoupdate_timestamp)
|
||||
|
@ -26,15 +26,10 @@ from onionshare.onion import Onion
|
||||
|
||||
from . import strings, helpers
|
||||
|
||||
class UpdateCheckerTorError(Exception):
|
||||
class UpdateCheckerCheckError(Exception):
|
||||
"""
|
||||
Error checking for updates because of some Tor connection issue.
|
||||
"""
|
||||
pass
|
||||
|
||||
class UpdateCheckerSOCKSHTTPError(Exception):
|
||||
"""
|
||||
Error checking for updates because of some SOCKS proxy or HTTP request issue.
|
||||
Error checking for updates because of some Tor connection issue, or because
|
||||
the OnionShare website is down.
|
||||
"""
|
||||
pass
|
||||
|
||||
@ -58,8 +53,9 @@ class UpdateChecker(QtCore.QObject):
|
||||
update_not_available = QtCore.pyqtSignal()
|
||||
tor_status_update = QtCore.pyqtSignal(str)
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, onion):
|
||||
super(UpdateChecker, self).__init__()
|
||||
self.onion = onion
|
||||
|
||||
def check(self, force=False):
|
||||
# Load the settings
|
||||
@ -86,12 +82,6 @@ class UpdateChecker(QtCore.QObject):
|
||||
|
||||
# Check for updates
|
||||
if check_for_updates:
|
||||
# Create an Onion object, for checking for updates over tor
|
||||
try:
|
||||
onion = Onion(settings=settings, bundled_tor_func=self._bundled_tor_func)
|
||||
except:
|
||||
raise UpdateCheckerTorError
|
||||
|
||||
# Download the latest-version file over Tor
|
||||
try:
|
||||
# User agent string includes OnionShare version and platform
|
||||
@ -103,7 +93,7 @@ class UpdateChecker(QtCore.QObject):
|
||||
if force:
|
||||
path += '?force=1'
|
||||
|
||||
(socks_address, socks_port) = onion.get_tor_socks_port()
|
||||
(socks_address, socks_port) = self.onion.get_tor_socks_port()
|
||||
socks.set_default_proxy(socks.SOCKS5, socks_address, socks_port)
|
||||
|
||||
s = socks.socksocket()
|
||||
@ -118,11 +108,8 @@ class UpdateChecker(QtCore.QObject):
|
||||
|
||||
http_response = s.recv(1024)
|
||||
latest_version = http_response[http_response.find(b'\r\n\r\n'):].strip().decode('utf-8')
|
||||
|
||||
# Clean up from Onion
|
||||
onion.cleanup()
|
||||
except:
|
||||
raise UpdateCheckerSOCKSHTTPError
|
||||
raise UpdateCheckerCheckError
|
||||
|
||||
# Validate that latest_version looks like a version string
|
||||
# This regex is: 1-3 dot-separated numeric components
|
||||
@ -145,19 +132,19 @@ class UpdateChecker(QtCore.QObject):
|
||||
# No updates are available
|
||||
self.update_not_available.emit()
|
||||
|
||||
def _bundled_tor_func(self, message):
|
||||
self.tor_status_update.emit(message)
|
||||
|
||||
class UpdateThread(QtCore.QThread):
|
||||
update_available = QtCore.pyqtSignal(str, str, str)
|
||||
update_not_available = QtCore.pyqtSignal()
|
||||
tor_status_update = QtCore.pyqtSignal(str)
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, onion):
|
||||
super(UpdateThread, self).__init__()
|
||||
self.onion = onion
|
||||
|
||||
def run(self):
|
||||
u = UpdateChecker()
|
||||
u = UpdateChecker(self.onion)
|
||||
u.update_available.connect(self._update_available)
|
||||
u.update_not_available.connect(self._update_not_available)
|
||||
u.tor_status_update.connect(self._tor_status_update)
|
||||
try:
|
||||
u.check()
|
||||
@ -168,5 +155,8 @@ class UpdateThread(QtCore.QThread):
|
||||
def _update_available(self, update_url, installed_version, latest_version):
|
||||
self.update_available.emit(update_url, installed_version, latest_version)
|
||||
|
||||
def _update_not_available(self):
|
||||
self.update_not_available.emit()
|
||||
|
||||
def _tor_status_update(self, message):
|
||||
self.tor_status_update.emit(message)
|
||||
|
@ -97,8 +97,7 @@
|
||||
"error_tor_protocol_error": "Error talking to the Tor controller.\nIf you're using Whonix, check out https://www.whonix.org/wiki/onionshare to make OnionShare work.",
|
||||
"connecting_to_tor": "Connecting to the Tor network",
|
||||
"update_available": "There is an OnionShare update available. <a href='{}'>Click here</a> to download it.<br><br>Installed version: {}<br>Latest version: {}",
|
||||
"update_error_tor": "Error checking for updates: Can't connect to Tor.\nCheck your Tor connection settings.",
|
||||
"update_error_sockshttp": "Error checking for updates: Connected to Tor, but can't load the update HTTP request.",
|
||||
"update_error_check_error": "Error checking for updates: Maybe you're not connected to Tor, or maybe the OnionShare website is down.",
|
||||
"update_error_invalid_latest_version": "Error checking for updates: The OnionShare website responded saying the latest version is '{}', but that doesn't appear to be a valid version string.",
|
||||
"update_not_available": "You are running the latest version of OnionShare.",
|
||||
"gui_tor_connection_error_settings": "Try adjusting how OnionShare connects to the Tor network in Settings."
|
||||
|
Loading…
Reference in New Issue
Block a user