Skip to content

Commit

Permalink
Merge f9aefda into 1af8775
Browse files Browse the repository at this point in the history
  • Loading branch information
josephsl committed Aug 1, 2019
2 parents 1af8775 + f9aefda commit 9568e7e
Show file tree
Hide file tree
Showing 6 changed files with 383 additions and 20 deletions.
67 changes: 64 additions & 3 deletions source/addonHandler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# -*- coding: UTF-8 -*-
#addonHandler.py
#addonHandler/__init__.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2012-2019 Rui Batista, NV Access Limited, Noelia Ruiz Martínez, Joseph Lee, Babbage B.V., Arnold Loubriat
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.

"""Manages add-ons
The add-on handler provides a definition of an add-on bundle, as well as functions to install, remove, disable/enable, and update add-on bundles.
See https://addons.nvda-project.org for more information on NVDA community add-ons.
See the NVDA developer guide for more info on writing add-ons.
"""

import sys
import os.path
import gettext
Expand All @@ -19,9 +25,13 @@
from six import string_types
import globalVars
import zipfile
import urllib
import threading
import wx
# #3208 todo: tentatively use JSON for exchanging add-on update data.
import json
from configobj import ConfigObj
from configobj.validate import Validator

import config
import globalVars
import languageHandler
Expand Down Expand Up @@ -57,6 +67,8 @@ def loadState():
state["pendingDisableSet"] = set()
if "pendingEnableSet" not in state:
state["pendingEnableSet"] = set()
if "noUpdates" not in state:
state["noUpdates"] = set()
except:
# Defaults.
state = {
Expand All @@ -65,6 +77,7 @@ def loadState():
"disabledAddons":set(),
"pendingEnableSet":set(),
"pendingDisableSet":set(),
"noUpdates":set(),
}

def saveState():
Expand Down Expand Up @@ -145,6 +158,53 @@ def disableAddonsIfAny():
state["pendingDisableSet"].clear()
state["pendingEnableSet"].clear()

def checkForAddonUpdates():
# Prepare to receive a record of add-ons with update checking turned off.
if "noUpdates" not in state:
state["noUpdates"] = set()
curAddons = {}
addonSummaries = {}
for addon in getAvailableAddons():
name = addon.name
# Only check for updates for add-ons that can check for updates.
if name in state["noUpdates"]: continue
manifest = addon.manifest
curVersion = manifest["version"]
curAddons[name] = {"summary": manifest["summary"], "version": curVersion}
addonSummaries[name] = {"summary": manifest["summary"], "curVersion": curVersion}
data = json.dumps(curAddons)
# Pseudocode:
"""try:
res = urllib.request.open(someURL, data)
# Check SSL and what not.
res = json.loads(res)"""
res = json.loads(data)
for addon in res:
res[addon].update(addonSummaries[addon])
# In reality, it'll be a list of URL's to try.
res[addon]["urls"] = None
return res

def autoAddonUpdateCheck():
t = threading.Thread(target=_showAddonUpdateUI)
t.daemon = True
t.start()

def _showAddonUpdateUI():
def _showAddonUpdateUICallback(info):
# The only purpose of this callback is to force add-on updates window to show up at startup.
import gui
from gui.addonGui import AddonUpdatesDialog
gui.mainFrame.prePopup()
AddonUpdatesDialog(gui.mainFrame, info).Show()
gui.mainFrame.postPopup()
try:
info = checkForAddonUpdates()
except:
info = None
if info is not None:
wx.CallAfter(_showAddonUpdateUICallback, info)

def initialize():
""" Initializes the add-ons subsystem. """
if config.isAppX:
Expand All @@ -158,7 +218,8 @@ def initialize():
disableAddonsIfAny()
getAvailableAddons(refresh=True)
saveState()

# #3208 todo: Check for add-on updates unless NVDA itself is updating right now.
#checkForAddonUpdates()

def terminate():
""" Terminates the add-ons subsystem. """
Expand Down
1 change: 1 addition & 0 deletions source/config/configSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
startupNotification = boolean(default=true)
allowUsageStats = boolean(default=false)
askedAllowUsageStats = boolean(default=false)
addonUpdateAtStartup = boolean(default=true)
[inputComposition]
autoReportAllCandidates = boolean(default=True)
Expand Down
Loading

0 comments on commit 9568e7e

Please sign in to comment.