Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions addon/globalPlugins/updateChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import globalPluginHandler
import addonHandler
import versionInfo
import buildVersion
import config
from gui import guiHelper, NVDASettingsDialog
from gui.settingsDialogs import SettingsPanel
Expand Down Expand Up @@ -41,10 +41,10 @@


def getVersionStringFromBuildValues():
"""Creates a build string from the release year, mayor and minor versions.
"""Creates a build string from the release year, major and minor versions.
This string is used for version info to work around issue 3.
"""
return ".".join(map(str, (versionInfo.version_year, versionInfo.version_major, versionInfo.version_minor)))
return ".".join(map(str, (buildVersion.version_year, buildVersion.version_major, buildVersion.version_minor)))


def getConfiguredChannel():
Expand All @@ -63,20 +63,20 @@ def checkForUpdateReplacement(auto=False):
# and for the duration of retrieving update info replace real NVDA's version with it.
# We cannot do this when initializing the plugin
# as this breaks the process of creating portable copies (see issue #5).
ORIG_NVDA_VERSION = versionInfo.version
ORIG_NVDA_VERSION = buildVersion.version
IS_ALPHA = originalChannel == "snapshot:alpha"
shouldReplaceVersion = False
if IS_ALPHA and versionInfo.updateVersionType != originalChannel:
if IS_ALPHA and buildVersion.updateVersionType != originalChannel:
shouldReplaceVersion = True
if shouldReplaceVersion is False and IS_ALPHA and getConfiguredChannel() in {1, 2}:
shouldReplaceVersion = True
if shouldReplaceVersion:
versionInfo.version = getVersionStringFromBuildValues()
buildVersion.version = getVersionStringFromBuildValues()
try:
return updateCheck.checkForUpdate_orig(auto)
finally:
if shouldReplaceVersion:
versionInfo.version = ORIG_NVDA_VERSION
buildVersion.version = ORIG_NVDA_VERSION


class UpdateChannelPanel(SettingsPanel):
Expand Down Expand Up @@ -110,7 +110,7 @@ def makeSettings(self, sizer):
self.status = 0
self.event = Event()
# It is done in a separate thread so as not to slow down the execution.
self.thGetAvailableUpdates = Thread(target=self.getAvailableUpdates, args=(versionInfo.updateVersionType,))
self.thGetAvailableUpdates = Thread(target=self.getAvailableUpdates, args=(buildVersion.updateVersionType,))
self.thGetAvailableUpdates.setDaemon(True)
self.thGetAvailableUpdates.start()
self.onChoice(None)
Expand All @@ -122,15 +122,15 @@ def getAvailableUpdates(self, currentChannel): # noqa C901
break
if channel == "default" or not channel:
continue
versionInfo.updateVersionType = channel
buildVersion.updateVersionType = channel
try:
self.availableUpdates[channel] = updateCheck.checkForUpdate()
except RuntimeError: # Thrown by `updateCheck.checkForUpdate`
self.availableUpdates[channel] = -1 # An error occurred
else:
if not self.availableUpdates[channel]:
self.availableUpdates[channel] = 1 # Already updated
versionInfo.updateVersionType = currentChannel
buildVersion.updateVersionType = currentChannel
try:
# Don't wait for wx.EVT_CHOICE, update selected channel in self.channels now.
if self.channels.Selection == 0:
Expand All @@ -143,13 +143,13 @@ def getAvailableUpdates(self, currentChannel): # noqa C901
pass
self.event.wait()
if self.status == 1:
versionInfo.updateVersionType = channels[config.conf.profiles[0]['updateChannel']['channel']]\
buildVersion.updateVersionType = channels[config.conf.profiles[0]['updateChannel']['channel']]\
if config.conf.profiles[0]['updateChannel']['channel'] != 0\
else originalChannel
elif self.status == 2:
# Workaround for issue 3
if originalChannel == "snapshot:alpha" and originalChannel == currentChannel:
versionInfo.updateVersionType = currentChannel
buildVersion.updateVersionType = currentChannel

def displayUpdateInfo(self, updateVersionInfo): # noqa C901
""" Select the appropriate message and put it in the edit box and updates de hyperlinks. """
Expand Down Expand Up @@ -196,7 +196,7 @@ def displayUpdateInfo(self, updateVersionInfo): # noqa C901
if channels[self.channels.Selection] is None:
# TRANSLATORS: When disable updates has been selected, the current version information is displayed.
channelInfo = _("Current version: {version} build {version_build}").format(
version=versionInfo.version, version_build=versionInfo.version_build)
version=buildVersion.version, version_build=buildVersion.version_build)
self.channelInfo.Value = channelInfo
if not showLinks:
if self.download.IsShown():
Expand Down Expand Up @@ -229,9 +229,9 @@ def onSave(self):
# When configuring for the first time, required keys are created in the normal profile
config.conf.profiles[0]['updateChannel'] = {'channel': self.channels.Selection}
if self.channels.Selection == 0:
versionInfo.updateVersionType = originalChannel
buildVersion.updateVersionType = originalChannel
else:
versionInfo.updateVersionType = channels[config.conf.profiles[0]['updateChannel']['channel']]
buildVersion.updateVersionType = channels[config.conf.profiles[0]['updateChannel']['channel']]
# This prevents an issue caused when updates were downloaded without installing and the channel was changed.
# Reset the state dictionary and save it
try:
Expand Down Expand Up @@ -268,12 +268,12 @@ def __init__(self):
if globalVars.appArgs.secure or config.isAppX or not updateCheck: # Security checks
return
global originalChannel
originalChannel = versionInfo.updateVersionType
originalChannel = buildVersion.updateVersionType
index = getConfiguredChannel()
if index > len(channels):
index = 0
if index > 0:
versionInfo.updateVersionType = channels[index]
buildVersion.updateVersionType = channels[index]
NVDASettingsDialog.categoryClasses.append(UpdateChannelPanel)
if updateCheck is not None:
updateCheck.checkForUpdate_orig = updateCheck.checkForUpdate
Expand All @@ -291,7 +291,7 @@ def terminate(self):
pass
try:
NVDASettingsDialog.categoryClasses.remove(UpdateChannelPanel)
versionInfo.updateVersionType = originalChannel
buildVersion.updateVersionType = originalChannel
originalChannel = None
except Exception:
pass