From 2ec04ede404dda61fc05be13a16dc87491d3bf6d Mon Sep 17 00:00:00 2001 From: mailchuck Date: Mon, 19 Oct 2015 22:33:18 +0200 Subject: [PATCH] Passive version check Bitmessage will now notify you if it encounters someone with a newer version. Takes into account that it should not recommend switching from stable to unstable and vice versa. Also, temporarily treats 0.5 as a mailchuck fork. Fixes #43 --- src/bitmessageqt/__init__.py | 29 +++++++++++++++++++++++++++++ src/class_receiveDataThread.py | 11 +++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index ea16a045..2b994dd7 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -718,6 +718,8 @@ class MyForm(QtGui.QMainWindow): "rerenderBlackWhiteList()"), self.rerenderBlackWhiteList) QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( "removeInboxRowByMsgid(PyQt_PyObject)"), self.removeInboxRowByMsgid) + QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( + "newVersionAvailable(PyQt_PyObject)"), self.newVersionAvailable) QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( "displayAlert(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.displayAlert) self.UISignalThread.start() @@ -1816,6 +1818,31 @@ class MyForm(QtGui.QMainWindow): inbox.removeRow(i) break self.changedInboxUnread() + + def newVersionAvailable(self, version): +# if (not (self.windowState() & QtCore.Qt.WindowActive)) or (self.windowState() & QtCore.Qt.WindowMinimized): +# print "SHIIIIIIIIIIIIIIIIT" +# return + # only notify once until next restart + try: + if self.notifiedNewVersion: + return + except AttributeError: + pass + + self.notifiedNewVersion = ".".join(str(n) for n in version) + message = "New " + if version[1] % 2: + message += "UNSTABLE" + else: + message += "stable" + message += " version of PyBitmessage is available: " + self.notifiedNewVersion + ". Download it from https://github.com/" + if version[0] == 0 and version[1] == 5: + message += "mailchuck" + else: + message += "Bitmessage" + message += "/PyBitmessage/releases/latest" + self.displayAlert("New release of PyBitmessage available", message, False) def displayAlert(self, title, text, exitAfterUserClicksOk): self.statusBar().showMessage(text) @@ -4147,6 +4174,8 @@ class UISignaler(QThread): self.emit(SIGNAL("rerenderBlackWhiteList()")) elif command == 'removeInboxRowByMsgid': self.emit(SIGNAL("removeInboxRowByMsgid(PyQt_PyObject)"), data) + elif command == 'newVersionAvailable': + self.emit(SIGNAL("newVersionAvailable(PyQt_PyObject)"), data) elif command == 'alert': title, text, exitAfterUserClicksOk = data self.emit(SIGNAL("displayAlert(PyQt_PyObject, PyQt_PyObject, PyQt_PyObject)"), title, text, exitAfterUserClicksOk) diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index ff5371ad..07569b7b 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -698,6 +698,17 @@ class receiveDataThread(threading.Thread): data[80:84]) readPosition = 80 + lengthOfUseragentVarint useragent = data[readPosition:readPosition + useragentLength] + + # version check + userAgentName, userAgentVersion = useragent[1:-1].split(":") + if userAgentName == "PyBitmessage": + myVersion = [int(n) for n in shared.softwareVersion.split(".")] + remoteVersion = [int(n) for n in userAgentVersion.split(".")] + # remote is newer, but do not cross between stable and unstable + if cmp(remoteVersion, myVersion) > 0 and \ + (myVersion[1] % 2 == remoteVersion[1] % 2): + shared.UISignalQueue.put(('newVersionAvailable', remoteVersion)) + readPosition += useragentLength numberOfStreamsInVersionMessage, lengthOfNumberOfStreamsInVersionMessage = decodeVarint( data[readPosition:])