mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-12 03:14:58 -04:00
Refactor UpdateChecker into a class that's a QObject, and make it use signals and slots to communicate
This commit is contained in:
parent
ca16600d29
commit
47c1488512
2 changed files with 74 additions and 57 deletions
|
@ -381,9 +381,17 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||||
bundled_tor_func = None
|
bundled_tor_func = None
|
||||||
|
|
||||||
# Check for updates
|
# Check for updates
|
||||||
try:
|
def update_available(update_url, installed_version, latest_version):
|
||||||
if not check_for_updates(force=True, bundled_tor_func=bundled_tor_func):
|
Alert(strings._("update_available", True).format(update_url, installed_version, latest_version))
|
||||||
|
def update_not_available():
|
||||||
Alert(strings._('update_not_available', True))
|
Alert(strings._('update_not_available', True))
|
||||||
|
|
||||||
|
u = UpdateChecker()
|
||||||
|
u.update_available.connect(update_available)
|
||||||
|
u.update_not_available.connect(update_not_available)
|
||||||
|
|
||||||
|
try:
|
||||||
|
u.check(force=True, bundled_tor_func=bundled_tor_func)
|
||||||
except UpdateCheckerTorError:
|
except UpdateCheckerTorError:
|
||||||
Alert(strings._('update_error_tor', True), QtWidgets.QMessageBox.Warning)
|
Alert(strings._('update_error_tor', True), QtWidgets.QMessageBox.Warning)
|
||||||
except UpdateCheckerSOCKSHTTPError:
|
except UpdateCheckerSOCKSHTTPError:
|
||||||
|
|
|
@ -17,12 +17,12 @@ 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/>.
|
||||||
"""
|
"""
|
||||||
|
from PyQt5 import QtCore
|
||||||
import datetime, time, socks, socket, re, platform
|
import datetime, time, socks, socket, re, platform
|
||||||
|
|
||||||
from . import strings, helpers
|
from . import strings, helpers
|
||||||
from onionshare.settings import Settings
|
from onionshare.settings import Settings
|
||||||
from onionshare.onion import Onion
|
from onionshare.onion import Onion
|
||||||
from .alert import Alert
|
|
||||||
|
|
||||||
class UpdateCheckerTorError(Exception):
|
class UpdateCheckerTorError(Exception):
|
||||||
"""
|
"""
|
||||||
|
@ -44,7 +44,7 @@ class UpdateCheckerInvalidLatestVersion(Exception):
|
||||||
def __init__(self, latest_version):
|
def __init__(self, latest_version):
|
||||||
self.latest_version = latest_version
|
self.latest_version = latest_version
|
||||||
|
|
||||||
def check_for_updates(force=False, bundled_tor_func=None):
|
class UpdateChecker(QtCore.QObject):
|
||||||
"""
|
"""
|
||||||
Load http://elx57ue5uyfplgva.onion/latest-version.txt to see what the latest
|
Load http://elx57ue5uyfplgva.onion/latest-version.txt to see what the latest
|
||||||
version of OnionShare is. If the latest version is newer than the
|
version of OnionShare is. If the latest version is newer than the
|
||||||
|
@ -52,6 +52,13 @@ def check_for_updates(force=False, bundled_tor_func=None):
|
||||||
|
|
||||||
Only check at most once per day, unless force is True.
|
Only check at most once per day, unless force is True.
|
||||||
"""
|
"""
|
||||||
|
update_available = QtCore.pyqtSignal(str, str, str)
|
||||||
|
update_not_available = QtCore.pyqtSignal()
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(UpdateChecker, self).__init__()
|
||||||
|
|
||||||
|
def check(self, force=False, bundled_tor_func=None):
|
||||||
# Load the settings
|
# Load the settings
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
settings.load()
|
settings.load()
|
||||||
|
@ -83,6 +90,7 @@ def check_for_updates(force=False, bundled_tor_func=None):
|
||||||
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.connect(('elx57ue5uyfplgva.onion', 80))
|
s.connect(('elx57ue5uyfplgva.onion', 80))
|
||||||
|
|
||||||
http_request = 'GET /latest-version.txt HTTP/1.0\r\n'
|
http_request = 'GET /latest-version.txt HTTP/1.0\r\n'
|
||||||
|
@ -114,7 +122,8 @@ def check_for_updates(force=False, bundled_tor_func=None):
|
||||||
update_url = 'https://github.com/micahflee/onionshare/releases/tag/v{}'.format(latest_version)
|
update_url = 'https://github.com/micahflee/onionshare/releases/tag/v{}'.format(latest_version)
|
||||||
installed_version = helpers.get_version()
|
installed_version = helpers.get_version()
|
||||||
if installed_version < latest_version:
|
if installed_version < latest_version:
|
||||||
Alert(strings._("update_available", True).format(update_url, installed_version, latest_version))
|
self.update_available.emit(update_url, installed_version, latest_version)
|
||||||
return True
|
return
|
||||||
|
|
||||||
return False
|
# No updates are available
|
||||||
|
self.update_not_available.emit()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue