automatic version upgrade

This commit is contained in:
Alex Yatskov 2017-02-19 13:18:07 -08:00
parent ea38f95d6d
commit c2d280726f

View File

@ -230,7 +230,7 @@ class AjaxServer:
def handlerWrapper(self, req): def handlerWrapper(self, req):
if len(req.body) == 0: if len(req.body) == 0:
body = 'AnkiConnect v.{}'.format(API_VERSION) body = makeBytes('AnkiConnect v.{}'.format(API_VERSION))
else: else:
try: try:
params = json.loads(makeStr(req.body)) params = json.loads(makeStr(req.body))
@ -502,10 +502,12 @@ class AnkiConnect:
if response == QMessageBox.Yes: if response == QMessageBox.Yes:
data = download(URL_UPGRADE) data = download(URL_UPGRADE)
if data is None: if data is None:
QMessageBox.critical(self.anki.window, 'AnkiConnect', 'Failed to download latest version') QMessageBox.critical(self.anki.window, 'AnkiConnect', 'Failed to download latest version.')
else: else:
with open(__file__, 'w') as fp: path = os.path.splitext(__file__)[0] + '.py'
fp.write(data) with open(path, 'w') as fp:
fp.write(makeStr(data))
QMessageBox.information(self.anki.window(), 'AnkiConnect', 'Upgraded to the latest version.')
def api_version(self): def api_version(self):