mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-15 01:07:21 -05:00
Fix UpdateChecker and UpdateThread to work with refactor, now it pops up an update reminder
This commit is contained in:
parent
ea745e63f3
commit
24ccb3995f
@ -17,7 +17,7 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
import os, platform, threading, time
|
import os, threading, time
|
||||||
from PyQt5 import QtCore, QtWidgets, QtGui
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||||
|
|
||||||
from onionshare import strings, common, web
|
from onionshare import strings, common, web
|
||||||
@ -59,17 +59,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
self.settings = Settings()
|
self.settings = Settings()
|
||||||
self.settings.load()
|
self.settings.load()
|
||||||
|
|
||||||
# Check for updates in a new thread, if enabled
|
|
||||||
system = platform.system()
|
|
||||||
if system == 'Windows' or system == 'Darwin':
|
|
||||||
if self.settings.get('use_autoupdate'):
|
|
||||||
def update_available(update_url, installed_version, latest_version):
|
|
||||||
Alert(strings._("update_available", True).format(update_url, installed_version, latest_version))
|
|
||||||
|
|
||||||
t = UpdateThread(self.onion)
|
|
||||||
t.update_available.connect(update_available)
|
|
||||||
t.start()
|
|
||||||
|
|
||||||
# File selection
|
# File selection
|
||||||
self.file_selection = FileSelection()
|
self.file_selection = FileSelection()
|
||||||
if filenames:
|
if filenames:
|
||||||
@ -151,6 +140,9 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
tor_con.open_settings.connect(self._tor_connection_open_settings)
|
tor_con.open_settings.connect(self._tor_connection_open_settings)
|
||||||
tor_con.start()
|
tor_con.start()
|
||||||
|
|
||||||
|
# After connecting to Tor, check for updates
|
||||||
|
self.check_for_updates()
|
||||||
|
|
||||||
def _tor_connection_canceled(self):
|
def _tor_connection_canceled(self):
|
||||||
"""
|
"""
|
||||||
If the user cancels before Tor finishes connecting, ask if they want to
|
If the user cancels before Tor finishes connecting, ask if they want to
|
||||||
@ -312,6 +304,20 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
self.set_server_active(False)
|
self.set_server_active(False)
|
||||||
|
|
||||||
|
def check_for_updates(self):
|
||||||
|
"""
|
||||||
|
Check for updates in a new thread, if enabled.
|
||||||
|
"""
|
||||||
|
system = common.get_platform()
|
||||||
|
if system == 'Windows' or system == 'Darwin':
|
||||||
|
if self.settings.get('use_autoupdate'):
|
||||||
|
def update_available(update_url, installed_version, latest_version):
|
||||||
|
Alert(strings._("update_available", True).format(update_url, installed_version, latest_version))
|
||||||
|
|
||||||
|
self.update_thread = UpdateThread(self.onion)
|
||||||
|
self.update_thread.update_available.connect(update_available)
|
||||||
|
self.update_thread.start()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _compute_total_size(filenames):
|
def _compute_total_size(filenames):
|
||||||
total_size = 0
|
total_size = 0
|
||||||
|
@ -209,6 +209,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||||||
self.cancel_button = QtWidgets.QPushButton(strings._('gui_settings_button_cancel', True))
|
self.cancel_button = QtWidgets.QPushButton(strings._('gui_settings_button_cancel', True))
|
||||||
self.cancel_button.clicked.connect(self.cancel_clicked)
|
self.cancel_button.clicked.connect(self.cancel_clicked)
|
||||||
buttons_layout = QtWidgets.QHBoxLayout()
|
buttons_layout = QtWidgets.QHBoxLayout()
|
||||||
|
buttons_layout.addStretch()
|
||||||
buttons_layout.addWidget(self.save_button)
|
buttons_layout.addWidget(self.save_button)
|
||||||
buttons_layout.addWidget(self.cancel_button)
|
buttons_layout.addWidget(self.cancel_button)
|
||||||
|
|
||||||
|
@ -51,13 +51,14 @@ 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()
|
||||||
tor_status_update = QtCore.pyqtSignal(str)
|
|
||||||
|
|
||||||
def __init__(self, onion):
|
def __init__(self, onion):
|
||||||
super(UpdateChecker, self).__init__()
|
super(UpdateChecker, self).__init__()
|
||||||
|
common.log('UpdateChecker', '__init__')
|
||||||
self.onion = onion
|
self.onion = onion
|
||||||
|
|
||||||
def check(self, force=False):
|
def check(self, force=False):
|
||||||
|
common.log('UpdateChecker', 'check', 'force={}'.format(force))
|
||||||
# Load the settings
|
# Load the settings
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
settings.load()
|
settings.load()
|
||||||
@ -82,6 +83,7 @@ class UpdateChecker(QtCore.QObject):
|
|||||||
|
|
||||||
# Check for updates
|
# Check for updates
|
||||||
if check_for_updates:
|
if check_for_updates:
|
||||||
|
common.log('UpdateChecker', 'check', 'checking for updates')
|
||||||
# Download the latest-version file over Tor
|
# Download the latest-version file over Tor
|
||||||
try:
|
try:
|
||||||
# User agent string includes OnionShare version and platform
|
# User agent string includes OnionShare version and platform
|
||||||
@ -93,22 +95,30 @@ class UpdateChecker(QtCore.QObject):
|
|||||||
if force:
|
if force:
|
||||||
path += '?force=1'
|
path += '?force=1'
|
||||||
|
|
||||||
|
onion_domain = 'elx57ue5uyfplgva.onion'
|
||||||
|
|
||||||
|
common.log('UpdateChecker', 'check', 'loading http://{}/{}'.format(onion_domain, path))
|
||||||
|
|
||||||
(socks_address, socks_port) = self.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)
|
socks.set_default_proxy(socks.SOCKS5, socks_address, socks_port)
|
||||||
|
|
||||||
s = socks.socksocket()
|
s = socks.socksocket()
|
||||||
s.settimeout(15) # 15 second timeout
|
s.settimeout(15) # 15 second timeout
|
||||||
s.connect(('elx57ue5uyfplgva.onion', 80))
|
s.connect((onion_domain, 80))
|
||||||
|
|
||||||
http_request = 'GET {} HTTP/1.0\r\n'.format(path)
|
http_request = 'GET {} HTTP/1.0\r\n'.format(path)
|
||||||
http_request += 'Host: elx57ue5uyfplgva.onion\r\n'
|
http_request += 'Host: {}\r\n'.format(onion_domain)
|
||||||
http_request += 'User-Agent: {}\r\n'.format(user_agent)
|
http_request += 'User-Agent: {}\r\n'.format(user_agent)
|
||||||
http_request += '\r\n'
|
http_request += '\r\n'
|
||||||
s.sendall(http_request.encode('utf-8'))
|
s.sendall(http_request.encode('utf-8'))
|
||||||
|
|
||||||
http_response = s.recv(1024)
|
http_response = s.recv(1024)
|
||||||
latest_version = http_response[http_response.find(b'\r\n\r\n'):].strip().decode('utf-8')
|
latest_version = http_response[http_response.find(b'\r\n\r\n'):].strip().decode('utf-8')
|
||||||
except:
|
|
||||||
|
common.log('UpdateChecker', 'check', 'latest OnionShare version: {}'.format(latest_version))
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
common.log('UpdateChecker', 'check', '{}'.format(e))
|
||||||
raise UpdateCheckerCheckError
|
raise UpdateCheckerCheckError
|
||||||
|
|
||||||
# Validate that latest_version looks like a version string
|
# Validate that latest_version looks like a version string
|
||||||
@ -135,28 +145,32 @@ 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()
|
||||||
tor_status_update = QtCore.pyqtSignal(str)
|
|
||||||
|
|
||||||
def __init__(self, onion):
|
def __init__(self, onion):
|
||||||
super(UpdateThread, self).__init__()
|
super(UpdateThread, self).__init__()
|
||||||
|
common.log('UpdateThread', '__init__')
|
||||||
self.onion = onion
|
self.onion = onion
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
common.log('UpdateThread', 'run')
|
||||||
|
|
||||||
u = UpdateChecker(self.onion)
|
u = UpdateChecker(self.onion)
|
||||||
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.tor_status_update.connect(self._tor_status_update)
|
|
||||||
try:
|
try:
|
||||||
u.check()
|
u.check()
|
||||||
except:
|
except Exception as e:
|
||||||
# If update check fails, silently ignore
|
# If update check fails, silently ignore
|
||||||
|
common.log('UpdateThread', 'run', '{}'.format(e))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _update_available(self, update_url, installed_version, latest_version):
|
def _update_available(self, update_url, installed_version, latest_version):
|
||||||
|
common.log('UpdateThread', '_update_available')
|
||||||
|
self.active = False
|
||||||
self.update_available.emit(update_url, installed_version, latest_version)
|
self.update_available.emit(update_url, installed_version, latest_version)
|
||||||
|
|
||||||
def _update_not_available(self):
|
def _update_not_available(self):
|
||||||
|
common.log('UpdateThread', '_update_not_available')
|
||||||
|
self.active = False
|
||||||
self.update_not_available.emit()
|
self.update_not_available.emit()
|
||||||
|
|
||||||
def _tor_status_update(self, message):
|
|
||||||
self.tor_status_update.emit(message)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user