Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- Fixed a potential crash on exit due to an unterminated thread.
- Little internal updater fixes.
- Do not log each time we check for updates.
  • Loading branch information
yan committed Jan 5, 2021
1 parent c3bcd15 commit f676a04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 3 additions & 1 deletion addon/globalPlugins/translate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def __init__(self):
self.language = languageHandler.getWindowsLanguage()[:2]
except:
self.language = 'en'
self.updater = updater.TranslateUpdater()
self.updater = updater.ExtensionUpdater()
self.updater.start()
self.inTimer = False
self.hasBeenUpdated = False
Expand All @@ -344,6 +344,8 @@ def terminate(self):
speech._manager.speak = _nvdaSpeak
speech.getPropertiesSpeech = _nvdaGetPropertiesSpeech
self.saveLocalCache()
self.updater.quit = True
self.updater.join()
def onTimer(self):
if self.inTimer is True or self.hasBeenUpdated is True:
return
Expand Down
10 changes: 4 additions & 6 deletions addon/globalPlugins/translate/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import json
import os

class TranslateUpdater(threading.Thread):
class ExtensionUpdater(threading.Thread):
quit = False
quitLock = threading.RLock()
queue = queue.Queue()

def run(self):
Expand All @@ -22,7 +21,6 @@ def run(self):
time.sleep(1)
if time.time() - self.lastCheck < UPDATE_CHECK_INTERVAL:
continue
logHandler.log.info("translate: Checking for update...")
try:
res = urllib.request.urlopen("http://www.mtyp.fr/nvda")
data = res.read()
Expand All @@ -31,7 +29,7 @@ def run(self):
if mod is not None:
new_version = self.getLatestVersion(mod)
if new_version is not None:
logHandler.log.info("Translate update available: %s" %(new_version["version"]))
logHandler.log.info("%s update available: %s" %(ADDON_NAME, new_version["version"]))
self.queue.put({"update": new_version})
self.download(new_version)
except Exception as ex:
Expand All @@ -42,7 +40,7 @@ def run(self):



logHandler.log.info("Translate: exiting update thred...")
logHandler.log.info("%s: exiting update thred..." %(ADDON_NAME))
def getLatestVersion(self, mod):
import addonHandler
actual = None
Expand Down Expand Up @@ -73,7 +71,7 @@ def download(self, mod):
f.write(res.read())
f.close()
except Exception as ex:
logHandler.log.error("Translate: failed to download %s: %s" %(mod["url"], ex))
logHandler.log.error("%s: failed to download %s: %s" %(ADDON_NAME, mod["url"], ex))
return False
self.queue.put({"download": tmp,
"version": mod["version"]})
Expand Down
2 changes: 1 addition & 1 deletion buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"addon_description" : _("""Uses the Google Translate API to translate each spoken text to the desired language, on the fly.
This add-on requires an internet connection."""),
# version
"addon_version" : "2021.01.1",
"addon_version" : "2021.01.2",
# Author(s)
"addon_author" : u"Yannick PLASSIARD <[email protected]>, Hxebolax",
# URL for the add-on documentation support
Expand Down

0 comments on commit f676a04

Please sign in to comment.