Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JS Addons] list addons from addons directory #10985

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

krmanik
Copy link
Member

@krmanik krmanik commented Apr 20, 2022

Pull Request template

Purpose / Description

This is UI for addons listing in recycler view from addons directory. The list in view will contains details, remove and toggle switch button.
Also addons menu added to side bar but it will be hidden till all the PR merged.
The implementation will be used in next PR when addons listed from network for download and install.

Fixes

Fixes #7959

Approach

  1. dist package.json made empty when package.json loaded from local directory.
  2. Popup window class created to show info related the current clicked addons
  3. Added a class to list addons from directory, the validated AddonModel added to adapter
  4. Each view in list have three buttons
    details button - show popup with addons info like name, author, version etc.
    remove button - remove the addons from directory
    toggle switch - used to enable/disable addons, for enabled addons, the content will be added to reviewer or note editor

How Has This Been Tested?

Tested on emulator and devices. (Test will be added in next PR)

  1. Listing of empty folder
  2. Listing when one addon added manually (currently manually, in next PR download and install will be implemented)
  3. Info popup window test
  4. Toggle switch test
  5. Delete test
demo.mp4

Learning (optional, can help others)

Checklist

Please, go through these checks before submitting the PR.

  • You have not changed whitespace unnecessarily (it makes diffs hard to read)
  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • Your code follows the style of the project (e.g. never omit braces in if statements)
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

package.json in tgz file does not contains dist but it is available when the file loaded from network
the dist contains .tgz url which will be used to download the file
recycler view used to list addons with delete, details and toggle switch button.
delete button - remove the addons from directory
details button - show popup with addons info like name, author, version etc.
toggle switch - used to enable/disable addons, for enabled addons, the content will be added to reviewer or note editor
and show menu in debug mode
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of unrelated comments :-), I don't see anything really wrong here - a minor structural question, some Kotlin null-typing stuff and some grammar bikeshedding ... Curious for thoughts on all of them

AnkiDroid/src/main/res/values/02-strings.xml Outdated Show resolved Hide resolved
AnkiDroid/src/main/res/values/02-strings.xml Outdated Show resolved Hide resolved
AnkiDroid/src/main/res/values/02-strings.xml Show resolved Hide resolved
AnkiDroid/src/main/res/values/02-strings.xml Outdated Show resolved Hide resolved
AnkiDroid/src/main/res/values/02-strings.xml Outdated Show resolved Hide resolved
Comment on lines +53 to +55
supportActionBar!!.setHomeButtonEnabled(true)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.title = getString(R.string.javascript_addons)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate to see new Kotlin code with !! in it, is there any way to avoid this? "There is no way to avoid this" may be a valid answer, I'm just asking/hoping

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried but there is no option here. Either it should be wrapped in if/else. I have taken this from another class. So, I need to check more implementation for this.

Copy link
Member

@david-allison david-allison Apr 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For another issue if you agree @mikehardy

protected void enableToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
} else {
// likely missing "<include layout="@layout/toolbar" />"
Timber.w("Could not find toolbar");
}
}

If we change enableToolbar to return supportActionBar!! (or throw otherwise - the invalid case should be an error), we could:

enableToolbar().apply {
    setHomeButtonEnabled(true)
    setDisplayHomeAsUpEnabled(true)
    title = getString(R.string.javascript_addons)
}

Comment on lines 101 to 108
private fun deleteSelectedAddonPackageDir(addonModel: AddonModel) {
// remove the js addon folder
val currentAnkiDroidDirectory = CollectionHelper.getCurrentAnkiDroidDirectory(context)
val addonsHomeDir = File(currentAnkiDroidDirectory, "addons")
val dir = File(addonsHomeDir, addonModel.name)

val deleted = BackupManager.removeDir(dir)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to over-engineer it, but I feel like having the filesystem code mixed in with the UI code will make it harder to test etc - you have AddonModel, Is there an AddonStorage perhaps, where the "get me the add on directory / get me the list of addons in directory / delete the addon" code could go? Then it would be really easy to have a test just for that stuff

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created AddonStorage class. It is more cleaner and better implementation. Thanks

*
* @param addonModel
*/
private fun deleteSelectedAddonPackageDir(addonModel: AddonModel) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think delete can go in the new extracted AddOnStorage object now

Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's really close now - can put more into the storage class and use it by reference, and should probably do a second refactor as a follow-on to have code from previous PRs use the storage class as well and centralize all the directory / file handling (from the download/install/unpack PRs)

@mikehardy mikehardy added the Needs Author Reply Waiting for a reply from the original author label Apr 24, 2022
@krmanik
Copy link
Member Author

krmanik commented Apr 24, 2022

I think this is good idea to handle the addons related file/folder related from a centralized class. I will do refactor in next PR. (Added to TODO)

@krmanik krmanik added the Blocked by dependency Currently blocked by some other dependent / related change label Apr 25, 2022
@mikehardy
Copy link
Member

I'm going to move this to draft just as a strategy to manage the PR review queue, and because I know you are focused on exams right now (as you should be!). Cheers

@mikehardy mikehardy marked this pull request as draft May 10, 2022 15:40
@krmanik
Copy link
Member Author

krmanik commented May 11, 2022

I will update the PR later.

@github-actions
Copy link
Contributor

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Jul 10, 2022
@krmanik krmanik removed the Stale label Jul 10, 2022
@github-actions
Copy link
Contributor

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Dec 12, 2022
@mikehardy
Copy link
Member

Not stale - dormant because of too much work on my end and prioritizing scoped storage but this will all happen. JS addons are the future and this is the infrastructure...

@github-actions github-actions bot removed the Stale label Dec 18, 2022
@github-actions
Copy link
Contributor

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2023

Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Mar 5, 2023
@mikehardy mikehardy added Keep Open avoids the stale bot and removed Stale labels Mar 5, 2023
@mikehardy
Copy link
Member

The JS AddOn series needs to stay open. It is perfect for 2.17 once storage is finally done

@krmanik
Copy link
Member Author

krmanik commented Mar 6, 2023

The JS AddOn series needs to stay open. It is perfect for 2.17 once storage is finally done

I will start implementing this after scope storage.

@lukstbit
Copy link
Member

lukstbit commented Oct 4, 2024

@krmanik If you want I can look into fixing and updating the code in this PR to get it merged. Maybe the other related PR as well.

@mikehardy
Copy link
Member

Pains me greatly that these aren't merged yet and I feel a lot of responsibility there - not sure how @krmanik feels about it but I would owe you or anyone a debt of gratitude if the work here was finally shepherded in. It's good stuff IMHO and would be a big step forward I think

@david-allison
Copy link
Member

@BrayanDSO I believe you had the last conversation regarding addons in the forums. Pinging for your understanding & thoughts

@BrayanDSO
Copy link
Member

Reviewer add-ons won't happen in the desktop version if they aren't 99,99% secure, and Damien apparently doesn't want it even as a per-notetype opt-in setting with a big warning or just stopped replying because he's busy with something else.

To avoid duplicating the bulletproofing job in the mobile versions, the reviewer should ideally be moved to Svelte first.

I do think that there should be a JS API and addons infrastructure as soon as possible so we can take advantage of the work of other developers. If we wait until all of those desktop issues to be solved (probably at least 3 years from now if I'm optimistic with the current development pace), we will lose a lot of work that could be done in the addons ecosystem in that meantime.

There are a lot of developers, including myself, that may have some time and motivation right now, but not in the future. I could have implemented the whole infrastructure when I created the forums post, but I lost two weeks just in discussion, and stopped getting replied. Now I don't have time for it, nor I want to do it anymore in the future.

So I strongly suggest to continue the JS addons work here in AnkiDroid. To avoid issues in the future, like when Anki implemented a different TTS syntax, I suggest consulting Damien and making him compromise with the API, with whatever is saved in the collection, and with the way that addons are distributed.
That way, things won't break if he wants to distribute things in GitHub with zip files instead of npm with tar.gz, or save the addons list ordered by creation date instead of ID (just an invented example, idk what is planned).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked by dependency Currently blocked by some other dependent / related change Has Conflicts Keep Open avoids the stale bot Needs Author Reply Waiting for a reply from the original author Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] JavaScript Addons support for AnkiDroid
5 participants