Commit graph

3649 commits

Author SHA1 Message Date
Luc Mcgrady
f5285f359a
Feat/Add legacy evaluate config bool (#4149)
* Feat/Add legacy evaluate config bool

* Minor tweaks based on PR suggestions (dae)

New enabling command:

from anki.config import Config
mw.col.set_config_bool(Config.Bool.FSRS_LEGACY_EVALUATE, True)
2025-07-04 15:32:09 +07:00
Damien Elmes
bb1b289690 Add some helpers to allow add-ons to install packages into the venv
While something we probably don't want to encourage much of, this
may enable some previously-unshared add-ons.

https://forums.ankiweb.net/t/bundling-numpy-in-an-add-on/62669/5

The 'uv add' command is transaction, so if an add-on tries to inject
incompatible dependencies into the environment, the venv will be
left as-is. And each Anki upgrade/downgrade resets the requirements,
so the requested packages shouldn't cause errors down the line.

Sample add-on:

import subprocess
from aqt import mw
from aqt.operations import QueryOp
from aqt.qt import QAction
from aqt.utils import showInfo

def ensure_spacy(col):
    print("trying to import spacy")
    try:
        import spacy
        print("successful import")
        return
    except Exception as e:
        print("error importing:", e)

    print("attempting add")
    try:
        from aqt.package import add_python_requirements as add
    except Exception as e:
        raise Exception(f"package unavailable, can't install: {e}")
    # be explicit about version, or Anki beta users will get
    # a beta wheel that may break
    (success, output) = add(["spacy==3.8.7", "https://github.com/explosion/spacy-models/releases/download/ko_core_news_sm-3.8.0/ko_core_news_sm-3.8.0-py3-none-any.whl"])
    if not success:
        raise Exception(f"adding failed: {output}")

    print("success")

    # alterantively:
    # from aqt.package import venv_binary
    # subprocess.run([venv_binary("spacy"), "download", "ko_core_news_sm"], check=True)
    # print("model added")

    # large packages will freeze for a while on first import on macOS
    import spacy
    print("spacy import successful")

def activate_spacy():
    def on_success(res):
        mw.progress.single_shot(1000, lambda: showInfo("Spacy installed"))

    QueryOp(parent=mw, op=ensure_spacy, success=on_success).with_progress("Installing spacy...").run_in_background()

action = QAction("Activate Spacy", mw)
action.triggered.connect(activate_spacy)
mw.form.menuTools.addAction(action)
2025-07-04 14:23:04 +07:00
Damien Elmes
e81a7e8b1a Stop enabling betas by default 2025-07-02 12:57:02 +07:00
llama
14eb297bbf
add "copy debug info" button to show_exception's dialog (#4146) 2025-07-01 15:35:50 +07:00
Damien Elmes
a07370f565 Add a trademark symbol to the readme and about screens 2025-07-01 11:40:03 +07:00
Damien Elmes
0be87b887e Add category type
Unsure if this helps; the app is not even showing in the screen time
list for me at the moment.

https://forums.ankiweb.net/t/correct-apple-screen-time-category-macos-ios/62962
2025-06-30 14:28:37 +07:00
Damien Elmes
bce3cabf9b Friendlier error when glibc too old, and properly declare min macOS 2025-06-30 14:20:42 +07:00
Damien Elmes
469fd763c7 Fix taskbar pinning on Windows
Closes #4107
2025-06-29 20:53:43 +07:00
Damien Elmes
6eb1db0f5d Switch to the windows crate 2025-06-29 16:49:20 +07:00
Damien Elmes
349a696f93 Fix transient console pop-ups on Windows 2025-06-29 16:46:45 +07:00
Damien Elmes
66f34da7ef Fix lint, and ensure Rust checks get re-run on launcher change 2025-06-29 15:54:31 +07:00
Damien Elmes
3d7dc32777 Add a 'revert to previous version' action + more
- Show current version
- Ensure uv builds switch to python 3.13
2025-06-29 15:51:15 +07:00
Abdo
f94d05bcbe
Switch to Ruff (#4119)
* Add check:ruff build action

* Add fix:ruff action

* Add Ruff config

Mostly generated by Cursor

* Handle rest of lints

* Fix formatting

* Replace black and isort with ruff-format

* Run ruff-format

* Fix lint errors

* Remove pylint disables

* Remove .pylintrc

* Update docs

* Fix check:format not just checking

* Fix isort rule being ignored

* Sort imports

* Ensure ./ninja format also handles import sorting

* Remove unused isort cfg

* Enable unsafe fixes in fix:ruff, and enable unused var warning

* Re-run on config change; enable unnecessary ARG ignores

* Use all pycodestyle errors, and add some more commented-out ones

Latter logged on https://github.com/ankitects/anki/issues/4135
2025-06-29 14:38:35 +07:00
Damien Elmes
b8963b463e Fix Windows CI and minor display tweak 2025-06-29 13:54:17 +07:00
Damien Elmes
bdb3c714dc Put Python install inside uv root as well 2025-06-29 13:42:15 +07:00
Damien Elmes
731e7d5b5c Add uninstall support to launcher 2025-06-29 13:32:06 +07:00
Damien Elmes
f89ab00236 Update to Rust 1.88
We'll need to handle https://github.com/ankitects/anki/issues/4134 before
we get access to let chains.
2025-06-29 11:50:49 +07:00
Damien Elmes
b872852afe Store uv cache inside AnkiProgramFiles, and allow disabling 2025-06-29 11:50:49 +07:00
Damien Elmes
aa8dfe1cf4 Fix icon/menu entries on macOS after update
We need to exec() Python from a GUI context so that the app name and
icon are inherited from our launcher bundle. And we need to munge
sys.argv[0] prior to main window instantiation so that we don't get
app menu entries like "Hide -c". We do that in the launcher instead
of __init__.py so that older versions display correctly too.
2025-06-29 11:50:49 +07:00
Damien Elmes
f5073b402a Inject Upgrade/Downgrade menu item and audio support into older versions 2025-06-29 11:50:49 +07:00
GithubAnon0000
cfeb71724d
CHANGE right-click in the editor to show option to open folder in linux (#4125)
* CHANGE right-click in the editor to show option to open folder in linux

* FIX checks

* Use heuristics

* ./ninja format

* Use fallback from main instead of xdg-open
2025-06-28 21:33:17 +03:00
Damien Elmes
bedab0a54b Drop psutil from wheel requirements
We're not using it ourselves, and usage appears isolated to a couple of
add-ons (notably ankirestart)
2025-06-27 16:10:12 +07:00
Damien Elmes
de7de82f76 Refactor launcher + various tweaks
- Launcher can now be accessed via Tools>Upgrade/Downgrade
- Anki closes automatically on update
- When launcher not available, show update link like in the past
- It appears that access to the modern console host requires an app
to be built with the windows console subsystem, so we introduce an
extra anki-console.exe binary to relaunch ourselves with. Solves
https://forums.ankiweb.net/t/new-online-installer-launcher/62745/50
- Windows now requires you to close the terminal like on a Mac,
as I couldn't figure out how to have it automatically close. Suggestions
welcome!
- Reduce the amount of duplicate/near-duplicate code in the various
platform files, and improve readability
- Add a helper to install the current code into the launcher env
- Fix cargo test failing to build on ARM64 Windows
2025-06-27 16:10:12 +07:00
Damien Elmes
9b287dc51a Python dependency/wheel tweaks
- Use --locked to assert that the lockfile won't change, so we need
to explicitly 'uv lock' when making changes. Still trying to get to
the bottom of why the lockfile sometimes has editable entries, which
break things when switching between platforms.
- Exclude __pycache__ from wheels
- Move the typing stubs to our dev deps
(https://github.com/ankitects/anki/pull/4074#pullrequestreview-2948088436)
2025-06-27 16:10:12 +07:00
Damien Elmes
7edd9221ac Avoid Qt's automatic About labeling
It gets confused by our launcher process, and provides no way to
alter the default assigned text while keeping the About role on a Mac.
2025-06-27 16:10:12 +07:00
llama
d6f93fab76
adjust top toolbar height on body class update (#4120) 2025-06-25 14:20:31 +03:00
Damien Elmes
b250a2f724 Add terminal support for *nix 2025-06-22 21:52:44 +07:00
Damien Elmes
d2f818fad2 macOS launcher improvements
- do mpv initial run in parallel
- improve messages, show dots regularly
2025-06-22 21:03:02 +07:00
Damien Elmes
eb6c977e08 Add menu to launcher, and improve terminal display on Windows 2025-06-22 20:25:15 +07:00
Damien Elmes
246fa75a35 Create release wheel as part of normal build
Avoids the need for a separate publish
2025-06-21 19:17:48 +07:00
Damien Elmes
b781dfabf5 Add helpers to run Qt 6.7 and 6.9
Removed the 6.8 one, as that's our default
2025-06-20 21:55:38 +07:00
Damien Elmes
718f39fdf3 Temporarily force-enable prereleases
Some users are struggling to read or understand the steps to enable
it.
2025-06-20 19:05:30 +07:00
Damien Elmes
cd71931506 Launcher tweaks
- Handle beta/rc tags in .version when launching Anki
- Update pyproject.toml/.python_version if distributed version newer
- Support prerelease marker to opt in to betas
- Check for updates when using uv sync
- Avoid system Python by default, as it can cause breakages
(e.g. ARM Python installed on Windows)
2025-06-20 16:13:50 +07:00
Damien Elmes
4abc0eb8b8 Use same version for anki-release; publish to main index 2025-06-20 16:13:50 +07:00
Damien Elmes
a60a955c61 Handle beta/rc tags, bump beta, add exact version pin to aqt 2025-06-20 16:13:50 +07:00
Damien Elmes
a41c60c016 Trigger uv sync if user approves update 2025-06-20 16:13:50 +07:00
Damien Elmes
8e20973c52 Drop remaining qt5 code 2025-06-20 16:13:50 +07:00
Damien Elmes
cd411927cc Split libankihelper into a separate module
It's rarely updated, and the old approach resulted in a 'proper' aqt
build only being done on a Mac.
2025-06-20 16:13:49 +07:00
Damien Elmes
f98f620116 Avoid committing release deps
These will only get bumped on a new publish, and keeping the file
around leads to spurious security alerts.
2025-06-19 14:14:57 +07:00
Damien Elmes
04996c77f3
Migrate build system to uv (#4074)
* Migrate build system to uv

Closes #3787, and is a step towards #3081 and #4022

This change breaks our PyOxidizer bundling process. While we probably
could update it to work with the new venvs & lockfile, my intention
is to use this as a base to try out a uv-based packager/installer.

Some notes about the changes:

- Use uv for python download + venv installation
- Drop python/requirements* in favour of pyproject files / uv.lock
- Bumped to latest Python 3.9 version. The move to 3.13 should be
a fairly trivial change when we're ready.
- Dropped the old write_wheel.py in favour of uv/hatchling. This has
the unfortunate side-effect of dropping leading zeros in our wheels,
which we could try hack around in the future.
- Switch to Qt 6.7 for the dev repo, as it's the first PyQt version
with a Linux/ARM WebEngine wheel.
- Unified our macOS deployment target with minimum required for ARM.
- Dropped unused fluent python files
- Dropped unused python license generation
- Dropped helpers to run under Qt 5, as our wheels were already
requiring Qt 6 to install.

* Build action to create universal uv binary

* Drop some PyOxidizer-related files

* Use Windows ARM64 cargo/node binaries during build

We can't provide ARM64 wheels to users yet due to #4079, but we can
at least speed up the build.

The rustls -> native-tls change on Windows is because ring requires
clang to compile for ARM64, and I figured it's best to keep our Windows
deps consistent. We already built the wheels with native-tls.

* Make libankihelper a universal library

We were shipping a single arch library in a purelib, leading to
breakages when running on a different platform.

* Use Python wheel for mpv/lame on Windows/Mac

This is convenient, but suboptimal on a Mac at the moment. The first
run of mpv will take a number of seconds for security checks to run,
and our mpv code ends up timing out, repeating the process each time.
Our installer stub will need to invoke mpv once first to get it validated.

We could address this by distributing the audio with the installer/stub,
or perhaps by putting the binaries in a .pkg file that's notarized+stapled
and then included in the wheel.

* Add some helper scripts to build a fully-locked wheel

* Initial macOS launcher prototype

* Add a hidden env var to preload our libs and audio helpers on macOS

* qt/bundle -> qt/launcher

- remove more of the old bundling code
- handle app icon

* Fat binary, notarization & dmg

* Publish wheels on testpypi for testing

* Use our Python pin for the launcher too

* Python cleanups

* Extend launcher to other platforms + more

- Switch to Qt 6.8 for repo default, as 6.7 depends on an older
libwebp/tiff which is unavailable on newer installs
- Drop tools/mac-x86, as we no longer need to test against Qt 5
- Add flags to cross compile wheels on Mac and Linux
- Bump glibc target to 2_36, building on Debian Stable
- Increase mpv timeout on macOS to allow for initial gatekeeper checks
- Ship both arm64 and amd64 uv on Linux, with a bash stub to pick
the appropriate arch.

* Fix pylint on Linux

* Fix failure to run from /usr/local/bin

* Remove remaining pyoxidizer refs, and clean up duplicate release folder

* Rust dep updates

- Rust 1.87 for now (1.88 due out in around a week)
- Nom looks involved, so I left it for now
- prost-reflect depends on a new prost version that got yanked

* Python 3.13 + dep updates

Updated protoc binaries + add helper in order to try fix build breakage.
Ended up being due to an AI-generated update to pip-system-certs that
was not reviewed carefully enough:
https://gitlab.com/alelec/pip-system-certs/-/issues/36

The updated mypy/black needed some tweaks to our files.

* Windows compilation fixes

* Automatically run Anki after installing on Windows

* Touch pyproject.toml upon install, so we check for updates

* Update Python deps

- urllib3 for CVE
- pip-system-certs got fixed
- markdown/pytest also updated
2025-06-19 14:03:16 +07:00
Damien Elmes
a63e4ef1c8 Revert "Ignore TaskManager's on_done callback if collection unloaded (#4076)"
This reverts commit ccc42227d8.

Closes #4094
2025-06-19 13:17:30 +07:00
llama
669312d5eb
Fix unescaped deck names potentially missing from overview (#4084)
* html-escape deck name in overview

* move escaping past hook
2025-06-18 11:35:02 +07:00
Abdo
ccc42227d8
Ignore TaskManager's on_done callback if collection unloaded (#4076)
* Ignore TaskManager's on_done callback if collection unloaded

* Check col.db
2025-06-13 10:45:41 +07:00
Damien Elmes
50b7588231
Treat play_file() and co as internal routines without protection (#4059)
* Treat play_file() and co as internal routines without protection

Our code and add-ons need a way to play audio from arbitrary locations. I propose we treat the _tag API as suitable for user input, and the _file API for internal use.

* Mention basename in the *_file() paths
2025-06-06 12:55:04 +07:00
Ren Tatsumoto
29e3146e1f
trim file to basename before creating SoundOrVideoTag (#4057)
* trim file to basename before creating SoundOrVideoTag

* add import
2025-06-04 18:03:14 +07:00
llama
996fa8bcb0
add answer key shortcuts to grade now dialog (#4055) 2025-06-04 12:15:33 +07:00
Damien Elmes
37984233cc Restore cert error check
https://forums.ankiweb.net/t/bug-unknown-error-on-startup-anki-25-02/61232/3
2025-06-02 16:52:09 +07:00
Damien Elmes
f81a9bfdfb
Fix mpv being left around on abrupt termination (#4042)
Closes #4015
2025-06-01 13:16:28 +07:00
Damien Elmes
96ff27d1fb
Ensure media files are passed relative to the media folder (#4041)
We were (partially) doing this for MpvManager, but not for
Windows' SimpleMpvPlayer. By passing a media file starting
with a special scheme, a malicious actor could have caused a file to
be written to the filesystem on Windows.

Thanks once again to Michael Lappas for the report.
2025-06-01 13:16:04 +07:00
Damien Elmes
757247d424 Use more secure API key
https://github.com/ankitects/anki/pull/3925#discussion_r2051494659
2025-05-31 16:01:03 +07:00
Damien Elmes
6cdebd7638 Fix inverted margin logic
https://github.com/ankitects/anki/pull/4040#issuecomment-2921626962
2025-05-30 22:48:31 +07:00
llama
f9f0894162
Add left margin to browser when sidebar is closed (#4040)
* add left margin to browser when sidebar is closed

* listen for event instead of explicit user action

* refresh sidebar on visibility change

* Add a margin on macOS even when not collapsed

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2025-05-30 13:35:06 +07:00
Marvin Kopf
7a8b4a193f
offload mpv callback registration to background thread to avoid UI blocking (#4038)
Instantiating `MPV(MPVBase)` triggers multiple synchronous `command()` calls to the mpv process during callback registration. These calls block the main thread and degrade startup performance. This change defers registration via `taskman.run_in_background`.
2025-05-30 13:05:06 +07:00
Luc Mcgrady
f29bcb743b
Feat/Desired retention warning improvements (#3995)
* Feat/90% desired retention warning

* Update ftl/core/deck-config.ftl

* show on newly enabled

* Show warning on focus

* Never hide warning

* Display relative change

* Add: Separate warning for too long and short

* Revert unchanged text changes

* interval -> workload

* Remove dead code

* fsrs-rs/@L-M-Sherlock's workload calculation

* Added: delay

* CONSTANT_CASE

* Fix: optimized state

* Removed "Processing"

* Remove dead code

* 1 digit precision

* bump fsrs-rs

* typo

* Apply suggestions from code review

Co-authored-by: Damien Elmes <dae@users.noreply.github.com>

* Improve rounding

* improve comment

* rounding <1%

* decrease rounding precision

* bump ts-fsrs

* use actual cost values

* ./check

* typo

* include relearning

* change factor wording

* simplify sql

* ./check

* Apply suggestions from code review

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>

* Fix: missing search_cids

* @dae's style patch

* Fix: Doesn't update on arrow keys change

* force two lines

* center two lines

---------

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>
2025-05-27 13:07:21 +10:00
GithubAnon0000
6a1d55ae75
ADD myself to about.py (#4026) 2025-05-22 22:55:37 +10:00
Luc Mcgrady
8694b3b410
Use non breaking spaces for names on about page (#4025)
* use non breaking spaces for names on about page

* Update qt/aqt/about.py

Co-authored-by: llama <gh@siid.sh>

---------

Co-authored-by: llama <gh@siid.sh>
2025-05-22 22:55:15 +10:00
GithubAnon0000
e989564be2
FIX borken support link (#4019)
https://github.com/ankitects/anki/issues/4017
2025-05-22 21:40:13 +10:00
Emmanuel Ferdman
8a61a5470c
Resolve Python regex library warnings (#4012)
* Resolve Python regex library warnings

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>

* Add CONTRIBUTORS

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
2025-05-19 13:29:54 +10:00
Damien Elmes
d3d6bd8ce0 Skip ytdl flag on macOS ARM
Fixes sounds failing to play in the packaged build on macOS.
2025-05-15 19:04:26 +10:00
llama
413b73d9f4
fix onNote potentially discarding editor field changes (#4001) 2025-05-15 16:48:56 +10:00
Adnane Taghi
f96c8c2ac8 Make URL schemes dialog more ergonomic (#4002)
(originally merged into a PR branch)

* Make URL schemes dialog more ergonomic

* add name to contributors list

* Title Case

* Tweak build instructions so Cursor picks them up

* Use a warning icon for the URL scheme pop-up

* Default to cancelling
2025-05-15 16:17:33 +10:00
Damien Elmes
86c89907e7
Add URL scheme whitelist (#3994)
* Add experimental Cursor rules

* Add the ability to customize URL schemes

Closes #3965
2025-05-15 15:37:49 +10:00
Luc Mcgrady
f7cdf4eb9e
Fix/Leech suspended tooltip (#3992)
* Fix/Leech suspended popup

* extra check

* Fix: None check

* move comment
2025-05-15 15:14:10 +10:00
Damien Elmes
5080451829 Disable YouTube DL in mpv
mpv looks for ytdl on the path, which includes the CWD on Windows.
A malicious shared deck could place an executable called yt-dlp.exe in the
media folder, which mpv would then helpfully invoke the first time
a YouTube link was encountered.

A big thank you to Michael Lappas for the report.
2025-05-10 19:31:06 +10:00
llama
9025202204
properly construct file url when opening image/folder on linux (#3986) 2025-05-08 23:29:46 +10:00
Abdo
80618cad85
Clear notetypes cache on import (#3969)
* Clear notetypes cache on import

* Clear cache in AnkiQt.on_operation_did_execute() instead
2025-05-08 23:11:47 +10:00
Damien Elmes
d1bb69aaec Remove unused import 2025-05-05 18:08:31 +10:00
Abdo
b84f2d7873
Use correct debug scripts folder (#3973) 2025-05-05 17:26:04 +10:00
Jarrett Ye
92cfb7340e
add ellipsis to Grade Now (#3970)
* add ellipsis to Grade Now

* Revert "add ellipsis to Grade Now"

This reverts commit 8a3cf51c9e.

* add ellipsis to Grade Now
2025-04-29 16:43:14 +10:00
llama
51b5086b01
Fix unescaped deck names missing from tooltips when deleted (#3960) 2025-04-29 02:18:56 +03:00
Evgeny Kulikov
2acdc8c30a
Close only "child" window (e.g. Preview) inside Browser on Cmd+W (#3913)
Currently, if a user tries to close Preview which was opened inside Browse, the "parent" Browse window itself gets closed

Co-authored-by: beyondcompute <beyondcompute@users.noreply.github.com>
2025-04-27 18:25:20 +10:00
JL710
62bad44eed
add toggle for browser sidebar (#3953)
* add toggle for browser sidebar

* Update CONTRIBUTORS
2025-04-27 18:22:56 +10:00
Damien Elmes
365d50012c Add another contributor to the about screen as requested 2025-04-25 18:42:54 +10:00
Jonathan Schoreels
863fe3cd50
Add a way to pass information from browser_will_search to browser_did_search without having it going to the backend (#3945)
* Add a way to pass information from browser_will_search to browser_did_search without having it going to the backend

* Allow None for SearchContext.properties

* Adding myself in CONTRIBUTORS

* Rename SearchContext.properties to SearchContext.addon_metadata

* Revert "Adding myself in CONTRIBUTORS"

This reverts commit a993577279.

* Reapply "Adding myself in CONTRIBUTORS"

This reverts commit f3ce51c83d.
2025-04-25 18:40:24 +10:00
Evgeny Kulikov
fe2c1510ca
Add Cmd+W close shortcut (on Mac) to more dialogs (#3905)
* Enable Cmd+W shortcut in "Edit Current" on Mac

* Enable Cmd+W shortcut in "Fields" editor on Mac

* Enable Cmd+W shortcut in "Cards" editing on Mac

* Enable Cmd+W shortcut in "Sync" tab modal on Mac

* Enable Cmd+W shortcut in "Custom Study" tab modal on Mac

* Enable Cmd+W shortcut in Settings view on Mac

* Enable Cmd+W shortcut in Export dialogs on Mac

* Enable Cmd+W shortcut for getText dialog on Mac

* Enable Cmd+W shortcut in "Change Deck" on Mac

* Enable Cmd+W shortcut in Reposition dialog on Mac

* Enable Cmd+W shortcut in "Grade Now" dialog on Mac

* Enable Cmd+W shortcut in "Reset…" dialog on Mac

* Remove duplicate camelCase variant of add_close_shortcut (dae)

- The camelCase variant will remain accessible with a warning.
- The removed setattr line is legacy cruft, and wasn't doing anything.
2025-04-24 18:53:01 +10:00
Arthur Milchior
efaaae8ce4
Cloze button get disabled outside of cloze field (#3879)
* NF: replace `disabled` by `enabled`

This allows to remove the negations and, in my opinion, make the code
easier to understand and edit.

* Cloze button get disabled outside of cloze field

More specifically, if the user focus in a field that is not a cloze
field, the button are still there but appear as disabled. The shortcut
instead of adding the cloze context shows an alert explaining why this
can't be done.

While this message is already displayed when the user tries to add a
note with cloze in non-cloze field, I suspect it will save time to
stop the user as soon as possible from making mistake. This should
make very clear what is authorized and what is not.

It'll also be a reminder of whether the current field is a cloze or
not.

In order to do this, I added a back-end method (that I expect we may
reuse in ankidroid) to get the index of the fields used in cloze. This
set is sent to the note editor, which propagates it where needed.

In mathjax, the cloze symbol is removed when the selected field is not
a cloze field.
2025-04-24 18:37:41 +10:00
Damien Elmes
b23a6af63e Restore ability to check pages externally on other devices
Broken by the recent security changes
2025-04-24 18:33:09 +10:00
Aristotelis
79b19a17a3
Add add-on scripts to editor CSP (#3942) 2025-04-24 15:28:25 +10:00
Damien Elmes
1e74e8e86e
Fix add-on buttons not working in the editor (#3941)
* Fix add-on buttons not working in the editor

* Ensure old listeners are cleaned up

Thanks to iamllama: https://github.com/ankitects/anki/pull/3941#discussion_r2057066283
2025-04-24 15:26:46 +10:00
Damien Elmes
ddb8573e8d
Use CSP to block inline JS content in editor (#3939)
* Revert "Sanitize field content in editor"

This reverts commit 1c156905f8.

* Use CSP to block inline JS content in editor

This blocks inline scripts, scripts in the media folder, and
handlers like onclick in the editor. This is nicer than the previous
solution - it doesn't make any permanent changes, and leaves other
content like SVGs alone. Thanks to Nil Admirari for the suggestion.
2025-04-23 16:21:48 +10:00
Aristotelis
5b0f371791
Fix AnkiWebPage not being initialized for default web view kinds (e.g. in add-ons) (#3933)
* add AnkiWebView subclasses for stats, empty cards and find dupes ui

* update ui files to use subclassed webviews instead

* remove superfluous calls to AnkiWebView.set_kind

* Avoid set_kind() race condition in legacy stats webview

Replacing the web view is a hacky workaround, but likely a reasonable compromise for a legacy view that we do not want to maintain a separate Qt form for.

* Slightly refactor AnkiWebView subclass creation and tweak inline comment

+ Extend create_ankiwebview_subclass() with the ability to set any
  init time AnkiWebView argument
+ Introduce some nice-to-haves in terms of static type checking support
  and IDE autocompletion
+ Mark helper function as private to discourage add-on use

* Drop `AnkiWebView.set_kind` completely

There no longer is an Anki-internal use case for changing the web view kind after initializing a web view, and add-ons almost certainly do not have any use for it either.

Given that setting the kind after web view construction can lead  to known race conditions with `domDone` signals, we should remove this method to discourage uses like this in both Anki code and add-on consumers.

There currenty only seems to be one add-on calling `set_kind()`, so this seem like a justifiable API change.

---------

Co-authored-by: llama <100429699+iamllama@users.noreply.github.com>
2025-04-22 21:22:40 +10:00
llama
a74fd74631
Fix flashing when opening the stats, empty cards or find dupes dialogs (#3928)
* add AnkiWebView subclasses for stats, empty cards and find dupes ui

* update ui files to use subclassed webviews instead

* remove superfluous calls to AnkiWebView.set_kind

* revert impl

* set page background colour after setPage in AnkiWebView.set_kind
2025-04-17 15:18:55 +03:00
Damien Elmes
1a68c9f5d5
Harden access to internal API (#3925)
* Sanitize field content in editor

The editor already strips script tags from fields, but was allowing
through Javascript in things like onclick handlers. We block this now,
as the editor context has access to internal APIs that we don't want to
expose to untrusted third-party code.

* Require an auth token for API access

We were previously inspecting the referrer, but that is spoofable,
and doesn't guard against other processes on the machine.

To accomplish this, we use a request interceptor to automatically
add an auth token to webviews with the right context. Some related
changes were required:

- We avoid storing _page, which was leading to leaks & warning on exit
- At webview creation (or set_kind() invocation), we assign either
an authenticated or unauthenticated web profile.
- Some of our screens initialize the AnkiWebView when calling, e.g.,
aqt.forms.stats.Ui_Dialog(). They then immediately call .set_kind().
This reveals a race condition in our DOM handling code: the webview
initialization creates an empty page with the injected script, which
causes a domDone signal to be sent back. This signal arrives after
we've created another page with .set_kind(), causing our code to think
the DOM is ready when it's not. Then when we try to inject the dynamic
styling, we get an error, as the DOM is not ready yet. In the absence
of better solutions, I've added a hack to set_kind() to deal with this
for now.

* Provide AnkiWebPage init defaults for existing add-on callers

* Inject bridge script when profile set-up skipped

Some add-ons fully override AnkiWebPage.__init__ and thus depend on _setupBridge injecting the JS bridge script.

With this change we account for these cases, while giving add-ons the opportunity to look for solutions that do not require overriding AnkiWebPage.__init__ completely.

* Add some missed pages/endpoints (thanks to iamllama)

* Avoid sending API key for remote resources

Thanks to Abdo for the report

---------

Co-authored-by: Aristotelis P <201596065+aps-amboss@users.noreply.github.com>
2025-04-17 11:15:10 +10:00
llama
1d2d6e51b9
Fix error when middle clicking in editor on systems w/o global mouse selection (#3923)
* fix potential error when middle clicking in editor

* update about.py
2025-04-15 20:26:18 +10:00
Luc Mcgrady
781a23c6c4
Feat/Ignored before card count (#3910)
* GetIgnoredBeforeCount

* get_card_count_with_ignore_before

* Included / total

* Respect search

* Get frontend hooked up

* Fix: Malformed sql and search

* Variable names

* Added: Alert colours

* i18n

* ./check

* Remove console.log

* Fix: Tooltip showing for default value

* Update ftl/core/deck-config.ftl

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>

* Fix: Multiple backend calls

* Message: (Approximately)

* Fix: Bouncing info message

* Added: Change delay

* Added: ignore_before_updated

* ./check

* Fix typing, camelCase and improve wording

* Temporarily enable the check on startup

---------

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>
2025-04-15 20:21:54 +10:00
(x⋅ln(7))⁻¹
369dec9319
Add an option to disable middle click to paste on Linux (#3904)
* Add checkbox

* Working in editor

* Toolbar webview

* Other webviews

* Even more webviews

* Move to profile settings

* Add to contributors [skip ci]

* Fix checks

* Fix checks

* Better?

* Remove unneded

* Remove checkbox and a few other things

* How the hell did that happen

* Undo FTL changes (dae)

* Remove superfluous config entry (dae)

* Add comment about profile keys (dae)
2025-04-15 19:51:00 +10:00
babofitos
066f5fd281
Fix: correct typo and adjust indentation in docstring (#3920)
* fix: correct typo and adjust indentation in docstring

Fixed a small typo in the webview_did_inject_style_into_page docstring and adjusted indentation for consistency.

* Update CONTRIBUTORS
2025-04-13 17:00:19 +10:00
llama
8b2a64852b
fix drag/drop breaking when editor is zoomed (#3916) 2025-04-13 14:44:28 +10:00
llama
4f6dcb0b5b
Fix autoplay not being stopped on editor close if it interrupted another (#3915)
* fix autoplay not stopped on editor close if it interrupted another

* Update qt/aqt/sound.py
2025-04-13 14:43:25 +10:00
Yuki
acdf486b29
Refactor: Make Load Balancer Optional Throughout Codebase (#3860)
* Refactoring: load balancer

* Update about.py

* Refactoring: load balancer

* Update about.py

* Clean the code

* Remove config check from get_scheduling_states

* Backend method for the load balancer

* Refactor backend method for the load balancer
2025-03-26 23:19:28 +10:00
Kris Cherven
ab8692a91e
Show "and others" at the end of the contributor list in the About dialog (#3863)
* Show "and others" at the end of the contributor list in the about dialog

* Make about addendum translatable

* Fix CONTRIBUTORS

* Fix CONTRIBUTORS

* Update ftl/qt/about.ftl (dae)
2025-03-19 18:16:51 +07:00
Kris Cherven
938c55ca01
Fix broken window decorations on unpackaged GNOME instances (#3858)
* Fix broken window decorations on unpackaged GNOME instances

* Fix CONTRIBUTORS detection

* Fix CONTRIBUTORS
2025-03-19 17:58:42 +07:00
Evgeny Kulikov
ffcc7612ab
Add-ons Dialog: disable View Config/Page/Files buttons when clicking them would not lead to useful result (#3869)
* Remove unused import

* Nit-pick on code comment

* Enable View Page/Config buttons only when 1 add-on selected

* Enable Cmd+W shortcut (on Mac only) to close Add-ons dialog
2025-03-19 04:27:34 +03:00
Damien Elmes
83d0f5dae9 Add ES translator as requested 2025-03-17 22:11:29 +07:00
Jarrett Ye
0e31efac08
Feat/grade now (#3840)
* Feat/grade now

* pass ci

* fix from_queue

* Refactor card answering to support from_queue flag

- Add `from_queue` field to `CardAnswer` struct and proto message
- Modify `answer_card_inner` to handle queue updates based on `from_queue`
- Remove `grade_card` method and consolidate card answering logic
- Update related test cases to set `from_queue` flag

* fix current_changes() called when no op set

* Optimize queue updates for batch card processing

- Refactor `grade_now` to collect processed card IDs first
- Add new `update_queues_for_processed_cards` method for efficient batch queue updates
- Improve queue management by removing entries and updating counts in a single pass
- Remove individual queue update method in favor of batch processing

* pass ci

* keep the same style

* remove ineffective code

* remove unused imports
2025-03-15 17:30:40 +07:00
chel-ou
122980e06b
Add hooks for comparing answers (#3855)
* Add hooks associated to compare answer feature

* Update CONTRIBUTORS

* Add type pattern to compare answer related hooks
2025-03-15 12:12:01 +07:00
Val Enfys
d0ed54a768
Update my name in Anki's credits (#3852)
* Update my name in about.py

* Add name to CONTRIBUTORS
2025-03-14 17:00:48 +07:00
Evgeny Kulikov
339bf436d1
Prevent accidental dragging of audio playback buttons and hint links (#3844)
* Add myself to CONTRIBUTORS

* Set draggable="false" attribute on .replay-button

Because currently if a user drags slightly (even unintentionally) upon clicking a play button, play does not happen

* Prevent dragging hint links

Because if a user moves cursor a little after `mousedown`, action (expanding the hint) does not occur. Which might cause issues from accessibility standpoint
2025-03-14 16:47:03 +07:00
Luc Mcgrady
cad6e0b0bf
Added: Max interval too low warning. (#3847)
* Added: Max interval too low warning.

* Lower threshold to 180

* Add self to about.py
2025-03-10 16:14:35 +07:00
Brayan Oliveira
94e90dbf85
Add title for some dialogs and avoid hardcoding the text of the discard changes dialog (#3846)
* feat: add title to rename dialog

* fix: localize hardcoded message

* feat: add title to create deck dialog

* refactor: formatting fixes

* add name to about screen

adding my name to contributors for the third time
2025-03-10 15:53:43 +07:00