* Prevent unwanted <div> from being left behind when clearing field
* Use event.currentTarget instead of 'this'
* Check if event.data is empty for better performance
* Change order of conditions for better performance
* Allow customization of add-on config help path
This is useful for loading translated versions of the help file if available
* dir -> module
* Allow setting a callback instead to produce config docs
* Fix media playback not terminating when previewer is closed
https://forums.ankiweb.net/t/anki-2-1-50-beta/15608/78
* Fix _on_preview_closed being called twice unnecessarily
The function was being called twice when the preview button is clicked
while the previewer is open.
* Fix console error caused by leftover code
The following error was shown in the console when closing previewer:
`Uncaught TypeError: Cannot read property 'classList' of null`
* Toggle state of preview button via 'active' prop
* Support drag & drop in main window to import files
* Pass drag & drop events to super when not in deck browser
Seems this is required so that JS in the reviewer receives dragover
* Remove unused allowDrops
* Add new `card_rendering` mod
Parses a text with av/tts tags and strips or extracts tags.
* Replace old `extract_av_tags` and `strip_av_tags`
... with new `card_rendering` mod
* ressource -> resource
* Add AV prettifier for use in browser table
* Accept String in av tag routines
... and avoid redundant writes if no changes need to be made.
* add benchmarking with criterion; make links test optional (dae)
cargo install cargo-criterion, then run ./bench.sh
* performance comparison: creating HashMap up front (dae)
the previous solution:
anki_tag_parse time: [1.8401 us 1.8437 us 1.8476 us]
this solution:
anki_tag_parse time: [2.2420 us 2.2447 us 2.2477 us]
change: [+21.477% +21.770% +22.066%] (p = 0.00 < 0.05)
Performance has regressed.
* Revert "performance comparison: creating HashMap up front" (dae)
This reverts commit f19126a2f15b729b825825a49283f63ab13474d0.
* add missing header
* Write error message if tts lang is missing
* `Tag` -> `Directive`
* Make hard repeat the current step's interval in v3
Unless for the first step to avoid identical interval with Again.
* Make Hard repeat the current step's interval in v2
* Adjust test to new Hard behaviour
- Copy identical fields as before, but maintain a list of copied fields
and only add non-empty ones to it.
- Instead of setting remaining fields by their indices, assign remaining non-empty old fields to new fields sequentially
This results in less fields being lost when switching notetypes.
* Preload external css files to prevent flash of unstyled content
This is an implementation of the approach mentioned in the commit
message of 46b85d5.
* Tweak max_age value for css files
Ensure that css preloading works even on a slow PC.
* Fix steps being mistaken for seconds
* Cap steps at `u32::max` seconds
* Fix overflow of steps in Rust
* Prevent overflow of `IntervalKind`
* Prevent overflow in `revlod/mod.rs`
Also replace some `as` with `from` and `try_from` as is recommended to
highlight potential issues.
* Ensure v2 doesn't store overflowing revlog ivls
* Lower steps cap in deck options
Whereas large card intervals are converted to days, revlog intervals use
i32s to store large numbers of seconds.
* Format
We want to preserve the backend checks, because they may also detect
bugs. So we do the debouncing on the frontend instead, transitioning
into a temporary state until the background op completes.
https://forums.ankiweb.net/t/anki-2-1-50-beta/15608/74
When we updated to flask 2.0, the default caching time changed to
0. When setting the HTML of a new card side in the DOM, the browser
first removes the existing content (including styling), then sends a
HTTP request to us to check whether the file has changed or not. By the
time the answer has arrived, the browser has repainted without the
styling, and thus we get a flicker.
A side-effect of reverting to flask 1.x behaviour is that external changes
to media files will not be reflected in Anki for an hour, unless Anki
is restarted, or the caches are cleared manually with an add-on. An
alternative approach would be to pre-fetch the css files like we do with
images, but there are other things like fonts to think about as well.
Closes#1455
* Add "Show duplicates" to LabelContainer
* Avoid bubbling down the duplicate logic into EditorField
* Move duplicate link into its own slot
to center it between name/description and field-state.
* Revert "Move duplicate link into its own slot"
This reverts commit 3a4511042da7083a52d67b58550b13d873dcbea5.
* Justify dupes within FieldState
to achieve the same result as before while avoiding additional logic within EditorField.
Co-Authored-By: Henrik Giesel <hengiesel@gmail.com>
This brings the behaviour a bit closer to the default ordering of new
cards when they are reset, and is better than an undefined template
order. But it's a stopgap solution, and in the long run, filtered decks
need a bit of a rethink with the improved ordering than v3 has brought.
* Set QT_QPA_PLATFORM for Win on recent Qt versions
Erroneously dropped for Qt 5.15.1+.
* Enable original shortcut to create copy
* minor tweaks to comment to make it clearer (dae)
* The importer list have a Hook
Previously, add-on 175027074 simply edited the list once. It became impossible
since the list became a function. Hence I need a filter to add the list here.
@kelciour (nice to meet you by the way), you may be interested by it too (at
least if I believe efb1ce46d4 )
I would have preferred to use `anki.importing.base.Importer` instead of
`Any`. However, this leads to
> Name "anki.importing.base.Importer" is not defined [name-defined]
when I run test.
Helps to solve this would be welcomed
* mention the hook may not last too long (dae)
* Add py3.9 to hooks
This follows examples from efb1ce46d4 I assume the
hooks were missed because those were not considered types but strings.
I did not even try to run pyupgrade and did the change manually, then used bazel format
* remove wildcard import in find.py, and change Any to object (dae)
Kept the favicon, but have reverted the rest, as it unfortunately did
not seem to prevent the issue from occurring.
Original discussion: https://github.com/ankitects/anki/pull/1369
This reverts commit 6d0f7e7f05.
Fixes#983
This has been a long-standing issue that was infrequent enough on
developer machines that we weren't able to get to the bottom of it before
now. As luck would have it, the new ARM build had just the right timing
for this to occur every few invocations, and I was able to narrow it down
to the call that turns off the cache.
We don't really want the cache, so this is not a great solution. But I
ran into trouble when trying to figure out a better solution:
- Calling setHttpCacheType() earlier (eg immediately after creating the
page) fails.
- It even fails if you attempt to change the setting in the shared
default profile before any webviews are loaded:
```
def setupMainWindow(self) -> None:
QWebEngineProfile.defaultProfile().setHttpCacheType(QWebEngineProfile.HttpCacheType.NoCache)
```
- Creating a profile separately, and passing it into QWebEnginePage()
does work. But it introduces a warning each time a webview is deallocated,
and I fear it may lead to crashes:
```
Release of profile requested but WebEnginePage still not deleted. Expect troubles !
```
I tried various combinations of parents for the profile and page, and
turning web._page into an unretained property, but could not figure it out.
Some Googling pulls up a bunch of other people who seem to have hit similar
issues with PyQt. If anyone has any ideas, they'd be welcome; in the mean
time, I guess we're better off using up some of the user's disk
space than sometimes failing to load.
The profile-in-advance code I tried is below:
```
diff --git a/qt/aqt/webview.py b/qt/aqt/webview.py
index 1c96112d8..4f3e91284 100644
--- a/qt/aqt/webview.py
+++ b/qt/aqt/webview.py
@@ -23,9 +23,49 @@ serverbaseurl = re.compile(r"^.+:\/\/[^\/]+")
BridgeCommandHandler = Callable[[str], Any]
+def _create_profile(parent: QObject) -> QWebEngineProfile:
+ qwebchannel = ":/qtwebchannel/qwebchannel.js"
+ jsfile = QFile(qwebchannel)
+ if not jsfile.open(QIODevice.OpenModeFlag.ReadOnly):
+ print(f"Error opening '{qwebchannel}': {jsfile.error()}", file=sys.stderr)
+ jstext = bytes(cast(bytes, jsfile.readAll())).decode("utf-8")
+ jsfile.close()
+
+ script = QWebEngineScript()
+ script.setSourceCode(
+ jstext
+ + """
+ var pycmd, bridgeCommand;
+ new QWebChannel(qt.webChannelTransport, function(channel) {
+ bridgeCommand = pycmd = function (arg, cb) {
+ var resultCB = function (res) {
+ // pass result back to user-provided callback
+ if (cb) {
+ cb(JSON.parse(res));
+ }
+ }
+
+ channel.objects.py.cmd(arg, resultCB);
+ return false;
+ }
+ pycmd("domDone");
+ });
+ """
+ )
+ script.setWorldId(QWebEngineScript.ScriptWorldId.MainWorld)
+ script.setInjectionPoint(QWebEngineScript.InjectionPoint.DocumentReady)
+ script.setRunsOnSubFrames(False)
+
+ profile = QWebEngineProfile(parent)
+ profile.setHttpCacheType(QWebEngineProfile.HttpCacheType.NoCache)
+ profile.scripts().insert(script)
+ return profile
+
+
class AnkiWebPage(QWebEnginePage):
- def __init__(self, onBridgeCmd: BridgeCommandHandler) -> None:
- QWebEnginePage.__init__(self)
+ def __init__(self, onBridgeCmd: BridgeCommandHandler, parent: QObject) -> None:
+ profile = _create_profile(parent)
+ QWebEnginePage.__init__(self, profile, parent)
self._onBridgeCmd = onBridgeCmd
self._setupBridge()
self.open_links_externally = True
@@ -46,39 +86,6 @@ class AnkiWebPage(QWebEnginePage):
self._channel.registerObject("py", self._bridge)
self.setWebChannel(self._channel)
- qwebchannel = ":/qtwebchannel/qwebchannel.js"
- jsfile = QFile(qwebchannel)
- if not jsfile.open(QIODevice.OpenModeFlag.ReadOnly):
- print(f"Error opening '{qwebchannel}': {jsfile.error()}", file=sys.stderr)
- jstext = bytes(cast(bytes, jsfile.readAll())).decode("utf-8")
- jsfile.close()
-
- script = QWebEngineScript()
- script.setSourceCode(
- jstext
- + """
- var pycmd, bridgeCommand;
- new QWebChannel(qt.webChannelTransport, function(channel) {
- bridgeCommand = pycmd = function (arg, cb) {
- var resultCB = function (res) {
- // pass result back to user-provided callback
- if (cb) {
- cb(JSON.parse(res));
- }
- }
-
- channel.objects.py.cmd(arg, resultCB);
- return false;
- }
- pycmd("domDone");
- });
- """
- )
- script.setWorldId(QWebEngineScript.ScriptWorldId.MainWorld)
- script.setInjectionPoint(QWebEngineScript.InjectionPoint.DocumentReady)
- script.setRunsOnSubFrames(False)
- self.profile().scripts().insert(script)
-
def javaScriptConsoleMessage(
self,
level: QWebEnginePage.JavaScriptConsoleMessageLevel,
@@ -228,7 +235,7 @@ class AnkiWebView(QWebEngineView):
) -> None:
QWebEngineView.__init__(self, parent=parent)
self.set_title(title)
- self._page = AnkiWebPage(self._onBridgeCmd)
+ self._page = AnkiWebPage(self._onBridgeCmd, self)
self._page.setBackgroundColor(
self.get_window_bg_color(theme_manager.night_mode)
@@ -242,7 +249,6 @@ class AnkiWebView(QWebEngineView):
self.requiresCol = True
self.setPage(self._page)
- self._page.profile().setHttpCacheType(QWebEngineProfile.HttpCacheType.NoCache)
self.resetHandlers()
self.allowDrops = False
self._filterSet = False
```
This was motivated by the fact that recording was crashing on the native
M1 build. That ended up being mostly a PEBKAC problem - turns out the
Mac Mini has no built-in microphone 🤦.
I still thinks this has some value though - it doesn't crash in such
cases, and probably doesn't suffer from the problem shown in this thread
either:
https://forums.ankiweb.net/t/anki-crashes-when-trying-to-record-on-mac/14764
For now, this is only enabled when running on arm64. If it turns out to
be reliable, it could be offered as an option on amd64 as well.
More pleasant to work with than ObjectiveC, which will help with the
following commit.
Swift libraries weren't added to macOS until 10.14.4, so theme
autodetection will fail on 10.14.0-10.14.3. The Qt6 build will have its
minimum version bumped to 10.14.4; the Qt5 build will remain on 10.13.4.
Bazel's rules_swift doesn't currently support building Swift dylibs, so
we need to invoke swiftc directly via a genrule().