Skip to content

Commit

Permalink
Merge pull request #23 from actlaboratory/cat/compat
Browse files Browse the repository at this point in the history
compat: Support NVDA 2025.1 later and older versions without deprecation warning
  • Loading branch information
yncat authored Feb 16, 2025
2 parents 76c758f + 5217d3b commit b314a5a
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions addon/globalPlugins/UML/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@
AUTO=0
MANUAL=1

def isCompatibleWith2025():
return versionInfo.version_year >= 2025

def messageBox(message, title):
if isCompatibleWith2025():
gui.message.MessageDialog.alert(message, title)
else:
gui.messageBox(message, title, style=wx.CENTER)

def confirm(message, title):
if isCompatibleWith2025():
return gui.message.MessageDialog.confirm(message, title) == gui.message.ReturnCode.OK
else:
return gui.messageBox(message, title, style=wx.CENTER | wx.OK | wx.CANCEL | wx.ICON_INFORMATION) == wx.ID_OK


class AutoUpdateChecker:
def __init__(self):
self.updater = None
Expand Down Expand Up @@ -69,13 +85,12 @@ def check_update(self):
f = urlopen(req)
except BaseException:
if self.mode == MANUAL:
gui.messageBox(strs.ERROR_UNABLE_TO_CONNECT,
strs.ERROR, style=wx.CENTER | wx.ICON_WARNING)
messageBox(strs.ERROR_UNABLE_TO_CONNECT, strs.ERROR)
return False

if f.getcode() != 200:
if self.mode == MANUAL:
gui.messageBox(strs.ERROR_UNABLE_TO_CONNECT_SERVERSIDE, strs.ERROR, style=wx.CENTER | wx.ICON_WARNING)
messageBox(strs.ERROR_UNABLE_TO_CONNECT_SERVERSIDE, strs.ERROR)
return False

try:
Expand All @@ -84,31 +99,25 @@ def check_update(self):
update_dict = json.loads(update_dict)
except BaseException:
if self.mode == MANUAL:
gui.messageBox(
strs.ERROR_UPDATE_INFO_INVALID,
strs.ERROR,
style=wx.CENTER | wx.ICON_WARNING)
gui.messageBox(strs.ERROR_UPDATE_INFO_INVALID, strs.ERROR)
return False

code = update_dict["code"]
if code == UPDATER_LATEST:
if self.mode == MANUAL:
gui.messageBox(strs.NO_UPDATES, strs.UPDATE_CHECK_TITLE, style=wx.CENTER | wx.ICON_INFORMATION)
messageBox(strs.NO_UPDATES, strs.UPDATE_CHECK_TITLE)
return False
elif code == UPDATER_BAD_PARAM:
if self.mode == MANUAL:
gui.messageBox(strs.ERROR_REQUEST_PARAMETERS_INVALID,
strs.UPDATE_CHECK_TITLE, style=wx.CENTER | wx.ICON_INFORMATION)
messageBox(strs.ERROR_REQUEST_PARAMETERS_INVALID, strs.UPDATE_CHECK_TITLE)
return False
elif code == UPDATER_NOT_FOUND:
if self.mode == MANUAL:
gui.messageBox(strs.UPDATER_NOT_REGISTERED,
strs.UPDATE_CHECK_TITLE, style=wx.CENTER | wx.ICON_INFORMATION)
messageBox(strs.UPDATER_NOT_REGISTERED, strs.UPDATE_CHECK_TITLE)
return False
elif code == UPDATER_VISIT_SITE:
if self.mode == MANUAL:
gui.messageBox(strs.UPDATE_NOT_POSSIBLE,
strs.UPDATE_CHECK_TITLE, style=wx.CENTER | wx.ICON_INFORMATION)
messageBox(strs.UPDATE_NOT_POSSIBLE, strs.UPDATE_CHECK_TITLE)
return False

new_version = update_dict["update_version"]
Expand All @@ -122,8 +131,8 @@ def check_update(self):
caption = strs.UPDATE_CONFIRMATION_TITLE
question = strs.UPDATE_CONFIRMATION_MESSAGE.format(
summary=addonSummary, newVersion=new_version, currentVersion=addonVersion)
answer = gui.messageBox(question, caption, style=wx.CENTER | wx.OK | wx.CANCEL | wx.CANCEL_DEFAULT | wx.ICON_INFORMATION)
if answer == wx.OK:
answer = confirm(question, caption)
if answer == True:
downloader = UpdateDownloader(addonName, [url], hash)
wx.CallAfter(downloader.start)
return
Expand Down Expand Up @@ -158,10 +167,7 @@ def start(self):
def _error(self):
self._stopped()
self.cleanup_tempfile()
gui.messageBox(
strs.ERROR_DOWNLOADING,
strs.ERROR,
wx.OK | wx.ICON_ERROR)
messageBox(strs.ERROR_DOWNLOADING, strs.ERROR)

def _download(self, url):
headers = {}
Expand Down Expand Up @@ -216,9 +222,7 @@ def _downloadSuccess(self):
bundle = addonHandler.AddonBundle(self.destPath)
except BaseException:
log.error("Error opening addon bundle from %s" % self.destPath, exc_info=True)
gui.messageBox(strs.ERROR_OPENING % self.destPath,
strs.ERROR,
wx.OK | wx.ICON_ERROR)
messageBox(strs.ERROR_OPENING % self.destPath, strs.ERROR)
return
bundleName = bundle.manifest['name']
for addon in addonHandler.getAvailableAddons():
Expand All @@ -234,9 +238,7 @@ def _downloadSuccess(self):
log.error("Error installing addon bundle from %s" % self.destPath, exc_info=True)
progressDialog.done()
del progressDialog
gui.messageBox(strs.ERROR_FAILED_TO_UPDATE % self.destPath,
strs.ERROR,
wx.OK | wx.ICON_ERROR)
messageBox(strs.ERROR_FAILED_TO_UPDATE % self.destPath, strs.ERROR)
return
else:
progressDialog.done()
Expand Down

0 comments on commit b314a5a

Please sign in to comment.