Skip to content

Commit

Permalink
Updated add-on templates, updated for compatibility with NVDA2023.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
cary-rowen committed Mar 8, 2023
1 parent 805de7b commit ce9d45e
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-ast
- id: check-case-conflict
- id: check-yaml
12 changes: 12 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-python.python",
"ms-python.vscode-pylance",
"redhat.vscode-yaml"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
25 changes: 25 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"editor.accessibilitySupport": "on",
"python.linting.enabled": true,
"python.linting.maxNumberOfProblems": 10000,
"python.linting.flake8Args": [
"--config=flake8.ini"
],
"python.linting.flake8Enabled": true,
"python.linting.pylintEnabled": false,
"python.autoComplete.extraPaths": [
"../nvda/source",
"../nvda/miscDeps/python"
],
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"editor.insertSpaces": false,
"python.analysis.diagnosticSeverityOverrides": {
"reportUndefinedVariable": "none"
},
"python.analysis.extraPaths": [
"../nvda/source",
"../nvda/miscDeps/python"
],
"python.defaultInterpreterPath": "../nvda/.venv/scripts/python.exe"
}
8 changes: 6 additions & 2 deletions addon/doc/zh_CN/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
作者: Ibrahim Hamadeh, Cary-Rowen, Belala Toufik
NVDA 兼容性:2018.3 及更高版本

下载 [2.7版][1]
下载 [2.8版][1]


该插件可以从选中的文本、剪贴板中的文本或最后一次朗读的文本中提取所包含的链接,并显示在一个弹出对话框的列表内,您可以选择使用已安装的浏览器打开列表中的链接。
Expand All @@ -23,6 +23,10 @@ NVDA 兼容性:2018.3 及更高版本
* 如果只有一个链接可以直接使用默认浏览器打开,当然这是一个可选项,在设置面板中可以开启 / 关闭。
* 您还可以在设置面板中设置是否在打开链接后关闭链接对话框。

## 2.7 的变化 ##
* 更新了插件模板。
* 将最后测试的 NVDA 版本更新为 2023.1 以兼容最新的 API 更改。


## 2.7 的变化 ##

Expand Down Expand Up @@ -55,4 +59,4 @@ NVDA 兼容性:2018.3 及更高版本
## 1.0 的变化 ##
* 初始版本

[1]: https://github.com/ibrahim-s/openLinkWith/releases/download/v2.7/openLinkWith-2.7.nvda-addon
[1]: https://github.com/ibrahim-s/openLinkWith/releases/download/v2.8/openLinkWith-2.8.nvda-addon
16 changes: 10 additions & 6 deletions buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,29 @@ def _(arg):
Press the command you assotiated with the addon via input gestures, to display OpenLinkWith dialog.
"""),
# version
"addon_version": "2.7",
"addon_version": "2.8",
# Author(s)
"addon_author": u"Ibrahim Hamadeh <[email protected]>, Cary Rowen <[email protected]>, Belala Toufik<[email protected]>",
"addon_author": "Ibrahim Hamadeh <[email protected]>, Cary Rowen <[email protected]>, Belala Toufik<[email protected]>",
# URL for the add-on documentation support
"addon_url": "https://github.com/ibrahim-s/openLinkWith.git",
# URL for the add-on repository where the source code can be found
"addon_sourceURL": "https://github.com/ibrahim-s/openLinkWith.git",
# Documentation file name
"addon_docFileName": "readme.html",
# Minimum NVDA version supported (e.g. "2018.3.0", minor version is optional)
"addon_minimumNVDAVersion": "2018.3.0",
# Last NVDA version supported/tested (e.g. "2018.4.0", ideally more recent than minimum version)
"addon_lastTestedNVDAVersion": "2022.1.0",
"addon_lastTestedNVDAVersion": "2023.1.0",
# Add-on update channel (default is None, denoting stable releases,
# and for development releases, use "dev".)
# Do not change unless you know what you are doing!
"addon_updateChannel": None,
# Add-on license such as GPL 2
"addon_license": None,
# URL for the license document the ad-on is licensed under
"addon_licenseURL": None,
}

import os.path

# Define the python files that are the sources of your add-on.
# You can either list every file (using ""/") as a path separator,
# or use glob expressions.
Expand All @@ -55,7 +59,7 @@ def _(arg):
# pythonSources = ["addon/globalPlugins/*.py"]
# For more information on SCons Glob expressions please take a look at:
# https://scons.org/doc/production/HTML/scons-user/apd.html
pythonSources = [os.path.join("addon", "globalPlugins", "OpenLinkWith", "*.py"), ]
pythonSources = ["addon/globalPlugins/OpenLinkWith/*.py"]

# Files that contain strings for translation. Usually your python sources
i18nSources = pythonSources + ["buildVars.py"]
Expand Down
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Authors: Ibrahim Hamadeh, Cary Rowen, Belala Toufik
NVDA compatibility: 2018.3 and beyond
Download [Version 2.7][1]
Download [Version 2.8][1]

This addon is used to extract links either from selected, clipboard, or last spoken text
display them in a list in a dialog
Expand All @@ -24,6 +24,10 @@ and give you the opportunity to open them with several browsers if found on your
* If there is only one link, you can choose to be opened directly with the default browser. this obtion can be adjusted in the settings panel.
* In the settings panel also, remember that you got the obtion to close the dialog, after activating a link.

## Changes for 2.8 ##
* Updated add-on template.
* Update last tested version to 2023.1, to comply with latest addon api.

## Changes for 2.7 ##

* Now, You can extract the links from the text in last spoken.
Expand Down Expand Up @@ -61,4 +65,4 @@ So that we have the obtion to close the dialog after activating a link.

* Initial version.

[1]: https://github.com/ibrahim-s/openLinkWith/releases/download/v2.7/openLinkWith-2.7.nvda-addon
[1]: https://github.com/ibrahim-s/openLinkWith/releases/download/v2.8/openLinkWith-2.8.nvda-addon
95 changes: 93 additions & 2 deletions sconstruct
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# NVDA add-on template SCONSTRUCT file
# Copyright (C) 2012-2021 Rui Batista, Noelia Martinez, Joseph Lee
# Copyright (C) 2012-2023 Rui Batista, Noelia Martinez, Joseph Lee
# This file is covered by the GNU General Public License.
# See the file COPYING.txt for more details.

Expand Down Expand Up @@ -75,8 +75,21 @@ def mdTool(env):
env['BUILDERS']['markdown'] = mdBuilder


def validateVersionNumber(key, val, env):
# Used to make sure version major.minor.patch are integers to comply with NV Access add-on store.
# Ignore all this if version number is not specified, in which case json generator will validate this info.
if val == "0.0.0":
return
versionNumber = val.split(".")
if len(versionNumber) < 3:
raise ValueError("versionNumber must have three parts (major.minor.patch)")
if not all([part.isnumeric() for part in versionNumber]):
raise ValueError("versionNumber (major.minor.patch) must be integers")


vars = Variables()
vars.Add("version", "The version of this build", buildVars.addon_info["addon_version"])
vars.Add("versionNumber", "Version number of the form major.minor.patch", "0.0.0", validateVersionNumber)
vars.Add(BoolVariable("dev", "Whether this is a daily development version", False))
vars.Add("channel", "Update channel for this build", buildVars.addon_info["addon_updateChannel"])

Expand All @@ -87,7 +100,9 @@ if env["dev"]:
import datetime
buildDate = datetime.datetime.now()
year, month, day = str(buildDate.year), str(buildDate.month), str(buildDate.day)
env["addon_version"] = "".join([year, month.zfill(2), day.zfill(2), "-dev"])
versionTimestamp = "".join([year, month.zfill(2), day.zfill(2)])
env["addon_version"] = f"{versionTimestamp}-dev"
env["versionNumber"] = f"{versionTimestamp}.0.0"
env["channel"] = "dev"
elif env["version"] is not None:
env["addon_version"] = env["version"]
Expand Down Expand Up @@ -155,9 +170,85 @@ def createAddonBundleFromPath(path, dest):
absPath = os.path.join(dir, filename)
if pathInBundle not in buildVars.excludedFiles:
z.write(absPath, pathInBundle)
createAddonStoreJson(dest)
return dest


def createAddonStoreJson(bundle):
"""Creates add-on store JSON file from an add-on package and manifest data."""
import json
import hashlib
# Set different json file names and version number properties based on version number parsing results.
if env["versionNumber"] == "0.0.0":
env["versionNumber"] = buildVars.addon_info["addon_version"]
versionNumberParsed = env["versionNumber"].split(".")
if all([part.isnumeric() for part in versionNumberParsed]):
if len(versionNumberParsed) == 1:
versionNumberParsed += ["0", "0"]
elif len(versionNumberParsed) == 2:
versionNumberParsed.append("0")
else:
versionNumberParsed = []
if len(versionNumberParsed):
major, minor, patch = [int(part) for part in versionNumberParsed]
jsonFilename = f'{buildVars.addon_info["addon_name"]}-{major}.{minor}.{patch}.json'
else:
jsonFilename = f'{buildVars.addon_info["addon_name"]}-{buildVars.addon_info["addon_version"]}.json'
major, minor, patch = 0, 0, 0
print('Generating % s' % jsonFilename)
sha256 = hashlib.sha256()
with open(bundle, "rb") as f:
for byte_block in iter(lambda: f.read(65536), b""):
sha256.update(byte_block)
hashValue = sha256.hexdigest()
try:
minimumNVDAVersion = buildVars.addon_info["addon_minimumNVDAVersion"].split(".")
except AttributeError:
minimumNVDAVersion = [0, 0, 0]
minMajor, minMinor = minimumNVDAVersion[:2]
minPatch = minimumNVDAVersion[-1] if len(minimumNVDAVersion) == 3 else "0"
try:
lastTestedNVDAVersion = buildVars.addon_info["addon_lastTestedNVDAVersion"].split(".")
except AttributeError:
lastTestedNVDAVersion = [0, 0, 0]
lastTestedMajor, lastTestedMinor = lastTestedNVDAVersion[:2]
lastTestedPatch = lastTestedNVDAVersion[-1] if len(lastTestedNVDAVersion) == 3 else "0"
channel = buildVars.addon_info["addon_updateChannel"]
if channel is None:
channel = "stable"
addonStoreEntry = {
"addonId": buildVars.addon_info["addon_name"],
"displayName": buildVars.addon_info["addon_summary"],
"URL": "",
"description": buildVars.addon_info["addon_description"],
"sha256": hashValue,
"homepage": buildVars.addon_info["addon_url"],
"addonVersionName": buildVars.addon_info["addon_version"],
"addonVersionNumber": {
"major": major,
"minor": minor,
"patch": patch
},
"minNVDAVersion": {
"major": int(minMajor),
"minor": int(minMinor),
"patch": int(minPatch)
},
"lastTestedVersion": {
"major": int(lastTestedMajor),
"minor": int(lastTestedMinor),
"patch": int(lastTestedPatch)
},
"channel": channel,
"publisher": "",
"sourceURL": buildVars.addon_info["addon_sourceURL"],
"license": buildVars.addon_info["addon_license"],
"licenseURL": buildVars.addon_info["addon_licenseURL"],
}
with open(jsonFilename, "w") as addonStoreJson:
json.dump(addonStoreEntry, addonStoreJson, indent="\t")


def generateManifest(source, dest):
addon_info = buildVars.addon_info
with codecs.open(source, "r", "utf-8") as f:
Expand Down

0 comments on commit ce9d45e

Please sign in to comment.