auto update - settings, version checking
This commit is contained in:
		
							parent
							
								
									8025c6a638
								
							
						
					
					
						commit
						dfab0491a5
					
				
					 5 changed files with 114 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -259,6 +259,23 @@ class Toxygen:
 | 
			
		|||
        self.tray.show()
 | 
			
		||||
        self.tray.activated.connect(tray_activated)
 | 
			
		||||
 | 
			
		||||
        if settings['update']:  # auto update
 | 
			
		||||
            version = updater.check_for_updates()
 | 
			
		||||
            if version is not None:
 | 
			
		||||
                if settings['update'] == 2:
 | 
			
		||||
                    updater.download(version)
 | 
			
		||||
                else:
 | 
			
		||||
                    reply = QtGui.QMessageBox.question(None,
 | 
			
		||||
                                                       '',
 | 
			
		||||
                                                       QtGui.QApplication.translate("login",
 | 
			
		||||
                                                                                    'Update for Toxygen was found. Download and install it?',
 | 
			
		||||
                                                                                    None,
 | 
			
		||||
                                                                                    QtGui.QApplication.UnicodeUTF8),
 | 
			
		||||
                                                       QtGui.QMessageBox.Yes,
 | 
			
		||||
                                                       QtGui.QMessageBox.No)
 | 
			
		||||
                    if reply == QtGui.QMessageBox.Yes:
 | 
			
		||||
                        updater.download(version)
 | 
			
		||||
 | 
			
		||||
        self.ms.show()
 | 
			
		||||
 | 
			
		||||
        plugin_helper = PluginLoader(self.tox, settings)  # plugin support
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,6 +52,7 @@ class MainWindow(QtGui.QMainWindow, Singleton):
 | 
			
		|||
        self.actionNetwork.setObjectName("actionNetwork")
 | 
			
		||||
        self.actionAbout_program = QtGui.QAction(MainWindow)
 | 
			
		||||
        self.actionAbout_program.setObjectName("actionAbout_program")
 | 
			
		||||
        self.updateSettings = QtGui.QAction(MainWindow)
 | 
			
		||||
        self.actionSettings = QtGui.QAction(MainWindow)
 | 
			
		||||
        self.actionSettings.setObjectName("actionSettings")
 | 
			
		||||
        self.audioSettings = QtGui.QAction(MainWindow)
 | 
			
		||||
| 
						 | 
				
			
			@ -66,6 +67,7 @@ class MainWindow(QtGui.QMainWindow, Singleton):
 | 
			
		|||
        self.menuSettings.addAction(self.actionNotifications)
 | 
			
		||||
        self.menuSettings.addAction(self.actionNetwork)
 | 
			
		||||
        self.menuSettings.addAction(self.audioSettings)
 | 
			
		||||
        self.menuSettings.addAction(self.updateSettings)
 | 
			
		||||
        self.menuPlugins.addAction(self.pluginData)
 | 
			
		||||
        self.menuPlugins.addAction(self.importPlugin)
 | 
			
		||||
        self.menuAbout.addAction(self.actionAbout_program)
 | 
			
		||||
| 
						 | 
				
			
			@ -82,6 +84,7 @@ class MainWindow(QtGui.QMainWindow, Singleton):
 | 
			
		|||
        self.actionInterface_settings.triggered.connect(self.interface_settings)
 | 
			
		||||
        self.actionNotifications.triggered.connect(self.notification_settings)
 | 
			
		||||
        self.audioSettings.triggered.connect(self.audio_settings)
 | 
			
		||||
        self.updateSettings.triggered.connect(self.update_settings)
 | 
			
		||||
        self.pluginData.triggered.connect(self.plugins_menu)
 | 
			
		||||
        self.lockApp.triggered.connect(self.lock_app)
 | 
			
		||||
        self.importPlugin.triggered.connect(self.import_plugin)
 | 
			
		||||
| 
						 | 
				
			
			@ -112,6 +115,7 @@ class MainWindow(QtGui.QMainWindow, Singleton):
 | 
			
		|||
        self.actionAbout_program.setText(QtGui.QApplication.translate("MainWindow", "About program", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.actionSettings.setText(QtGui.QApplication.translate("MainWindow", "Settings", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.audioSettings.setText(QtGui.QApplication.translate("MainWindow", "Audio", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.updateSettings.setText(QtGui.QApplication.translate("MainWindow", "Updates", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.contact_name.setPlaceholderText(QtGui.QApplication.translate("MainWindow", "Search", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.sendMessageButton.setToolTip(QtGui.QApplication.translate("MainWindow", "Send message", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.callButton.setToolTip(QtGui.QApplication.translate("MainWindow", "Start audio call with friend", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
| 
						 | 
				
			
			@ -420,6 +424,10 @@ class MainWindow(QtGui.QMainWindow, Singleton):
 | 
			
		|||
        self.audio_s = AudioSettings()
 | 
			
		||||
        self.audio_s.show()
 | 
			
		||||
 | 
			
		||||
    def update_settings(self):
 | 
			
		||||
        self.update_s = UpdateSettings()
 | 
			
		||||
        self.update_s.show()
 | 
			
		||||
 | 
			
		||||
    def import_plugin(self):
 | 
			
		||||
        import util
 | 
			
		||||
        directory = QtGui.QFileDialog.getExistingDirectory(self,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,7 @@ from widgets import CenteredWidget, DataLabel, LineEdit
 | 
			
		|||
import pyaudio
 | 
			
		||||
import toxencryptsave
 | 
			
		||||
import plugin_support
 | 
			
		||||
import updater
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AddContact(CenteredWidget):
 | 
			
		||||
| 
						 | 
				
			
			@ -899,3 +900,64 @@ class PluginsSettings(CenteredWidget):
 | 
			
		|||
            self.button.setText(QtGui.QApplication.translate("PluginsForm", "Disable plugin", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        else:
 | 
			
		||||
            self.button.setText(QtGui.QApplication.translate("PluginsForm", "Enable plugin", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class UpdateSettings(CenteredWidget):
 | 
			
		||||
    """
 | 
			
		||||
    Audio calls settings form
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        super(UpdateSettings, self).__init__()
 | 
			
		||||
        self.initUI()
 | 
			
		||||
        self.center()
 | 
			
		||||
 | 
			
		||||
    def initUI(self):
 | 
			
		||||
        self.setObjectName("updateSettingsForm")
 | 
			
		||||
        self.resize(400, 150)
 | 
			
		||||
        self.setMinimumSize(QtCore.QSize(400, 120))
 | 
			
		||||
        self.setMaximumSize(QtCore.QSize(400, 120))
 | 
			
		||||
        self.in_label = QtGui.QLabel(self)
 | 
			
		||||
        self.in_label.setGeometry(QtCore.QRect(25, 5, 350, 20))
 | 
			
		||||
        settings = Settings.get_instance()
 | 
			
		||||
        font = QtGui.QFont()
 | 
			
		||||
        font.setPointSize(16)
 | 
			
		||||
        font.setBold(True)
 | 
			
		||||
        font.setFamily(settings['font'])
 | 
			
		||||
        self.in_label.setFont(font)
 | 
			
		||||
        self.autoupdate = QtGui.QComboBox(self)
 | 
			
		||||
        self.autoupdate.setGeometry(QtCore.QRect(25, 30, 350, 30))
 | 
			
		||||
        self.button = QtGui.QPushButton(self)
 | 
			
		||||
        self.button.setGeometry(QtCore.QRect(25, 70, 350, 30))
 | 
			
		||||
        self.button.setEnabled(settings['update'])
 | 
			
		||||
        self.button.clicked.connect(self.update_client)
 | 
			
		||||
 | 
			
		||||
        self.retranslateUi()
 | 
			
		||||
        self.autoupdate.setCurrentIndex(settings['update'])
 | 
			
		||||
        QtCore.QMetaObject.connectSlotsByName(self)
 | 
			
		||||
 | 
			
		||||
    def retranslateUi(self):
 | 
			
		||||
        self.setWindowTitle(QtGui.QApplication.translate("updateSettingsForm", "Update settings", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.in_label.setText(QtGui.QApplication.translate("updateSettingsForm", "Select update mode:", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.button.setText(QtGui.QApplication.translate("updateSettingsForm", "Update Toxygen", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.autoupdate.addItem(QtGui.QApplication.translate("updateSettingsForm", "Disabled", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.autoupdate.addItem(QtGui.QApplication.translate("updateSettingsForm", "Manual", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
        self.autoupdate.addItem(QtGui.QApplication.translate("updateSettingsForm", "Auto", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
 | 
			
		||||
    def closeEvent(self, event):
 | 
			
		||||
        settings = Settings.get_instance()
 | 
			
		||||
        settings['update'] = self.autoupdate.currentIndex()
 | 
			
		||||
        settings.save()
 | 
			
		||||
 | 
			
		||||
    def update_client(self):
 | 
			
		||||
        version = updater.check_for_updates()
 | 
			
		||||
        if version is not None:
 | 
			
		||||
            updater.download(version)
 | 
			
		||||
        else:
 | 
			
		||||
            msgBox = QtGui.QMessageBox()
 | 
			
		||||
            msgBox.setWindowTitle(
 | 
			
		||||
                QtGui.QApplication.translate("updateSettingsForm", "No updates found", None, QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
            text = (QtGui.QApplication.translate("updateSettingsForm", 'Toxygen is up to date', None,
 | 
			
		||||
                                                 QtGui.QApplication.UnicodeUTF8))
 | 
			
		||||
            msgBox.setText(text)
 | 
			
		||||
            msgBox.exec_()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
import util
 | 
			
		||||
import settings
 | 
			
		||||
import platform
 | 
			
		||||
try:
 | 
			
		||||
    from PySide import QtNetwork, QtCore
 | 
			
		||||
except:
 | 
			
		||||
| 
						 | 
				
			
			@ -16,10 +17,27 @@ def check_for_updates():
 | 
			
		|||
    return None  # no new version was found
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_url(version):
 | 
			
		||||
def is_from_sources():
 | 
			
		||||
    return __file__.endswith('.py')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_file_name():
 | 
			
		||||
    res = 'toxygen.zip' if platform.system() == 'Windows' else 'toxygen.tar.gz'
 | 
			
		||||
    return util.curr_directory() + '/' + res
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_url(version):
 | 
			
		||||
    return 'https://github.com/toxygen-project/toxygen/releases/tag/v' + version
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_url(version):
 | 
			
		||||
    if not is_from_sources():
 | 
			
		||||
        return 'https://github.com/toxygen-project/toxygen/releases/tag/v' + version
 | 
			
		||||
    else:
 | 
			
		||||
        name = 'toxygen_windows.zip' if platform.system() == 'Windows' else 'toxygen_linux.tar.gz'
 | 
			
		||||
        return 'https://github.com/toxygen-project/toxygen/archive/v{}.{}'.format(version, name)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def download(version):
 | 
			
		||||
    s = settings.Settings.get_instance()
 | 
			
		||||
    if s['update']:
 | 
			
		||||
| 
						 | 
				
			
			@ -37,8 +55,9 @@ def download(version):
 | 
			
		|||
            reply = netman.get(request)
 | 
			
		||||
            while not reply.isFinished():
 | 
			
		||||
                QtCore.QThread.msleep(1)
 | 
			
		||||
            data = bytes(reply.readAll().data())
 | 
			
		||||
            with open('toxygen.zip', 'wb') as fl:
 | 
			
		||||
                QtCore.QCoreApplication.processEvents()
 | 
			
		||||
            data = bytes(reply.readAll().data())  # TODO: fix
 | 
			
		||||
            with open(get_file_name(), 'wb') as fl:
 | 
			
		||||
                fl.write(data)
 | 
			
		||||
        except Exception as ex:
 | 
			
		||||
            util.log('Downloading new version of Toxygen failed with exception: ' + str(ex))
 | 
			
		||||
| 
						 | 
				
			
			@ -53,13 +72,15 @@ def send_request(version):
 | 
			
		|||
        proxy.setHostName(s['proxy_host'])
 | 
			
		||||
        proxy.setPort(s['proxy_port'])
 | 
			
		||||
        netman.setProxy(proxy)
 | 
			
		||||
    url = get_url(version)
 | 
			
		||||
    url = test_url(version)
 | 
			
		||||
    try:
 | 
			
		||||
        request = QtNetwork.QNetworkRequest(url)
 | 
			
		||||
        reply = netman.get(request)
 | 
			
		||||
        while not reply.isFinished():
 | 
			
		||||
            QtCore.QThread.msleep(1)
 | 
			
		||||
        return reply.attribute() == 200
 | 
			
		||||
            QtCore.QCoreApplication.processEvents()
 | 
			
		||||
        attr = reply.attribute(QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
 | 
			
		||||
        return 200 <= attr < 300
 | 
			
		||||
    except Exception as ex:
 | 
			
		||||
        util.log('TOXYGEN UPDATER ERROR: ' + str(ex))
 | 
			
		||||
        return False
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@ import os
 | 
			
		|||
import time
 | 
			
		||||
import shutil
 | 
			
		||||
 | 
			
		||||
program_version = '0.2.3'
 | 
			
		||||
program_version = '0.2.6'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def log(data):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue