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
This commit is contained in:
mailchuck 2015-10-19 22:33:18 +02:00
parent dd47b9ab65
commit 5660f039a6
No known key found for this signature in database
GPG Key ID: B6311FA753FBF089
2 changed files with 40 additions and 0 deletions

View File

@ -718,6 +718,8 @@ class MyForm(QtGui.QMainWindow):
"rerenderBlackWhiteList()"), self.rerenderBlackWhiteList) "rerenderBlackWhiteList()"), self.rerenderBlackWhiteList)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"removeInboxRowByMsgid(PyQt_PyObject)"), self.removeInboxRowByMsgid) "removeInboxRowByMsgid(PyQt_PyObject)"), self.removeInboxRowByMsgid)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"newVersionAvailable(PyQt_PyObject)"), self.newVersionAvailable)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL( QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"displayAlert(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.displayAlert) "displayAlert(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.displayAlert)
self.UISignalThread.start() self.UISignalThread.start()
@ -1815,6 +1817,31 @@ class MyForm(QtGui.QMainWindow):
break break
self.changedInboxUnread() 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): def displayAlert(self, title, text, exitAfterUserClicksOk):
self.statusBar().showMessage(text) self.statusBar().showMessage(text)
QtGui.QMessageBox.critical(self, title, text, QMessageBox.Ok) QtGui.QMessageBox.critical(self, title, text, QMessageBox.Ok)
@ -4145,6 +4172,8 @@ class UISignaler(QThread):
self.emit(SIGNAL("rerenderBlackWhiteList()")) self.emit(SIGNAL("rerenderBlackWhiteList()"))
elif command == 'removeInboxRowByMsgid': elif command == 'removeInboxRowByMsgid':
self.emit(SIGNAL("removeInboxRowByMsgid(PyQt_PyObject)"), data) self.emit(SIGNAL("removeInboxRowByMsgid(PyQt_PyObject)"), data)
elif command == 'newVersionAvailable':
self.emit(SIGNAL("newVersionAvailable(PyQt_PyObject)"), data)
elif command == 'alert': elif command == 'alert':
title, text, exitAfterUserClicksOk = data title, text, exitAfterUserClicksOk = data
self.emit(SIGNAL("displayAlert(PyQt_PyObject, PyQt_PyObject, PyQt_PyObject)"), title, text, exitAfterUserClicksOk) self.emit(SIGNAL("displayAlert(PyQt_PyObject, PyQt_PyObject, PyQt_PyObject)"), title, text, exitAfterUserClicksOk)

View File

@ -698,6 +698,17 @@ class receiveDataThread(threading.Thread):
data[80:84]) data[80:84])
readPosition = 80 + lengthOfUseragentVarint readPosition = 80 + lengthOfUseragentVarint
useragent = data[readPosition:readPosition + useragentLength] 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 readPosition += useragentLength
numberOfStreamsInVersionMessage, lengthOfNumberOfStreamsInVersionMessage = decodeVarint( numberOfStreamsInVersionMessage, lengthOfNumberOfStreamsInVersionMessage = decodeVarint(
data[readPosition:]) data[readPosition:])