Commit graph

11858 commits

Author SHA1 Message Date
Damien Elmes
dd0abfc200 Don't check collection size on sync to third-party server
Closes #3936
2025-04-23 17:03:04 +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
Damien Elmes
7969b4061f Bump vite/svelte for latest security fixes 2025-04-15 20:53:26 +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
GithubAnon0000
e7fbf159a6
add min-height to fields (#3922)
* add min-height to fields

* 30px → 1.5em

This works with different font sizes too. Now there are no size jumps between empty field / field with string / field with empty html.
2025-04-15 20:24:43 +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
9d167feb8f
Remove use of createClassComponent in mathjax-element.ts (#3919)
* replace use of deprecated createClassComponent with mount

* bump esbuild-svelte from 0.8.1 to 0.9.2

* mathjax-element.ts -> mathjax-element.svelte.ts

* move caret after tick
2025-04-13 16:21:22 +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
RREEMMII
1fa99c97e4
Add a warning when there is a cloze in "back extra" and "text" is empty (#3912)
* Add a warning when there is a cloze in "back extra" and "text" is empty

Fix #3909

* Disallow non-blank first field card

* Fix Rust ninja check
2025-04-13 14:40:35 +10:00
user1823
e546c6d11f
Improve natural unit conversion for a time b/w 360 to 365 days (#3901)
* Improve natural unit conversion for a time b/w 360 to 365 days

Previously, 363 days would be converted to 12.1 months, which is quite confusing because
- a user would think that if the value is more than 12 months, why it isn't displayed in years
- the value is actually less than a year, which is counterintuitive as 12.1 m suggests a value more than a year.

* precise

* Update time.ts to match timespan.rs

* Add another test

* Use average duration of a month instead

* Update time.ts

* Update test_schedv3.py

* Update time.test.ts
2025-04-13 14:26:34 +10:00
GithubAnon0000
332830e5d7
Cleanup old TODO (#3903)
This Todo is no longer needed, since #1503 has been closed.
2025-04-11 20:38:20 +10:00
llama
d9c71a54cf
Allow drag-dropping into plaintext editor (#3902)
* expose field index as data attr on container

* allow drag/dropping into fields' plaintext editors
2025-04-11 19:34:47 +10:00
user1823
0f9216c127
Replace some means in Stats with medians (#3900)
* Display median interval in Stats instead of mean

Median is better suited than mean for reporting skewed data.

* Display median ease in Stats instead of mean

* Update difficulty.ts

* Update ease.ts

* Update statistics.ftl

* Format eases.rs

* Remove unused import

* Change Median back to Average in UI

* Revert "Change Median back to Average in UI"

This reverts commit e0c1e3f8e4.

* Preserve the old translations for now (dae)
2025-04-11 19:29:23 +10:00
ikkz
480e8f5409
style: use consistent input styles (#3894) 2025-04-10 15:51:52 +10:00
Lukas Sommer
56613be933
Comment for translators for statistics-total (#3880)
* Update statistics.ftl

* Update statistics.ftl

* Improve wording
2025-04-10 15:41:29 +10:00
Arthur Milchior
ab75e3d49b
Introduce language_bridge.md (#3572)
This commit explains how to calls a method implemented in a language
from a different language.

This explains how to declare the RPCs, how to call them and how to
implement them. This is based on examples of code at main at the time
of writting. I used permalink to ensure that the links remains
relevant even if the specific examples change later.

The last section is about the special case of calling TypeScript from
Python, which does not use RPC but is still relevant in a bridge
document.

This commit also add a paragraph explaining what protobuf is in the
protobuf documentation, so that new contributors who don't know what
protobuf is can understand why we use it.
2025-04-10 15:30:18 +10:00
Damien Elmes
ffbc9a77b7 Update tokio, crossbeam-channel and cargo-deny 2025-04-10 15:18:55 +10:00
dependabot[bot]
fab6ee96fe
Bump vite from 5.4.14 to 5.4.17 (#3914)
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 5.4.14 to 5.4.17.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/v5.4.17/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v5.4.17/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-version: 5.4.17
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-10 15:11:32 +10:00
Damien Elmes
9e3239baf4 Update translations 2025-04-10 15:03:14 +10:00
Damien Elmes
475fdf04a4 Latest Rust CVEs 2025-04-10 15:03:02 +10:00
llama
ccab18b7ba
Modify card rendering output to specify if rendered card is empty (#3890)
* modify render_card to return whether card was empty

* plumbing

* add flag to proto message

* plumbing: pass flag along to PartiallyRenderedCard

* add tests

* Use a custom return type for clarity (dae)
2025-03-31 17:51:28 +07:00
Lukas Sommer
1798620d64
Update statistics.ftl (#3887) 2025-03-31 17:39:51 +07:00
llama
aa5684638b
Improve performance of card rendering parser (#3886)
* refactor parser

* update test

* add tests

* refactor CardNodes

* Increase nested cloze limit to underlying protobuf limit (dae)
2025-03-31 17:38:46 +07:00
Kris Cherven
52781aaab8
Fix superfluous message when a deck is dragged to its parent (#3859)
* Move the solution to the Rust layer

* CONTRIBUTORS fix (1)

* CONTRIBUTORS fix (2)

* Fix CI issues

* Simplify reparenting solution

* Fix reparenting message with tags

* Revert "Fix reparenting message with tags"

This reverts commit 199958c1c5.

* tags: Return None in reparented_name when the name is unchanged
2025-03-31 16:47:56 +07:00
user1823
86ed715458
Hide AverageForDaysStudied when studiedPercent = 100 (#3888)
Showing both is redundant when studiedPercent is 100
2025-03-29 05:15:41 +03:00
ikkz
567cd9b9e3
style: add shadow to graph tooltip (#3891) 2025-03-29 05:08:59 +03: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
GithubAnon0000
e7e6a3834b
Center align rows in FSRS simulator (#3882) 2025-03-26 17:21:21 +10:00
Abdo
f4a0598f2f
Return a copy of note type in ModelManager.get() (#3865)
* Return a copy of note type in ModelManager.get()

* Update tests

* Revert "Return a copy of note type in ModelManager.get()"

This reverts commit 04ef186336.

* Add note to .get()
2025-03-26 15:11:34 +10:00
llama
45bb56808a
Fix deck day limits incorrectly being carried over when importing (#3878)
* re-export DayLimit

* add and use DeckContext::maybe_correct_day_limits

* update existing test

* add test

* small tweaks

* refactor

* refactor test
2025-03-25 00:45:09 +07:00
llama
886c5795d4
Fix panic when clearing today limits on the day collection was made (#3877)
* fix panic on clearing today limits on the day collection was made

* avoid possible overflow

* clear future today limits
2025-03-25 00:24:11 +07:00
GithubAnon0000
a766f511dd
Move TR table upwards (#3873)
* Move TR table upwards

This moves the TR table upwards, before the buttons graph.

Also see: https://forums.ankiweb.net/t/let-s-remove-the-answer-buttons-chart-from-stats/56170/26?u=anon_0000

* Moved hour graph below TR graph
2025-03-25 00:13:51 +07:00
Jarrett Ye
a4e0a0824b
Fix/out of index (#3872) 2025-03-25 00:04:25 +07:00
Jarrett Ye
d52889f45c
Feat/simplified relearning steps logic with updated FSRS training API (#3867)
* Feat/simplified relearning steps logic with updated FSRS training API

* Update params.rs

* use ComputeParametersInput

* update fsrs-rs dependency

* update cargo/format/rust-toolchain
2025-03-20 14:04:38 +07:00
Jarrett Ye
5d7f6b25c0
Improve performance of stats revlog entries with memory state (#3866)
* improve performace of stats_revlog_entries_with_memory_state

* format

* move Vec<RevlogEntry> into FsrsItemForMemoryState
2025-03-20 14:02:40 +07:00
llama
d8c83ac075
Loosen csv metadata parsing (#3862)
* add qsv-sniffer crate

* use qsv-sniffer before falling back to old delimiter heuristic

* update test metadata macro

* revert impl

* trim potential suffixed delimiters from non-freeform meta lines

* add test
2025-03-19 18:56:17 +07: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
Arthur Milchior
6ef24739fc
NF: sligthly optimize cards.py (#3870)
As AnkiDroid wants to be similar to Anki, instead of making AnkiDroid
slightly less efficient, I prefer to slightly improve Anki.

AnkiDroid related PR:
https://github.com/ankidroid/Anki-Android/pull/18112.
2025-03-19 04:14:13 +03:00
Damien Elmes
83d0f5dae9 Add ES translator as requested 2025-03-17 22:11:29 +07:00
Damien Elmes
14dc979e44 Fix panic when a preset is missing 2025-03-15 19:40:48 +07:00
Expertium
d53f01064c
Fine-tune load balancer (#3864) 2025-03-15 18:40:17 +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