diff --git a/toxygen/main.py b/toxygen/main.py index 6f34785..cee02dc 100644 --- a/toxygen/main.py +++ b/toxygen/main.py @@ -15,6 +15,7 @@ import platform import toxencryptsave from passwordscreen import PasswordScreen, UnlockAppScreen, SetProfilePasswordScreen from plugin_support import PluginLoader +import updater class Toxygen: @@ -278,6 +279,7 @@ class Toxygen: app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()")) app.exec_() + self.init.stop = True self.mainloop.stop = True self.avloop.stop = True diff --git a/toxygen/mainscreen.py b/toxygen/mainscreen.py index b9d7e12..672f181 100644 --- a/toxygen/mainscreen.py +++ b/toxygen/mainscreen.py @@ -337,7 +337,7 @@ class MainWindow(QtGui.QMainWindow, Singleton): s.save() QtGui.QApplication.closeAllWindows() event.accept() - else: + elif QtGui.QSystemTrayIcon.isSystemTrayAvailable(): event.ignore() self.hide() @@ -359,7 +359,7 @@ class MainWindow(QtGui.QMainWindow, Singleton): self.profile.update() def keyPressEvent(self, event): - if event.key() == QtCore.Qt.Key_Escape: + if event.key() == QtCore.Qt.Key_Escape and QtGui.QSystemTrayIcon.isSystemTrayAvailable(): self.hide() elif event.key() == QtCore.Qt.Key_C and event.modifiers() & QtCore.Qt.ControlModifier and self.messages.selectedIndexes(): rows = list(map(lambda x: self.messages.row(x), self.messages.selectedItems())) diff --git a/toxygen/settings.py b/toxygen/settings.py index daca665..b196477 100644 --- a/toxygen/settings.py +++ b/toxygen/settings.py @@ -145,7 +145,8 @@ class Settings(dict, Singleton): 'compact_mode': False, 'show_welcome_screen': True, 'close_to_tray': False, - 'font': 'Times New Roman' + 'font': 'Times New Roman', + 'update': 1 } @staticmethod diff --git a/toxygen/updater.py b/toxygen/updater.py index bc515b7..ba16aaf 100644 --- a/toxygen/updater.py +++ b/toxygen/updater.py @@ -1,5 +1,9 @@ import util -import requests +import settings +try: + from PySide import QtNetwork, QtCore +except: + from PyQt4 import QtNetwork, QtCore def check_for_updates(): @@ -9,17 +13,60 @@ def check_for_updates(): for version in versions: if send_request(version): return version - return None + return None # no new version was found + + +def get_url(version): + return 'https://github.com/toxygen-project/toxygen/releases/tag/v' + version + + +def download(version): + s = settings.Settings.get_instance() + if s['update']: + netman = QtNetwork.QNetworkAccessManager() + proxy = QtNetwork.QNetworkProxy() + if s['proxy_type']: + proxy.setType( + QtNetwork.QNetworkProxy.Socks5Proxy if s['proxy_type'] == 2 else QtNetwork.QNetworkProxy.HttpProxy) + proxy.setHostName(s['proxy_host']) + proxy.setPort(s['proxy_port']) + netman.setProxy(proxy) + url = get_url(version) + try: + request = QtNetwork.QNetworkRequest(url) + reply = netman.get(request) + while not reply.isFinished(): + QtCore.QThread.msleep(1) + data = bytes(reply.readAll().data()) + with open('toxygen.zip', 'wb') as fl: + fl.write(data) + except Exception as ex: + util.log('Downloading new version of Toxygen failed with exception: ' + str(ex)) def send_request(version): - # TODO: proxy support - request = requests.get('https://github.com/toxygen-project/toxygen/releases/tag/v' + version) - return request.status_code == 200 + s = settings.Settings.get_instance() + netman = QtNetwork.QNetworkAccessManager() + proxy = QtNetwork.QNetworkProxy() + if s['proxy_type']: + proxy.setType(QtNetwork.QNetworkProxy.Socks5Proxy if s['proxy_type'] == 2 else QtNetwork.QNetworkProxy.HttpProxy) + proxy.setHostName(s['proxy_host']) + proxy.setPort(s['proxy_port']) + netman.setProxy(proxy) + url = get_url(version) + try: + request = QtNetwork.QNetworkRequest(url) + reply = netman.get(request) + while not reply.isFinished(): + QtCore.QThread.msleep(1) + return reply.attribute() == 200 + except Exception as ex: + util.log('TOXYGEN UPDATER ERROR: ' + str(ex)) + return False def generate_versions(major, minor, patch): new_major = '.'.join([str(major + 1), '0', '0']) new_minor = '.'.join([str(major), str(minor + 1), '0']) new_patch = '.'.join([str(major), str(minor), str(patch + 1)]) - return new_major, new_minor, new_patch \ No newline at end of file + return new_major, new_minor, new_patch diff --git a/toxygen/util.py b/toxygen/util.py index 0d1a48f..c27bf44 100644 --- a/toxygen/util.py +++ b/toxygen/util.py @@ -2,7 +2,7 @@ import os import time import shutil -program_version = '0.2.6' +program_version = '0.2.3' def log(data):