Commit Graph

66 Commits

Author SHA1 Message Date
Glutanimate
4de09400c5 Fix timestamp comparison failing when update API returns null
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.
2019-04-08 17:51:15 +02:00
Damien Elmes
7d65594944
Merge pull request #288 from glutanimate/mediasrv-addon-support
Extend mediasrv to also serve media files in addons directory
2019-03-04 18:03:48 +10:00
Damien Elmes
da2ddcc6e2 explicitly import _ and ngettext 2019-03-04 11:58:34 +10:00
Glutanimate
5e90758f39 Allow add-on authors to set a whitelist of webview-accessible files
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.
2019-03-02 18:57:51 +01:00
Damien Elmes
d6915ff6e8 avoid traceback when network offline in add-on check 2019-02-27 14:18:16 +10:00
Damien Elmes
66cbc87580 ensure progress window cleared if error on add-on import 2019-02-27 14:08:20 +10:00
Damien Elmes
139e04c7c3 be explicit about text format when showing add-on errors
fixes br codes showing in error messages
2019-02-26 09:36:02 +10:00
Glutanimate
c45ea26cd6 Move annotatedName to AddonManager to allow outside access 2019-02-24 14:51:19 +01:00
Damien Elmes
86b3657969 clear selection when deleting add-on(s)
fixes error when deleting last, and wrong selection
otherwise
2019-02-24 15:24:31 +10:00
Glutanimate
195ca93cfe Preserve selected add-ons 2019-02-23 10:10:05 +01:00
Glutanimate
15a83df126 Colour disabled add-ons gray 2019-02-23 10:04:45 +01:00
Glutanimate
8725583c97 Add tooltip feedback for restoring defaults
Changes might not always be apparent, so a tooltip might help.
2019-02-23 09:39:49 +01:00
Glutanimate
1080ae10f9 Store addonconf geom and splitter. Tweak font sizes and margins. 2019-02-23 09:39:49 +01:00
Aristotelis
ff7b06fbda
Merge branch 'master' into install-local-addons 2019-02-23 09:27:17 +01:00
Glutanimate
512be4fc2c Implement add-on conflict handling via manifests "conflicts" value
Only enabled for locally installed packages for now
2019-02-22 21:14:42 +01:00
Glutanimate
8fceccf4b7 Refactor: Add manifest schema, unify install paths, use context manager
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.
2019-02-22 17:04:07 +01:00
Glutanimate
2ed61c9c99 Rename .apkx to .ankiaddon 2019-02-22 10:17:56 +01:00
Damien Elmes
ae67c97610 remember add-ons window geometry 2019-02-20 14:38:22 +10:00
Arthur-Milchior
c670dd65b4 Correct a bug during add-on update
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.
2019-02-18 12:29:08 +01:00
Glutanimate
280da9aee4 Fix linebreaks in add-on installation tooltips and warnings 2019-02-18 07:18:14 +01:00
Glutanimate
cc0dc812ad Implement drag-and-drop support for installing APKX-packaged add-ons 2019-02-18 07:17:53 +01:00
Glutanimate
4a21c2013f Ability to install add-ons from local add-on packages
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.
2019-02-18 07:17:14 +01:00
Glutanimate
11f3d77eb1 Switch to the system default monospaced font for the config editor area 2019-02-15 14:15:54 +01:00
Damien Elmes
aff810c18a make sure add-on list updates when toggling on qt 5.12/mac 2019-02-06 09:19:20 +10:00
Damien Elmes
372d5ed6e8 update copyright and clarify licenses 2019-02-05 14:01:33 +10:00
Damien Elmes
748f362695 fix the other json.dumps call
previous change was in the wrong place
33ae6404f1
2018-12-15 09:15:43 +10:00
Damien Elmes
33ae6404f1 don't escape unicode characters in add-on json
https://anki.tenderapp.com/discussions/ankidesktop/31423-configuration-module-of-addons-is-not-allowing-pt-br-accent
2018-12-13 21:34:55 +10:00
Damien Elmes
e4af18cf66 catch wrong objects in add-on conf
based on patch from Arthur: https://github.com/dae/anki/pull/261/files
2018-11-18 15:22:31 +10:00
Damien Elmes
6e9276e5a3 add missing translation line 2018-09-24 14:48:08 +10:00
Damien Elmes
36b763e45f
Merge pull request #251 from upday7/master
disable form.viewPage button when add-on was not downloaded from AnkiWeb
2018-09-02 18:03:14 +10:00
root
77e6b395e5 specify exception; convert match result to None 2018-08-31 15:13:06 +08:00
root
8aa27dcdf5 disable form.viewPage button when add-on was not downloaded from AnkiWeb 2018-08-31 14:56:16 +08:00
Glutanimate
8ce7c00d54 Pass new config on to add-on 2018-07-28 09:25:38 +02:00
Glutanimate
ee3357a943 Only update config if actually modified 2018-07-28 09:09:17 +02:00
Glutanimate
8935b99188 Extend add-on API with setConfigUpdatedAction
Allows add-on authors to define an action to be performed upon
manual editing of the add-on configuration through the ConfigEditor
2018-07-28 09:00:49 +02:00
Damien Elmes
9b5ee4ba44 change wording to differentiate from 'browse' in toolbar 2018-06-21 15:23:41 +10:00
Liam Cooke
0c1136e379 Read config.md as UTF-8 2018-04-05 22:11:44 +10:00
Damien Elmes
9a23f0958d load add-ons in consistent order
if ANKIREVADDONS env var is defined, reverse order for debugging

partially addresses pull req #225
2018-02-24 13:23:15 +11:00
Damien Elmes
118326df1e remove format literals so we can support python 3.5 2018-01-16 16:07:30 +10:00
Damien Elmes
81d4b77ee1 more open() and regex strings 2017-12-11 17:25:51 +10:00
Piotr Kubowicz
674d45a606 Allow to better translate add-ons dialog 2017-11-19 10:28:04 +01:00
Damien Elmes
5deb75f5c4 preserve user_files folder in add-ons 2017-09-10 18:53:47 +10:00
Damien Elmes
0bc4a1a220 replace _ with space in add-on names 2017-09-10 17:02:32 +10:00
Damien Elmes
2689c7cfe1 setConfigAction() and writeConfig() should work in submodules 2017-08-31 14:41:00 +10:00
Damien Elmes
5a11efa0e3 merge new keys from config.json into user conf 2017-08-30 15:31:03 +10:00
Damien Elmes
737a8d934e persistent add-on configuration
- 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)
2017-08-28 20:51:43 +10:00
Damien Elmes
76b4343c5e fix browse link 2017-08-26 22:40:11 +10:00
Damien Elmes
7288a9b063 new add-on handling
- 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-folders
https://apps.ankiweb.net/docs/addons21.html#sharing-add-ons

README.addons has been moved to the above page
2017-08-26 15:14:20 +10:00
luoliyan
c7e5a618a5 Fix NameError caused by missing import 2017-02-15 23:08:37 +09:30
Damien Elmes
b58c082e29 tweaks to add-on downloading
- avoid opening and closing multiple progress dialogs
- report errors at the end; download what we can
- update dialog text
2017-02-15 15:55:31 +10:00