Commit Graph

1848 Commits

Author SHA1 Message Date
Damien Elmes
6074865763 Calculate parameters automatically
Logic derived from d8e2f6a0ff

Closes #2661
2023-09-18 16:43:36 +10:00
Sam Waechter
e7bf248a62
Fix unable to save field dialog if certain fields are deleted (#2663)
* Fix unable to save field dialog if certain fields are deleted

Implemented solution suggested in issue #2556

* Fix unable to save field dialog if certain fields are deleted

fixed code formating

* Fix unable to save field dialog if certain fields are deleted

Made new functions to check referencelessness.  Added unit test.
2023-09-18 14:33:56 +10:00
Damien Elmes
a7b4c90146 Use field tags instead of hard-coding occlusion fields
+ Don't protect the comments field

It's not required by our current code. We can remove the protection
from Header and Back Extra in the future too, once we no longer depend
on them.

Closes #2621
2023-09-18 10:10:11 +10:00
Damien Elmes
906a937faf Add tags in DB check 2023-09-17 15:00:28 +10:00
Damien Elmes
f0be697b55 Protect image occlusion fields and cloze field 2023-09-17 14:22:25 +10:00
Damien Elmes
1e37c806e5 Add support for tagging + protecting fields 2023-09-17 14:03:42 +10:00
Damien Elmes
59759b468f Start on a 'get params' button 2023-09-17 12:58:13 +10:00
Damien Elmes
736054a2e4 Fix preset searches, and expose in text search 2023-09-17 12:51:22 +10:00
Damien Elmes
25d5e56397 Clear memory state when user disables FSRS 2023-09-17 11:50:38 +10:00
Damien Elmes
75de1f9709 Record FSRS difficulty in the review log
Will allow user to see a record of difficulty changes, and allows us
to identify reviews that have been done with FSRS vs SM-2, since the
valid range is different.
2023-09-17 11:50:38 +10:00
Damien Elmes
0301ae1d8a fsrs_memory_state -> memory_state 2023-09-17 11:50:38 +10:00
Damien Elmes
5004cd332b
Integrate FSRS into Anki (#2654)
* Pack FSRS data into card.data

* Update FSRS card data when preset or weights change

+ Show FSRS stats in card stats

* Show a warning when there's a limited review history

* Add some translations; tweak UI

* Fix default requested retention

* Add browser columns, fix calculation of R

* Property searches

eg prop:d>0.1

* Integrate FSRS into reviewer

* Warn about long learning steps

* Hide minimum interval when FSRS is on

* Don't apply interval multiplier to FSRS intervals

* Expose memory state to Python

* Don't set memory state on new cards

* Port Jarret's new tests; add some helpers to make tests more compact

https://github.com/open-spaced-repetition/fsrs-rs/pull/64

* Fix learning cards not being given memory state

* Require update to v3 scheduler

* Don't exclude single learning step when calculating memory state

* Use relearning step when learning steps unavailable

* Update docstring

* fix single_card_revlog_to_items (#2656)

* not need check the review_kind for unique_dates

* add email address to CONTRIBUTORS

* fix last first learn & keep early review

* cargo fmt

* cargo clippy --fix

* Add Jarrett to about screen

* Fix fsrs_memory_state being initialized to default in get_card()

* Set initial memory state on graduate

* Update to latest FSRS

* Fix experiment.log being empty

* Fix broken colpkg imports

Introduced by "Update FSRS card data when preset or weights change"

* Update memory state during (re)learning; use FSRS for graduating intervals

* Reset memory state when cards are manually rescheduled as new

* Add difficulty graph; hide eases when FSRS enabled

* Add retrievability graph

* Derive memory_state from revlog when it's missing and shouldn't be

---------

Co-authored-by: Jarrett Ye <jarrett.ye@outlook.com>
2023-09-16 16:09:26 +10:00
Abdo
6f0bf58d49
Add a backend method to add notes in bulk (#2659)
* Add a backend method to add notes in bulk

* i -> idx

* Remove duplicate assignment

* Allow add_notes to work with multiple deck IDs

* Rename note_deck_id to requests
2023-09-16 13:51:32 +10:00
Damien Elmes
30ae9f7c54 Fix merge_undoable_ops() not updating counter 2023-09-15 16:53:00 +10:00
Abdo
e2603a73f5
Fix unescaped HTML in type-in-the-answer (#2658) 2023-09-14 11:34:22 +10:00
RumovZ
850043b49b
Tooltips for CSV import and import page refactoring (#2655)
* Make enum selector generic

* Refactor ImportCsvPage to support tooltips

* Improve csv import defaults

* Unify import pages

* Improve import page styling

* Fix life cycle issue with import properties

* Remove size constraints to fix scrollbar styling

* Add help strings and urls to csv import page

* Show ErrorPage on ImportPage error

* Fix escaping of import path

* Unify ImportPage and ImportLogPage

* Apply suggestions from code review (dae)

* Fix import progress

* Fix preview overflowing container

* Don't include <br> in FileIoErrors (dae)

e.g. 500: Failed to read '/home/dae/foo2.csv':<br>stream did not contain valid UTF-8

I thought about using {@html ...} here, but that's a potential security issue,
as the filename is not something we control.
2023-09-14 09:06:15 +10:00
Damien Elmes
bfef908c6c
Refactor media sync handling (#2647)
* Refactor media sync handling

- The media USN is now returned in sync/meta, which avoids an extra
round-trip.
- Media syncing is now automatically started by the syncing code at
the end of a normal or full sync, which avoids it competing for bandwidth
and resources, and avoids duplicate invalid login messages when the auth
token is invalid.
- Added a new media_sync_progress() method to both check if media is
syncing, and get access to the latest progress.
- Updated the sync log screen to only show the latest line, like AnkiMobile.
- Show media sync errors in a pop-up, so they don't get missed. Use a non-modal
pop-up to avoid potential conflicts with other modals.

* Remove print statement
2023-09-10 13:22:20 +10:00
RumovZ
14de8451dc
Merging Notetypes on Import (#2612)
* Remember original id when importing notetype

* Reuse notetypes with matching original id

* Add field and template ids

* Enable merging imported notetypes

* Fix test

Note should be updated if the incoming note's notetype is
remapped to the existing note's notetype.
On the other hand, it should be skipped if its notetype id is mapped
to some new notetype.

* Change field and template ids to i32

* Add merge notetypes flag to proto message

* Add dialog for apkg import

* Move HelpModal into components

* Generalize import dialog

* Move SettingTitle into components

* Add help modal to ImportAnkiPackagePage

* Move SwitchRow into components

* Fix backend method import

* Make testable in browser

* Fix broken modal

* Wrap in container and fix margins

* Update commented Anki version of new proto fields

* Check ids when comparing notetype schemas

* Add tooltip for merging notetypes.

* Allow updating notes regardless of mtime

* Gitignore yarn-error.log

* Allow updating notetypes regardless of mtime

* Fix apkg help carousel

* Use i64s for template and field ids

* Add option to omit importing scheduling info

* Restore last settings in apkg import dialog

* Display error when getting metadata in webview

* Update manual links for apkg importing

* Apply suggestions from code review

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

* Omit schduling -> Import all cards as new cards

* Tweak importing-update-notes-help

* UpdateCondition → ImportAnkiPackageUpdateCondition

* Load keyboard.ftl

* Skip updating dupes in 'update alwyas' case

* Explain more when merging notetypes is required

* "omit scheduling" → "with scheduling"

* Skip updating notetype dupes if 'update always'

* Merge duplicated notetypes from previous imports

* Fix rebase aftermath

* Fix panic when merging

* Clarify 'update notetypes' help

* Mention 'merge notetypes' in the log

* Add a test which covers the previously panicking path

* Use nested ftl messages to ensure consistency

* Make order of merged fields deterministic

* Rewrite test to trigger panic

* Update version comment on new fields
2023-09-09 09:00:55 +10:00
Damien Elmes
9595101065 Wrap backend in an outer Arc
Necessary to allow backend commands that run in the background instead
of blocking.
2023-09-07 14:10:50 +10:00
Damien Elmes
ffd392de21
Change Anki's version scheme; bump to 23.09 (#2640)
* Accept iterables as inputs to backend methods

* Shift add-on check to backend; use new endpoint

The new endpoint will return info on a suitable branch if found,
instead of returning all branches. This simplifies the frontend code,
and means that you can now drop support for certain versions without
it also remotely disabling the add-on for people who are running one of
the excluded versions, like in

https://forums.ankiweb.net/t/prevent-add-ons-from-being-disabled-remote-stealthily-surreptitiously/33427

* Bump version to 23.09

This changes Anki's version numbering system to year.month.patch, as
previously mentioned on https://forums.ankiweb.net/t/use-a-different-versioning-system-semver-perhaps/20046/5

This is shaping up to be a big release, with the introduction of FSRS and
image occlusion, and it seems like a good time to be finally updating the
version scheme as well. AnkiWeb has been updated to understand the new
format, and add-on authors will now specify version compatibility using
the full version number, as can be seen here:

https://ankiweb.net/shared/info/3918629684

* Shift update check to backend, and tidy up update.py

* Use the shared client for sync connections too
2023-09-07 12:37:15 +10:00
Damien Elmes
6d34d19808 Drop legacy schema option 2023-09-06 15:49:14 +10:00
Damien Elmes
0c6e3eaa93
Integrate the FSRS optimizer (#2633)
* Support searching for deck configs by name

* Integrate FSRS optimizer into Anki

* Hack in a rough implementation of evaluate_weights()

* Interrupt calculation if user closes dialog

* Fix interrupted error check

* log_loss/rmse

* Update to latest fsrs commit; add progress info to weight evaluation

* Fix progress not appearing when pretrain takes a while

* Update to latest commit
2023-09-05 18:45:05 +10:00
Damien Elmes
fe8cf5ae7d Read csv text in eagerly
This allows us to display a more useful "not utf-8" message, instead of a
generic "invalid csv" message when the metadata can't be fetched.
2023-09-05 18:33:23 +10:00
Damien Elmes
ecaba5e655 Fix stack overflow in request::Error mapping 2023-09-05 15:27:17 +10:00
Abdo
d3d67c2083
Support searching for custom data strings (#2634)
* Add extract_custom_data

* Add tests for has-cd

* Add `prop:cds` query
2023-09-04 11:17:13 +10:00
Damien Elmes
ff53625408 Update nightly formatter
Rustfmt is now capable of formatting let Some(..) else {} blocks
2023-09-02 16:13:50 +10:00
Abdo
064b973a2a
Allow searching for missing custom data properties (#2626)
* Allow searching for missing custom data properties

* Add has-cd query
2023-09-01 14:13:31 +10:00
Nil Admirari
9d3f01043b
Support AVIF (#2630) 2023-08-31 08:44:10 +10:00
Damien Elmes
e86cebd45e Fix importing link 2023-08-31 07:52:21 +10:00
Damien Elmes
408b48834b Fix clippy issues in Rust 1.72 2023-08-25 07:56:38 +10:00
Damien Elmes
cdcd9bcce0 New collections now start with the v3 scheduler 2023-08-19 13:31:01 +10:00
Damien Elmes
d2022d1a6d Avoid allocating in extract_latex() if possible; make public 2023-08-19 08:05:39 +10:00
Damien Elmes
b73cb15888 Take another approach to dealing with conflicting flattened keys
The approach in #2542 unfortunately introduced a regression, as whilst
it ensured that duplicate keys are removed when downgrading, it no longer
prevented the duplicates from being removed when converting to a legacy
Schema11 object. This resulted in things like backend.get_notetype_legacy()
returning duplicate keys, and could break syncing:

https://forums.ankiweb.net/t/windows-desktop-sync-error/33128

As syncing and schema11 object usage is quite common compared to downgrading,
the extra Value deserialization seemed a bit expensive, so I've switched
back to explicitly removing the problem keys. To ensure we don't forget to
add new keys in the future, I've added some new tests that should alert us
whenever a newly-added key is missing from the reserved list.
2023-08-15 11:25:53 +10:00
Damien Elmes
c112236dd9 Support include_filtered=false, skip_default=true case 2023-08-08 15:34:43 +10:00
Damien Elmes
934f582804 Support importing AnkiDroid's legacy backups
They were missing the media map, and were not importable by the desktop.
2023-08-03 19:33:16 +10:00
Abdo
98715e593a
Improve presentation of importing results (#2568)
* Implement import log screen in Svelte

* Show filename in import log screen title

* Remove unused NoteRow property

* Show number of imported notes

* Use a single nid expression

* Use 'count' as variable name for consistency

* Import from @tslib/backend instead

* Fix summary_template typing

* Fix clippy warning

* Apply suggestions from code review

* Fix imports

* Contents -> Fields

* Increase max length of browser search bar

https://github.com/ankitects/anki/pull/2568/files#r1255227035

* Fix race condition in Bootstrap tooltip destruction

https://github.com/twbs/bootstrap/issues/37474

* summary_template -> summaryTemplate

* Make show link a button

* Run import ops on Svelte side

* Fix geometry not being restored in CSV Import page

* Make VirtualTable fill available height

* Keep CSV dialog modal

* Reword importing-existing-notes-skipped

* Avoid mentioning matching based on first field

* Change tick and cross icons

* List skipped notes last

* Pure CSS spinner

* Move set_wants_abort() call to relevant dialogs

* Show number of imported cards

* Remove bold from first sentence and indent summaries

* Update UI after import operations

* Add close button to import log page

Also make virtual table react to resize event.

* Fix typing

* Make CSV dialog non-modal again

Otherwise user can't interact with browser window.

* Update window modality after import

* Commit DB and update undo actions after import op

* Split frontend proto into separate file, so backend can ignore it

Currently the automatically-generated frontend RPC methods get placed in
'backend.js' with all the backend methods; we could optionally split them
into a separate 'frontend.js' file in the future.

* Migrate import_done from a bridgecmd to a HTTP request

* Update plural form of importing-notes-added

* Move import response handling to mediasrv

* Move task callback to script section

* Avoid unnecessary :global()

* .log cannot be missing if result exists

* Move import log search handling to mediasrv

* Type common params of ImportLogDialog

* Use else if

* Remove console.log()

* Add way to test apkg imports in new log screen

* Remove unused import

* Get actual card count for CSV imports

* Use import type

* Fix typing error

* Ignore import log when checking for changes in Python layer

* Apply suggestions from code review

* Remove imported card count for now

* Avoid non-null assertion in assignment

* Change showInBrowser to take an array of notes

* Use dataclasses for import log args

* Simplify ResultWithChanges in TS

* Only abort import when window is modal

* Fix ResultWithChanges typing

* Fix Rust warnings

* Only log one duplicate per incoming note

* Update wording about note updates

* Remove caveat about found_notes

* Reduce font size

* Remove redundant map

* Give credit to loading.io

* Remove unused line

---------

Co-authored-by: RumovZ <gp5glkw78@relay.firefox.com>
2023-08-02 20:29:44 +10:00
Damien Elmes
a35c1a058d Extract inline images as part of media check
We also need to get to the bottom of what's causing this:
https://forums.ankiweb.net/t/anki-browse-extremely-laggy/32533
2023-07-31 12:23:16 +10:00
Damien Elmes
a623dff0da Tolerate {{FrontSide}} on the front side
https://forums.ankiweb.net/t/display-the-template-for-the-front-has-a-problem/32035
2023-07-13 21:39:16 +10:00
Damien Elmes
9711044290 Improve performance of invalid ID fix in DB check
Fixes https://forums.ankiweb.net/t/check-database-is-stuck-on-checking-history/31891
2023-07-07 22:53:41 +10:00
Damien Elmes
fc0bff4166 Add updated script for transforming ftl text 2023-07-06 22:27:09 +10:00
Damien Elmes
516abf7cfa Stop including Qt translations when EXTRA_FTL_ROOT provided
This was causing index mismatches when switching between release and
non-release builds, presumably as the build script wasn't being rerun
in that case. We could add a rerun-if-changed=RELEASE, but easier to
strip this out, as it's rare to run the checks from an external repo.
2023-07-04 18:26:27 +10:00
Damien Elmes
e835922ded Fix i18n build script not responding to env var changes
Not much use declaring the cargo flag when we bake the env var into
the binary! Also treat an empty variable as missing.
2023-07-04 17:17:41 +10:00
Damien Elmes
13572a86b2 Move i18n helpers into ftl/, with a single main.rs
Clap gives us a nice help message and better arg parsing
2023-07-04 10:47:15 +10:00
Damien Elmes
78b4a391cc Fix some ftl args not being passed correctly in TypeScript 2023-07-04 00:47:59 +10:00
Damien Elmes
cb8007ce30 Move .py i18n method generation to Rust 2023-07-03 15:58:46 +10:00
Damien Elmes
4c76e3150b Move .ts i18n method generation to Rust
Based on a similar approach I used for AnkiDroid. The separate modules
file has been integrated into ftl.js.
2023-07-03 14:36:09 +10:00
Damien Elmes
f3b6deefe9 Combine all backend methods into a single js/d.ts file, like in Python
Easier to import from, and allows us to declare the output of the build
action without having to iterate over all the proto filenames. Have
confirmed it doesn't break esbuild's tree shaking.
2023-07-03 13:46:38 +10:00
Damien Elmes
ffadbf577b deckconfig.proto -> deck_config.proto
Makes it consistent with our other proto files, and matches the service
name.
2023-07-03 13:44:54 +10:00
Damien Elmes
8c712cd118 Support creating a standalone sync server 2023-07-02 18:22:44 +10:00
Damien Elmes
0f77de896d Fix building outside workspace
rslib/build.rs needs descriptors, even if env var not set
2023-07-02 18:22:44 +10:00
Damien Elmes
58c0f61d31 Fix progress not updating after one-way sync 2023-07-02 15:47:09 +10:00
Damien Elmes
5149cd13d4 Fix newly-added image occlusion notetype not syncing
https://forums.ankiweb.net/t/synchronisation-issue/31505/7
2023-07-01 22:10:29 +10:00
Damien Elmes
85c2769f80
Update Rust and Python deps (#2567)
* Update Python deps

* Update semver-compat Rust deps

* Update most crates to latest semver

* Update to latest axum-client-ip
2023-07-01 18:26:43 +10:00
Damien Elmes
f032242b65 Add must_use annotations to generated protobufs 2023-06-30 17:02:36 +10:00
Damien Elmes
5506f9bf2d Fix full template render choking on empty fields 2023-06-27 16:30:41 +10:00
Damien Elmes
dc56a2ca7d Rework RenderCardOutput::question/answer
Instead of flattening the output (which was missing FrontSide), alter
the behaviour of render() instead. The non-partial output is now exposed
via Protobuf, so the non-Python clients can take advantage of it.
2023-06-27 00:37:41 +10:00
Damien Elmes
21a03265a2 Rename sanity check fields avoid conflict with outer span 2023-06-26 15:04:58 +10:00
Damien Elmes
cf39455487 Handle invalid float mtimes in DB check
Likely an add-on or third-party tool created them, and they were breaking
DB queries for a user.

https://sqlite.org/stricttables.html could help us avoid this class of
issue in the future, though we'd need to check what client versions we'd
break with this change, and would need to change the 'sfld is an integer'
hack.
2023-06-26 13:40:54 +10:00
Damien Elmes
b2e7ab522b Remove some unused Rust dependencies 2023-06-24 19:30:29 +10:00
Damien Elmes
40e1520acb Drop workspace-hack in favor of workspace deps
Workspace deps were introduced in Rust 1.64. They don't cover all the
cases that Hakari did unfortunately, but they are simpler to maintain,
and they avoid a couple of issues that Hakari had:

- It sometimes made updating dependencies harder due to the locked versions,
so you had to disable Hakari, do the updates, and then re-generate (
e.g. 943dddf28f)
- The current Hakari config was breaking AnkiDroid's build, as it was
stopping a cross-compile from functioning correctly.
2023-06-23 17:41:31 +10:00
Damien Elmes
5023356dd2 Make Command::run() accept a single string for convenience
We can fall back on the standard constructor when we have dynamic input
2023-06-23 11:31:39 +10:00
Damien Elmes
a96d5a920b Add copy_file to anki_io, and ensure strings parent folder is created 2023-06-22 19:33:34 +10:00
Damien Elmes
1be9c36863 Fix ts interface being output to wrong filenames 2023-06-22 09:58:12 +10:00
Damien Elmes
0173ebf384 Fix lack of progress/error when importing a .colpkg
We should be accessing the backend progress state, instead of the
collection's state.
2023-06-22 09:46:09 +10:00
Damien Elmes
b37063e20a More service generation refactoring
- Dropped the protobuf extensions in favor of explicitly listing out
methods in both services if we want to implement both, as it's clearer.
- Move Service/Method wrappers into a separate crate that the various
clients can import, to easily get at the list of backend services and
their correct indices and comments.
2023-06-22 09:46:09 +10:00
Damien Elmes
c0f73d5f97 Drop the generated method map
I'd been thinking it might be useful for a future API service, but
I think that's better implemented with more codegen, so we have a
statically-typed interface.
2023-06-22 09:46:09 +10:00
Damien Elmes
7619891d4f Fix total note count not being logged in apkg import
https://forums.ankiweb.net/t/2-1-65-conflicting-import-message-when-importing-decks-with-v1-scheduler/31352/3
2023-06-22 09:46:09 +10:00
Damien Elmes
ba6325b47f Make some more fields/methods public
Continuation of https://github.com/ankitects/anki/issues/2494
2023-06-20 21:59:49 +10:00
Damien Elmes
c447999b4a Report actual error when DbError occurs 2023-06-20 21:58:27 +10:00
Damien Elmes
46722d792d Use a separate service definition for backend-only services
Realised this is clearer than tagging each method individually. The
enum has been retained for the case where we want to implement the backend
method separately from the collection one.
2023-06-19 22:06:50 +10:00
Damien Elmes
6f9b152028 Handle case where cards are imported into a collection with a newer start
https://forums.ankiweb.net/t/bug-report-when-the-original-due-is-less-than-0-the-due-will-be-weird-when-empty-the-filter-deck/31279

The 0 day case isn't fixed by this, but I don't think we can fix that
with the current schema.
2023-06-19 18:39:00 +10:00
Damien Elmes
553303fc12
Refactor service generation (#2552)
* Automatically elide empty inputs and outputs to backend methods

* Refactor service generation

Despite the fact that the majority of our Protobuf service methods require
an open collection, they were not accessible with just a Collection
object. To access the methods (e.g. because we haven't gotten around to
exposing the correct API in Collection yet), you had to wrap the collection
in a Backend object, and pay a mutex-acquisition cost for each call, even
if you have exclusive access to the object.

This commit migrates the majority of service methods to the Collection, so
they can now be used directly, and improves the ergonomics a bit at the
same time.

The approach taken:

- The service generation now happens in rslib instead of anki_proto, which
avoids the need for trait constraints and associated types.
- Service methods are assumed to be collection-based by default. Instead of
implementing the service on Backend, we now implement it on Collection, which
means our methods no longer need to use self.with_col(...).
- We automatically generate methods in Backend which use self.with_col() to
delegate to the Collection method.
- For methods that are only appropriate for the backend, we add a flag in
the .proto file. The codegen uses this flag to write the method into a
BackendFooService instead of FooService, which the backend implements.
- The flag can also allows us to define separate implementations for collection
and backend, so we can e.g. skip the collection mutex in the i18n service
while also providing the service on a collection.
2023-06-19 15:33:40 +10:00
Damien Elmes
dac532953e
Refactor progress handling (#2549)
Previously it was Backend's responsibility to store the last progress,
and when calling routines in Collection, one had to construct and pass
in a Fn, which wasn't the most ergonomic. This PR adds the last progress
state to the collection, so that the routines no longer need a separate
progress arg, and makes some other tweaks to improve ergonomics.

ThrottlingProgressHandler has been tweaked so that it now stores the
current state, so that callers don't need to store it separately. When
a long-running routine starts, it calls col.new_progress_handler(),
which automatically initializes the data to defaults, and updates the
shared UI state, so we no longer need to manually update the state at
the start of an operation.

The backend shares the Arc<Mutex<>> with the collection, so it can get
at the current state, and so we can update the state when importing a
backup.

Other tweaks:

- The current Incrementor was awkward to use in the media check, which
uses a single incrementing value across multiple method calls, so I've
added a simpler alternative for such cases. The old incrementor method
has been kept, but implemented directly on ThrottlingProgressHandler.
- The full sync code was passing the progress handler in a complicated
way that may once have been required, but no longer is.
- On the Qt side, timers are now stopped before deletion, or they keep
running for a few seconds.
- I left the ChangeTracker using a closure, as it's used for both importing
and syncing.
2023-06-19 13:48:32 +10:00
Damien Elmes
93da201f07 Include cmdline in error display; show cargo install progress 2023-06-17 14:55:55 +10:00
Damien Elmes
dd95f6f749 Check for stale licenses.json in minilints
+ Add an anki_process library with some helpers for command running.
2023-06-17 14:01:27 +10:00
Damien Elmes
84b3abab6c Fix rsbridge build when 1.61 snafu feature enabled 2023-06-17 12:44:25 +10:00
Damien Elmes
cf47e4c98d Drop num_integer crate 2023-06-17 00:09:41 +10:00
Damien Elmes
9b028e8f3d Bump Chrono now that Rumo's TZ parser has been merged
https://github.com/chronotope/chrono/pull/978

+ Update workspace hack/licenses
2023-06-16 11:43:12 +10:00
Damien Elmes
81ac5a91ad Include backend comments in Python and Rust codegen
This is of limited usefulness at the moment, as it doesn't help consumers
of the public API.

Also removed detached comments from the included comments.
2023-06-16 10:59:00 +10:00
Damien Elmes
02a1c891a6 Don't require DESCRIPTORS_BIN in an external workspace
Consumers may not require it
2023-06-15 22:32:16 +10:00
Damien Elmes
de8f62f831 Don't fail silently when an empty csv is imported 2023-06-15 17:47:46 +10:00
Damien Elmes
f4fca1f5fd Skip writing descriptors if unchanged 2023-06-15 17:17:56 +10:00
Damien Elmes
9701055eb5 Add support for using n2 instead of ninja
Provides better visibility into what the build is currently doing.
Motivated by slow node.js downloads making the build appear stuck.

You can test this out by running ./tools/install-n2 then building
normally. Please report any problems, and 'cargo uninstall n2' to get
back to the old behaviour. It works on Windows, but prints a new line
each second instead of redrawing the same area.

A couple of changes were required for compatibility:

- n2 doesn't resolve $variable names inside other variables, so the
resolution needs to be done by our build generator.
- Our inputs and outputs in build.ninja need to be listed in a deterministic
order to avoid unwanted rebuilds. I've made a few other tweaks so the
build file should now be fully-deterministic.
2023-06-15 17:17:56 +10:00
Damien Elmes
45f5709214
Migrate to protobuf-es (#2547)
* Fix .no-reduce-motion missing from graphs spinner, and not being honored

* Begin migration from protobuf.js -> protobuf-es

Motivation:

- Protobuf-es has a nicer API: messages are represented as classes, and
fields which should exist are not marked as nullable.
- As it uses modules, only the proto messages we actually use get included
in our bundle output. Protobuf.js put everything in a namespace, which
prevented tree-shaking, and made it awkward to access inner messages.
- ./run after touching a proto file drops from about 8s to 6s on my machine. The tradeoff
is slower decoding/encoding (#2043), but that was mainly a concern for the
graphs page, and was unblocked by
37151213cd

Approach/notes:

- We generate the new protobuf-es interface in addition to existing
protobuf.js interface, so we can migrate a module at a time, starting
with the graphs module.
- rslib:proto now generates RPC methods for TS in addition to the Python
interface. The input-arg-unrolling behaviour of the Python generation is
not required here, as we declare the input arg as a PlainMessage<T>, which
marks it as requiring all fields to be provided.
- i64 is represented as bigint in protobuf-es. We were using a patch to
protobuf.js to get it to output Javascript numbers instead of long.js
types, but now that our supported browser versions support bigint, it's
probably worth biting the bullet and migrating to bigint use. Our IDs
fit comfortably within MAX_SAFE_INTEGER, but that may not hold for future
fields we add.
- Oneofs are handled differently in protobuf-es, and are going to need
some refactoring.

Other notable changes:

- Added a --mkdir arg to our build runner, so we can create a dir easily
during the build on Windows.
- Simplified the preference handling code, by wrapping the preferences
in an outer store, instead of a separate store for each individual
preference. This means a change to one preference will trigger a redraw
of all components that depend on the preference store, but the redrawing
is cheap after moving the data processing to Rust, and it makes the code
easier to follow.
- Drop async(Reactive).ts in favour of more explicit handling with await
blocks/updating.
- Renamed add_inputs_to_group() -> add_dependency(), and fixed it not adding
dependencies to parent groups. Renamed add() -> add_action() for clarity.

* Remove a couple of unused proto imports

* Migrate card info

* Migrate congrats, image occlusion, and tag editor

+ Fix imports for multi-word proto files.

* Migrate change-notetype

* Migrate deck options

* Bump target to es2020; simplify ts lib list

Have used caniuse.com to confirm Chromium 77, iOS 14.5 and the Chrome
on Android support the full es2017-es2020 features.

* Migrate import-csv

* Migrate i18n and fix missing output types in .js

* Migrate custom scheduling, and remove protobuf.js

To mostly maintain our old API contract, we make use of protobuf-es's
ability to convert to JSON, which follows the same format as protobuf.js
did. It doesn't cover all case: users who were previously changing the
variant of a type will need to update their code, as assigning to a new
variant no longer automatically removes the old one, which will cause an
error when we try to convert back from JSON. But I suspect the large majority
of users are adjusting the current variant rather than creating a new one,
and this saves us having to write proxy wrappers, so it seems like a
reasonable compromise.

One other change I made at the same time was to rename value->kind for
the oneofs in our custom study protos, as 'value' was easily confused
with the 'case/value' output that protobuf-es has.

With protobuf.js codegen removed, touching a proto file and invoking
./run drops from about 8s to 6s.

This closes #2043.

* Allow tree-shaking on protobuf types

* Display backend error messages in our ts alert()

* Make sourcemap generation opt-in for ts-run

Considerably slows down build, and not used most of the time.
2023-06-14 22:47:37 +10:00
Damien Elmes
f6fdf64c5d Fix build failure in fresh checkout 2023-06-12 17:10:22 +10:00
Damien Elmes
850e564a99 Fix build failure on Windows 2023-06-12 16:06:40 +10:00
Damien Elmes
d380f3034c Split io.rs into separate crate, and use it in proto build
Will be handy to use it in our other scripts in the future too - thanks
Rumo!

Results of benchmarking ./run before and after these crate splits:

- Touching a proto file leads to a slight increase: about +90ms
- Touching an rslib file leads to a bigger decrease, as there's less to
recompile: about -700ms

And ./ninja test is even better: about +200ms and -3800ms.
2023-06-12 15:47:51 +10:00
Damien Elmes
a83c4a7da7 Move generated protobuf into anki_proto
Due to the orphan rule, this meant removing our usages of impl ProtoStruct,
or converting them to a trait when they were used commonly.

rslib now directly references anki_proto and anki_i18n, instead of
'pub use'-ing them, and we can put the generated files back in OUT_DIR.
2023-06-12 15:47:51 +10:00
RumovZ
651ba88393
Automate schema 11 other duplicates clearing (#2542)
* Skip linting target folder

Contains build files not passing the copyright header check.

* Implicitly clear duplicate keys when serializing

Fixes `originalStockKind` not being cleared from `other`, as it had
mistakenly been added to the field list for `NoteFieldSchema11`.
2023-06-12 11:14:14 +10:00
Damien Elmes
bac05039a7 Move protobuf generation into a separate crate; write .py interface in Rust
A couple of motivations for this:

- genbackend.py was somewhat messy, and difficult to change with the
lack of types. The mobile clients used it as a base for their generation,
so improving it will make life easier for them too, once they're ported.
- It will make it easier to write a .ts generator in the future
- We currently implement a bunch of helper methods on protobuf types
which don't allow us to compile the protobuf types until we compile
the Anki crate. If we change this in the future, we will be able to
do more of the compilation up-front.

We no longer need to record the services in the proto file, as we can
extract the service order from the compiled protos. Support for map types
has also been added.
2023-06-12 09:52:00 +10:00
Damien Elmes
7a9c6172ef When cards are intraday learning queue, don't use original due
https://forums.ankiweb.net/t/backlog-with-no-backlo/30832
2023-06-07 16:20:44 +10:00
Damien Elmes
f758b33346
Default to current deck in csv import if settings allow it (#2527)
* Default to current deck in csv import if settings allow it

Reuses defaults_for_adding(). In the future we might also want to update
the last deck/notetype on successful completion, if entries weren't
specified in the file.

https://forums.ankiweb.net/t/importing-new-notes-to-wrong-deck-in-anki-2-1-63/30598

* Address review feedback from Rumo
2023-05-31 13:47:12 +10:00
Damien Elmes
7f6c410ca5
Various changes to I/O handling (#2513)
* Store coordinates as ratios of full size

* Use single definition for cappedCanvasSize()

* Move I/O review code into ts/image-occlusion

A bit simpler when it's all in one place.

* Reduce number precision, and round to whole pixels

>>> n=10000
>>> for i in range(1, int(n)): assert i == round(float("%0.4f" % (i/n))*n)

* Minor typing tweak

So, it turns out that typing is mostly broken in ts/image-occlusion.
We're importing from fabric which is a js file without types, so types
like fabric.Canvas are resolving to any.

I first tried switching to `@types/fabric`, which introduced a slew of
typing errors. Wasted a few hours trying to address them, before deciding
to give up on it, since the types were not complete. Then found fabric
has a 6.0 beta that introduces typing, and spent some time with that, but
ran into some new issues as it still seems to be a work in progress.
I think we're probably best off waiting until it's out and stabilized
before sinking more effort into this.

* Refactor (de)serialization of occlusions

To make the code easier to follow/maintain, cloze deletions are now decoded/
encoded into simple data classes, which can then be converted to Fabric objects
and back. The data objects handle converting from absolute/normal positions, and
producing values suitable for writing to text (eg truncated floats).

Various other changes:

- Polygon points are now stored as 'x,y x2,y2 ...' instead of JSON in cloze
divs, as that makes the handling consistent with reading from cloze deletion
text.
- Fixed the reviewer not showing updated placement when a polygon was moved.
- Disabled rotation controls in the editor, since we don't support rotation during
review.
- Renamed hideInactive to occludeInactive, as it wasn't clear whether the former
meant to hide the occlusions, or keep them (hiding the content). It's stored
as 'oi=1' in the cloze text.

* Increase canvas size limit, and double pixels when required.

* Size canvas based on container size

This results in sharper masks when the intrinsic image size is smaller
than the container, and more legible ones when the container is smaller than
the intrinsic image size.

By using the container instead of the viewport, we account for margins,
and when the pixel ratio is 1x, the canvas size and container size should
match.

* Disable zoom animation on editor load

* Default to rectangle when adding new occlusions

* Allow users to add/update notes directly from mask editing page

* The mask editor needs to work with css pixels, not actual pixels

The canvas and image were being scaled too large, which impacted
performance.
2023-05-31 13:45:12 +10:00
Damien Elmes
921e8c7985 percent-encoding -> percent-encoding-iri
Closes #2526
2023-05-29 14:46:02 +10:00
Damien Elmes
15dcb09036
Detect incorrect usage of triple slash in TypeScript (#2524)
* Migrate check_copyright to Rust

* Add a new lint to check accidental usages of /// in ts/svelte comments

* Fix a bunch of incorrect jdoc comments

* Move contributor check into minilints

Will allow users to detect the issue locally with './ninja check'
before pushing to CI.

* Make Cargo.toml consistent with other crates
2023-05-26 12:49:44 +10:00
Damien Elmes
7686cb8de8
Fix misaligned image occlusions (#2512)
* Cloze styling is not required in I/O notetype

* Use raw string for IO template

* Rename to notetype.css and use more specific ids

* Move internal i/o styling into runtime

Storing it in the notetype makes it difficult to make changes, and
makes it easier for the user to break.

* Fix misaligned occlusions

At larger screen sizes, the canvas was not increasing above its configured
size, so it ended up being placed top center instead of expanding to fit
the entire container area.

To resolve this, both the image and canvas are forced to the container
size, and the container is constrained to the size of the viewport,
with the same aspect ratio as the image.

Closes #2492
2023-05-23 11:59:50 +10:00
Joel Koen
6b1c799cbf
Expose some collection methods already public in rslib backend (#2510)
* Expose some collection methods already public in rslib backend
2023-05-22 13:44:18 +10:00
Damien Elmes
c520b59311 Support prop queries in filtered decks
https://forums.ankiweb.net/t/phantom-overdue-reviews/30300
2023-05-20 10:49:00 +10:00
Damien Elmes
40a68afad3 Add the ability to search for custom data properties
Closes #2491
2023-05-18 15:54:01 +10:00
Damien Elmes
a19cb75768 Fix broken media importing in non-legacy apkg path
- Ensure our unit tests cover the non-legacy path, and check file
contents and not just existence.
- Pass `compressed` into copy_and_ensure_sha1_set(). We can't just
test for self.sha1.is_none(), as that fails in the case where an existing
media file was found in the legacy path.

https://forums.ankiweb.net/t/anki-media-file-corruption-when-exporting-png-files/30315
2023-05-18 11:33:01 +10:00