Addresses a rare instance of update checks failing when locally
installed packages point to a shared ID that has yet to be updated
to 2.1. In those instances Anki's update API returns null, which
causes a ValueError downstream when comparing the timestamps
against each other.
Extends the AddonManager API with two new methods, setWebExports and
getWebExports. setWebExports expects an add-on module name and a
valid RegEx pattern to match subpaths in the add-on folder against.
Any matching subpaths will be accessible in Anki's web views by
referencing them with /_addons/{addon_id}/{subpath}.
For instance, to allow access to .css and .png files in your add-on's
user_files directory you would call:
> mw.addonManager.setWebExports(__name__, r"user_files/.+(\.png|\.css)")
You could then reference these files in web views as such:
> <img src="/_addons/{addon_id}/user_files/test.png">
Please note that this bypasses the default security policies used
in Anki webviews. You should take care to construct your RegEx
patterns specific enough so that they do not match any sensitive
files of our add-on.
Sets the foundation for more elaborate additions to the manifest.
Manifest files are still only being read for local imports, but with
this commit that could be easily changed in the future.
If an add-on folder contains only number, but does not contains a
meta.json file, or if this file does not contains a "mod" value, then
the following uninformative message error occur:
```Python
File "aqt/addons.py", line 387, in onCheckForUpdates
File "aqt/addons.py", line 183, in checkForUpdates
File "aqt/addons.py", line 199, in _updatedIds
<class 'TypeError'>: '<' not supported between instances of 'NoneType' and 'int'
```
This is because there is a .get in a code while the None value makes
no sens. Thus, I replaced None by a 0 value. Which ensure that, if the
last modification time is missing, the update will be done. Three case
may occur:
* either the addon is already up to date, and it's only a waste of
bandwidth
* either the add-on is not up to date, and updating was the initial
goal anyway
* Or some change did occur in the add-on folder (which is actually
probably, since it would explain the "missing mod problem"; in this
case this change may be lost, but thout would be the same problem
if the mod number was still there.
Other solutions which I could implement would be:
* asking for the user whether they want to update
* considering that it's not an ankiweb related add-on anymore, and
ignore it.
Adds a new button to the add-on dialog that allows users to select
and install add-ons from local files.
Introduces APKX, a zip-based and manifest-backed filetype for
Anki add-on packages.
- add-ons can ship default config in a config.json file
- users can edit the config in the add-ons dialog, easily syntax-check
the json, and restore it to the defaults
- an optional config.md contains instructions to the user in markdown
format
- config will be preserved when add-on is updated, instead of being
overwritten as is the case when users are required to edit the source
files
A simple example: in config.json:
{"myvar": 5}
In your add-on's code:
from aqt import mw
config = mw.addonManager.getConfig(__name__)
print("var is", config['myvar'])
Add-ons that manage options in their own GUI can have that GUI
displayed when the config button is clicked:
mw.addonManager.setConfigAction(__name__, myOptionsFunc)
- separate dialog for managing add-ons
- only add-ons compatible with Anki 2.1 will be shown on AnkiWeb
- can delete or toggle disabled on multiple add-ons at once
- check for updates button
- button to view add-on's AnkiWeb page
The new handling drops support for single file .py add-ons, and requires
add-ons to store all files in a single folder. This ensures all files
are cleaned up properly when updating or deleting an add-on, and
prevents file conflicts between separate add-ons. See the updated
add-on docs for more:
https://apps.ankiweb.net/docs/addons21.html#add-on-foldershttps://apps.ankiweb.net/docs/addons21.html#sharing-add-ons
README.addons has been moved to the above page