[Feature] JavaScript Addons Support#7958
Conversation
|
This is first commit and need help in implementing way to store the activated addons status. |
Codecov Report
@@ Coverage Diff @@
## master #7958 +/- ##
============================================
- Coverage 37.11% 36.70% -0.42%
+ Complexity 3854 3791 -63
============================================
Files 361 358 -3
Lines 36326 36209 -117
Branches 4798 4778 -20
============================================
- Hits 13484 13291 -193
- Misses 21310 21409 +99
+ Partials 1532 1509 -23 Continue to review full report at Codecov.
|
|
I really like the general idea. A small note about screen capture. I believe you could easily improve it by turning on android's preference option to display where you click/touch. This way, it'll become easier to follow what you are doing. |
|
This will greatly help in introducing some features of Anki addons that can be implemented using JavaScript for AnkiDroid using JS API. For example I will implement the feature if file with Also there will be some place where user can search and find AnkiDroid JS addons like https://addon-docs.ankiweb.net/ |
|
This is second commit to this PR. |
|
For importing addon, addon must contain two files. content.html is file which get added to webview and manifest.json used for getting id. The id in manifest.json and folder name of addon must be same. The structure of In this case addon folder name and id both are The folder For testing I attached two jsaddons js_addons_progress_bar_12345678.zip js_addons_top_bar_12345678.zip Change the extension from zip to |
|
I'm sorry I haven't given this a real scan yet, but I wonder if it we could use the standard package.json format and thus rely on npmjs.com for distribution etc 🤔 ? |
|
I haven't implemented any packages for npmjs so I will study the distribution. The format can be updated to package.json but for distribution I will read the documentation and then try to implement. Distribution from npmjs will be better because there will no need for Anki Ecosystem to view and manage those files. That totally rely on developer. I will view the documentation of npmjs for better implementation. :) |
|
the package.json format is definitely the most well known. It defines an entry point for the package, naming (and npmjs.com will enforce unique names :-)) plus I think you can tag on npmjs.com with keywords so we could do a search or something for "ankidroid-js-addon" or something if we make a convention for that. It can also define homepages and version and dependencies (regular ones, devDependencies, peerDependencies) etc. For our purposes we likely won't be using anything but the most basic keywords in the package.json format but it keeps us using standard things which is nice |
|
I understood it. I will change the manifest.json to package.json and will use useful and needed keywords from package.json. |
|
Implementation
|
This is outdated now.
|
|
I have still been booked up completely on some contract work but every time I see one of your animated gifs it is 🤤 ! this looks very powerful |
|
The information need for contract is stored in package.json file. I think, gifs is better than written description for explaining workflow of the PR. As it changes ui element also. :) |
|
Also I think that one file in wiki should list all the addons that has been added to npmjs by a developer like wiki/Third-Party-Apps. New addons can be listed by the addon developer. |
|
Is there way to do "discovery by convention" with a search powered by someone else? That way all the search/discovery would be offloaded to npmjs.com and add on authors? zero maintenance burden unless npmjs.com changed their URL query interface... |
|
I found this url useful. In app we may add option for Get more addons.
|
|
Implementation
If in latest json file, Also added option to |
|
Implementation
Idea: |
Update addon info popup layout and remove prefs when addon delete
|
Update 1: Change addon info popup layout Update 2: Remove prefs when addon delete Update 3: Added a new addon for button and card counts to npmjs |
- added volley library for downloading json from npmjs - code cleanup
- Options in advance settings - Layout for showing message when no addons added - Open npmjs.org url in AnkiDroid - comments added
Arthur-Milchior
left a comment
There was a problem hiding this comment.
Are 22 commits really useful ? Hard to review from scratch right now. For example, I'd like "first commit" to explain a little bit more what I'm reading. I don't know NPM at all, I don't really know JS, so I need commit message to guide me through what's going on to be able to review this
| @@ -0,0 +1,7 @@ | |||
| package com.ichi2.anki; | |||
|
|
|||
| public class AddonsBrowserTest extends RobolectricTest { | |||
There was a problem hiding this comment.
What's the point of an empty class?
There was a problem hiding this comment.
To pass build of project.
|
I think it is not good idea to review from |
|
I am creating new PR for this with detailed commit message. |
|
Squashing everything will not really help me. I can not really read 1157 new lines of code and check that I'm okay with all of them. It's particularly hard because I don't know anything about JS and NPM and other tool you use. It is possible that you actually can not split this into smaller commits that all makes sens by themselves; it sometime happens and makes things hard. However, ideally, what I would love to see is a story. You make a first commit that compiles, pass tests, with a commit message that explains to me and future reader why you do it, why it is useful. Then you add another part of the code etc... |
|
I have created separate PR because creating is easy and better than rewriting history. :) |





Pull Request template
Purpose / Description
Using AnkiDroid JS API a deck can be extended to implement features like progress bar or custom card layouts. But it requires user to manually add the
html/css/jsto card templates. This is implementation for a way to inject code to all deck templates when addons get activated.Fixes
Fixes #7959
Approach
It will check following string in latest package.json
There isValidPackageJson boolean function will check for above values if present then the addons is valid.
enabledaddons'index.jscontent wrapped in<script>tag will be added tofillFlashCard()inAbstractFlashcardViewer.javaThere are two types of addon
reviewerandnote_editor. In this PR, reviewer addon is implemented.Idea for
note_editoraddon:The javascript function can be called using https://github.com/evgenyneu/js-evaluator-for-android/#call-a-javascript-function . So, in note editor multiple buttons will get added to toolbar with tag containing addons' name. When the toolbar button pressed, it will take
selected textfrom FieldEditText and pass to jsEvaluate java function. The jsEvaluate java function will get tag of clicked toolbar button and open js file with name equal to tag of button and pass the selected text to addon's function implementation. The addon's js function will return the manipulated string to FieldEditText in note editor. Even if other implementation can be done without selected text as defined in js file in addon's folder. This will implemented in separated PR.How Has This Been Tested?
Tested on emulator
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration (SDK version(s), emulator or physical, etc)
Learning (optional, can help others)
https://developer.android.com/guide/topics/ui/layout/recyclerview
Checklist
Please, go through these checks before submitting the PR.
ifstatements)