Commit Graph

10385 Commits

Author SHA1 Message Date
Kavel Rao
e4cc77bbf6
Issue #2546 Exclude Fabric's canvas dependency (#2551)
* point canvas resolution to empty package

* Update CONTRIBUTORS
2023-06-19 13:50:13 +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
ffac5e0d14 Add support for order-only inputs
Now actions that trigger the archive tool to be rebuilt will not cause
existing downloads/extractions to be redone.
2023-06-15 22:10:13 +10:00
Damien Elmes
f70307a753 Avoid downloading files we already have 2023-06-15 21:59:11 +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
09c57369ad Migrate pylib/anki qt/aqt to group syntax (eg pylib:anki) 2023-06-15 17:17:55 +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
Hikaru Y
7164723a7a
Fix two issues that can cause editor fields to behave incorrectly (#2540)
* Fix shortcut not being unregistered when Plain/RichTextBadge is detroyed

This fixes an issue where, if the "Show HTML by default" option of
fields located at the same position in two notetypes have different
values, switching between those notetypes during an editor session
would cause the keyboard shortcut (Ctrl+Shift+X) to no longer function
correctly thereafter.

* Don't restore fields' state if notetype has been modified

This fixes an issue where editor fields behave incorrectly after
opening the 'Fields' dialog and customizing the notetype. An example
of incorrect behavior is that after adding a new field and closing
the dialog, the added field would display both richtext input and
plaintext input, regardless of the options.

* Rename type, variable and function

- Apply suggestions from code review
- Also use optional chaining instead of non-null assertion
2023-06-14 09:38:06 +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
686b596d08 AVTags -> AvTags
Avoids having to special-case string inflection in interface generation
2023-06-11 19:18:32 +10:00
Damien Elmes
1aaf6dbf18 Update translations 2023-06-07 16:26:06 +10:00
Damien Elmes
e9bfebe83e Make stats title translatable
https://forums.ankiweb.net/t/why-is-the-title-of-the-statistics-window-not-can-be-translated/30944
2023-06-07 16:25:35 +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
ea1180ffc2 Remove duplicate renderPage invocation
https://forums.ankiweb.net/t/duplicate-execution-of-the-same-operation-in-code/30943
2023-06-07 16:10:35 +10:00
Abdo
7044f0c53c
Fix "Add-ons possibly involved" message never appearing on Windows (#2536) 2023-06-07 15:09:18 +10:00
Christopher Woggon
fadeb99c99
Partially supporting 한글 (hangul, Korean characters) (#2533)
* Partially supporting 한글 (hangul, Korean characters)

* Externalized korean shortcuts to separate function

* formatting
2023-06-07 14:54:52 +10:00
Damien Elmes
e3b634a805 Update to Rust 1.70
Sparse registry is now the default
2023-06-07 14:52:31 +10:00
Abdo
3a32e4b1bd
Disable add-on buttons when no field is focused by default (#2532) 2023-06-05 12:44:28 +10:00
Abdo
51dc5860bd
Fix toggleable editor button styles (#2531) 2023-06-05 12:43:50 +10:00
Damien Elmes
e94ab5a44d Update translations 2023-06-05 09:20:19 +10:00
Damien Elmes
3a65836e02 Bump version 2023-06-05 09:20:00 +10:00
Damien Elmes
e2f33bd646 Top-level prettier files should no longer be required
Exclusion is handled by dprint, and prettier conf is embedded in
.dprint.json.
2023-06-01 11:13:14 +10:00
Damien Elmes
e63b4b9927 Experiment with disabling prettier whitespace sensitivity
Prettier by default tries to preserve whitespace around inline tags,
which can prevent problems such as a space before the period in
'<a>text</a>.':

https://prettier.io/blog/2018/11/07/1.15.0.html#whitespace-sensitive-formatting

Unfortunately only standard HTML block elements are excluded from this
behaviour, so all of our Svelte components are treated the same way, even
if they are block-based, or used in a way where the extra whitespace
doesn't matter. This makes the code somewhat harder to read.

Changing this option does carry the risk that rogue spaces will creep
into our UI in the future as code is formatted, but as there don't appear
to be any such issues with this initial reformat, I think the improved
readability may justify the relatively small risk.
2023-06-01 11:11:26 +10:00
Damien Elmes
06a5ada99b Apply Latin1 fix to other platforms
While much less likely on other platforms (with no current reports and
/Applications or /usr/share folders being the norm), the issue
could still occur.
2023-05-31 16:41:12 +10:00
Damien Elmes
aa9a734f69 Workaround Ubuntu ignoring tooltip palette in dark mode
https://forums.ankiweb.net/t/tooltip-hover-appearance-looks-strange/30384
2023-05-31 15:19:10 +10:00
Damien Elmes
1e00b7d4c4 Expose onUpdateHook/onShownHook via package 2023-05-31 15:19:09 +10:00
Damien Elmes
88f613aaf0 Update translations 2023-05-31 13:49:35 +10:00
Damien Elmes
7c96a6c5e1 Add link to website in README
Closes #2528
2023-05-31 13:49:19 +10:00
Abdo
3787699f8c
Disable Toggle Bury when nothing is selected (#2529) 2023-05-31 13:47:43 +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
Abdo
c87f62487b
Add add-on installation hooks (#2523)
* Add add-on installation hooks

* Fix GUI code run in background thread

deleteAddon() is run in the background in the update routine so it
shouldn't containg any GUI code.

* Add a hint to the docstrings (dae)
2023-05-29 19:47:49 +10:00
Damien Elmes
93e1a6be22 Only apply Wayland workaround in Wayland path
https://github.com/ankitects/anki/issues/1767#issuecomment-1562695240
2023-05-29 19:07:54 +10:00
Damien Elmes
b618ab93a5 Update hakari and licenses 2023-05-29 17:54:00 +10:00
Damien Elmes
489f0fd066 Continue with install if old installer fails
User may have manually removed files, or the installation may be corrupt.

https://forums.ankiweb.net/t/installing-anki-when-there-seems-to-be-a-previous-version/30621
2023-05-29 15:07:44 +10:00
Damien Elmes
921e8c7985 percent-encoding -> percent-encoding-iri
Closes #2526
2023-05-29 14:46:02 +10:00