anki/qt/aqt
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
..
browser Disable Toggle Bury when nothing is selected (#2529) 2023-05-31 13:47:43 +10:00
data Ensure sync spinner spins when reduce motion is on 2023-03-26 14:49:49 +10:00
forms Make stats title translatable 2023-06-07 16:25:35 +10:00
import_export Fix inability to import csv when path contains single quote 2023-05-18 11:50:34 +10:00
operations Add ability to restore a notetype to its original configuration (#2472) 2023-04-18 14:07:51 +10:00
qt Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
__init__.py Only apply Wayland workaround in Wayland path 2023-05-29 19:07:54 +10:00
_macos_helper.py Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
about.py fix stats calendar incorrect due to daylight savings time (#2456) 2023-03-28 15:35:06 +10:00
addcards.py add shortcut to close addcards window (#2031) 2022-08-31 20:09:09 +10:00
addons.py Add add-on installation hooks (#2523) 2023-05-29 19:47:49 +10:00
changenotetype.py Update Python deps 2023-03-31 14:04:05 +10:00
clayout.py V -> ValueType 2023-04-19 16:43:23 +10:00
colors.py Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
customstudy.py Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
dbcheck.py Backup improvements (#1728) 2022-03-21 19:40:42 +10:00
debug_console.py Improve debug console (#2435) 2023-03-15 15:29:05 +10:00
deckbrowser.py Remove duplicate renderPage invocation 2023-06-07 16:10:35 +10:00
deckchooser.py Make dialogs non-blocking (#1650) 2022-02-10 09:53:13 +10:00
deckconf.py Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
deckdescription.py Update Python deps 2023-03-31 14:04:05 +10:00
deckoptions.py Rework & unify webview identification and title setting (#2366) 2023-02-10 14:53:11 +10:00
editcurrent.py PEP8 editorMode 2022-01-12 15:01:43 +10:00
editor.py Fix two issues that can cause editor fields to behave incorrectly (#2540) 2023-06-14 09:38:06 +10:00
emptycards.py Rework & unify webview identification and title setting (#2366) 2023-02-10 14:53:11 +10:00
errors.py Fix "Add-ons possibly involved" message never appearing on Windows (#2536) 2023-06-07 15:09:18 +10:00
exporting.py Add deck/collection export hooks (#1971) 2022-07-22 12:45:47 +10:00
fields.py Add option to exclude fields from search (#2394) 2023-03-20 07:46:03 +10:00
filtered_deck.py Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
flags.py Introduce new color palette using Sass maps (#2016) 2022-09-16 14:11:18 +10:00
gui_hooks.py Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
importing.py Update Python deps 2023-03-31 14:04:05 +10:00
legacy.py Import submodules directly (#1662) 2022-02-13 13:40:47 +10:00
main.py Ensure there's no duplicate shortcuts after running state_shortcuts_will_change (#2509) 2023-05-22 14:07:15 +10:00
mediacheck.py Add option to tag notes with missing media (#2379) 2023-02-20 18:48:09 +10:00
mediasrv.py Migrate to protobuf-es (#2547) 2023-06-14 22:47:37 +10:00
mediasync.py Rework syncing code, and replace local sync server (#2329) 2023-01-18 12:43:46 +10:00
modelchooser.py Add callback and non-blocking option to StudyDeck (#1643) 2022-02-07 22:05:59 +10:00
models.py Update Python deps 2023-03-31 14:04:05 +10:00
mpv.py Fix two mpv issues on Windows (#2294) 2023-01-03 11:59:39 +10:00
notetypechooser.py Make dialogs non-blocking (#1650) 2022-02-10 09:53:13 +10:00
overview.py Do not append description button for filtered deck (#2266) 2022-12-11 15:03:11 +10:00
package.py Another attempt at fixing missing cacert.pem 2022-12-30 15:30:53 +10:00
preferences.py Move answer keys to right of dialog to reduce vertical space 2023-05-20 17:37:55 +10:00
profiles.py Allow the user to configure answer keys (#2502) 2023-05-18 17:47:51 +10:00
progress.py fix progress.update(value=0) to not increment progress (#1998) 2022-08-01 20:16:42 +10:00
props.py Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
py.typed mark anki and aqt modules as having typing info 2020-01-13 13:03:37 +10:00
reviewer.py Migrate to protobuf-es (#2547) 2023-06-14 22:47:37 +10:00
schema_change_tracker.py Add ability to restore a notetype to its original configuration (#2472) 2023-04-18 14:07:51 +10:00
sound.py Log mpv invocation failure for debugging 2023-05-11 14:47:23 +10:00
stats.py Update Python deps 2023-03-31 14:04:05 +10:00
studydeck.py Fix new deck not being selected (#1681) 2022-02-22 21:51:23 +10:00
stylesheets.py Workaround Ubuntu ignoring tooltip palette in dark mode 2023-05-31 15:19:10 +10:00
switch.py Auto-hide toolbar in Reviewer (#2262) 2023-01-09 14:39:31 +10:00
sync.py Rework syncing code, and replace local sync server (#2329) 2023-01-18 12:43:46 +10:00
tagedit.py switch to new-style PyQt scoped enums and Qt6 2021-10-15 12:57:19 +10:00
taglimit.py Move custom study tag and limit gathering+saving into the backend 2022-03-10 16:23:03 +10:00
taskman.py Add apkg import/export on backend (#1743) 2022-05-02 21:12:46 +10:00
theme.py Apply Latin1 fix to other platforms 2023-05-31 16:41:12 +10:00
toolbar.py Update Python deps 2023-03-31 14:04:05 +10:00
tts.py Revert backwards incompatible changes to TTSVoice (#2378) 2023-02-20 17:43:18 +10:00
undo.py fix redo menu item showing undo text 2021-08-04 10:28:45 +10:00
update.py Update Python deps 2023-03-31 14:04:05 +10:00
utils.py Store separate state/geometry for each Qt minor version 2023-05-18 10:04:30 +10:00
webview.py Fix confusion of reduce_motion with minimalist_mode (#2413) 2023-03-06 18:15:43 +10:00
widgetgallery.py Improve debug console (#2435) 2023-03-15 15:29:05 +10:00
winpaths.py run pyupgrade over codebase [python upgrade required] 2021-10-04 15:05:48 +10:00