updater - loading and version checking

This commit is contained in:
ingvar1995 2016-09-23 20:37:32 +03:00
parent 9fe9ba4743
commit 006b3cd197
5 changed files with 60 additions and 10 deletions

View File

@ -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

View File

@ -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()))

View File

@ -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

View File

@ -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,13 +13,56 @@ 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):

View File

@ -2,7 +2,7 @@ import os
import time
import shutil
program_version = '0.2.6'
program_version = '0.2.3'
def log(data):