ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.62k stars 2.23k forks source link

Add ability to load media from JS #14762

Closed sarsamurmu closed 11 months ago

sarsamurmu commented 11 months ago

Is your feature request related to a problem? Please describe. I tried to load media in JS using the fetch() method. But it gives error that file:// protocol is not valid in fetch()

Describe the solution you'd like Maybe a new AnkiDroid JS API could solve that.

Describe alternatives you've considered I can embed the data I need in the card itself but it's would break functionality of addons in Anki desktop.

Additional context https://www.reddit.com/r/medicalschoolanki/comments/17xfqkl/image_occlusion_enhanced_one_by_one_incremental/ This script internally uses fetch() to load the SVG in a card. Without the SVG the script is basically useless.

welcome[bot] commented 11 months ago

Hello! 👋 Thanks for logging this issue. Please remember we are all volunteers here, so some patience may be required before we can get to the issue. Also remember that the fastest way to get resolution on an issue is to propose a change directly, https://github.com/ankidroid/Anki-Android/wiki/Contributing

krmanik commented 11 months ago

The file can be loaded now, because the card content is served using nano http server, so anything in collection.media can be accessed using fetch.

sarsamurmu commented 11 months ago

Thanks for fixing the issue :)

Is it supported in the latest alpha version? Or is it not yet released?

krmanik commented 11 months ago

It is supported in latest alpha version.

sarsamurmu commented 11 months ago

Nice! Thanks again.

sarsamurmu commented 11 months ago

The feature works fine. But it looks like it doesn't work when you're not connected to any Wi-Fi network. Maybe starting the server in localhost (127.0.0.1) would solve this.

sarsamurmu commented 11 months ago

It looks like the problem is not caused by not starting on 127.0.0.1

Apparantly the main thread is getting blocked somehow when not connected to network. Whenever I tap a deck to start reviewing it takes almost 10-15 seconds after the reviewer screen shows up

sarsamurmu commented 11 months ago

For some reason the problem vanished, I will let you know if the problem appears again

mikehardy commented 11 months ago

There have been a few problems @sarsamurmu (and @krmanik ) with regards to the new "AnkIDroid now runs it's own client/server architecture internally" setup when network is unavailable or changing or something. I just read through them and I haven't seen any conclusive resolution about the same. So please keep a close close eye on that and any sort of testing you can do (turning different networks like cellular, wifi, vpn or not, off and on, app cold start / hot start) and checking status to see if you can get a solid reproduction would be great