Commit Graph

9219 Commits

Author SHA1 Message Date
Arthur Milchior
69469c6428
Add py3.9 to hooks (#1542)
* 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)
2021-12-09 09:11:22 +10:00
TheFeelTrain
8306bc1e25
Add .aac files to editor (#1540)
.aac files work as expected, but Anki doesn't pick them up by default.
2021-12-08 21:25:47 +10:00
Damien Elmes
52f17c12e0 Partially revert "Fix issue 1362 and add a default favicon.ico (#1369)"
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.
2021-12-08 21:20:39 +10:00
Damien Elmes
db5117ce1a fix webviews sometimes failing to load, by enabling cache
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
```
2021-12-08 21:20:39 +10:00
Damien Elmes
d87383a2d5 experimental ARM Linux packaged build 2021-12-08 20:53:46 +10:00
Damien Elmes
ed5273fae7 unpin regex & update Python deps
regex was failing to build correctly on the latest Xcode/macOS 12, and
black have dropped it as a dependency due to the build difficulties it
creates.
2021-12-08 15:11:47 +10:00
Damien Elmes
fa71b40df9 update translations 2021-12-08 10:23:27 +10:00
Damien Elmes
cad0c64105 add unbury_cards() op
https://forums.ankiweb.net/t/add-a-collection-operation-to-unbury-cards/15720
2021-12-08 09:44:47 +10:00
RumovZ
cd22485f9b
Add browser action to create note copy (#1535)
* Add browser action to create note copy

* Use new note and copy instead of using source

* Change shortcut due to Qt's Alt-Gr bug

* Add separate routine for suffixing action with ...

* Remove '...' from some translations

The convention is to add an ellipsis if more input is required to
perform the action. Whether or not the action opens a new window is not
decisive.
Sources:
https://developer.apple.com/design/human-interface-guidelines/macos/menus/menu-anatomy/
https://docs.microsoft.com/en-us/windows/win32/uxguide/cmd-toolbars
2021-12-08 08:40:48 +10:00
RumovZ
bcea43dc6a
Disable saving fullscreen geometry (#1538)
Restoring fullscreen windows is buggy.
https://forums.ankiweb.net/t/anki-2-1-50-beta/15608/39
2021-12-08 08:12:10 +10:00
nwwt
9becb4c11f
Allow <audio> to play without user interaction in accordance to autoplay setting v2 (#1539)
Adds back setting Chromium's autoplay policy according to Anki's, this time without globals.
2021-12-08 08:08:56 +10:00
Damien Elmes
0de24122ad implement a basic native macOS audio recorder
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.
2021-12-07 18:48:24 +10:00
Damien Elmes
d9c8addbc1 switch AnkiHelper to Swift
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().
2021-12-07 18:48:24 +10:00
Matthias Metelka
924e16879f
Update about.py (#1533)
* Update about.py

* Add cqg to list

for his contributions to the community (testing, support, suggestions).

* Add the AnKing to list

for his efforts to keep add-ons compatible with new versions and popularizing Anki in the medical community via YouTube, Reddit and other social media.
2021-12-07 09:01:30 +10:00
Damien Elmes
a377edda7e remove legacy warning on pointVersion
https://forums.ankiweb.net/t/anki-2-1-50-beta/15608/30
2021-12-06 19:58:53 +10:00
Abdo
4571e78016
Fix error on previewer close (#1528)
_on_close was being called twice, causing an error when the destroyed
_web is accessed again.
2021-12-06 19:34:41 +10:00
Abdo
dc4fd95f24
Fix previous card info shortcut label (#1534) 2021-12-06 19:01:37 +10:00
Matthias Metelka
1fc060620c
Decrease button and tag size for Linux and Windows (#1532)
* Decrease button size for platforms other than Mac

* Refactor legacy button styles

* Restrict size of add-on icons
2021-12-06 19:01:15 +10:00
Henrik Giesel
fa6a531bd5
Block {,max-}{width,height} from being copied (#1529) 2021-12-06 18:41:08 +10:00
Abdo
b3ea7288ab
Flip arrows of Bootstrap-styled <select>s for RTL langs (#1526)
* Flip arrows of Bootstrap-styled <select>s for RTL langs

* Use the dir attribute to set document direction

* Remove unused variable and fix use of CSS var
2021-12-06 18:40:26 +10:00
Damien Elmes
cee57f4cb7 work around 'which deck would you like' sticking around on Qt6/macOS
Not a problem on Qt5, and not really sure why this works 🤷
2021-12-06 18:24:38 +10:00
Damien Elmes
d515939340 fix error when gathering new cards in reverse position
Also simplify order clause - with did and queue limited to a constant,
SQLite is smart enough to use the covering index for sorting by due.
2021-12-06 17:08:00 +10:00
Hikaru Y
fcb21ceed5
Update CONTRIBUTORS (#1527) 2021-12-05 12:33:40 +10:00
Hikaru Y
e8b795ba69
Fix custom CSS not being applied to scrollbars in night mode (#1525) 2021-12-05 08:20:42 +10:00
Matthias Metelka
eefa46dc8e
Rename StickyNav to StickyHeader (#1524)
so as to not create false assumptions about its functionality.
2021-12-05 08:18:58 +10:00
Damien Elmes
cbc4f25be7 ensure all packaged files are world-readable
https://forums.ankiweb.net/t/anki-2-1-50-beta/15608/4
2021-12-05 08:16:54 +10:00
Damien Elmes
9af87ba082 fix _db_command: TypeError: a bytes-like object is required, not 'list'
Bytes come in as an array of integers, which we could probably solve on
the PyO3 end instead, but this will do for now - the same fix is already
used for non-DB case.

https://forums.ankiweb.net/t/anki-2-1-50-beta/15608/15
2021-12-05 08:00:26 +10:00
Damien Elmes
43c41d76ba fix cargo-env on darwin-aarch64 2021-12-04 17:03:03 +10:00
Damien Elmes
6de2dc6cd4 place .cargo/bin at end of path when packaging
Otherwise a system-installed older Rust will override the version we
have set with cargo-env, which can break the build.
2021-12-04 16:43:56 +10:00
Matthias Metelka
933ee647bc
Align design of Change Notetype screen with rest of UI (#1522)
* Remove background and border from scrollArea

* Fix 1px of background text showing above template header on scroll

I couldn't figure out the reason for this "clipping" issue. What I tried:
- check HTML structure for any elements that might add extra padding/margin
- remove the 1px border of the header

* Adjust spacing to be more in line with rest of UI
2021-12-04 14:53:16 +10:00
Damien Elmes
80e6e7ab62 tweak qrc deprecation warning 2021-12-04 14:35:49 +10:00
Damien Elmes
3868e1e4a6 improve PyQt5.Qt compatibility
- support 'from PyQt5 import Qt' case
- alias it to aqt.qt modules instead of relying on getattr, so that
'from PyQt5.Qt import *' case works.
2021-12-04 14:35:49 +10:00
Damien Elmes
61aa8a5bc9 remove enum proxy on QUrl
No add-ons appear to be using it, and it breaks a method decorated
with @pyqtSlot(QUrl) that AMBOSS (unnecessarily) uses.
2021-12-04 14:35:49 +10:00
Damien Elmes
924fd39444 apply Qt aliases after enum proxy injected
Ensures legacy enum references on a legacy alias still work.
2021-12-04 14:35:49 +10:00
Damien Elmes
c1612e641d handle add-ons attempting to import isMac/isWin from aqt.utils 2021-12-04 14:35:47 +10:00
Damien Elmes
dcfc6d73a2 fix media trash throttling; decrease delay 2021-12-04 09:10:31 +10:00
Damien Elmes
db3ce467a3 clarify QueryOp docstring
Maybe there's a better name we could use than QueryOp - suggestions
welcome.
2021-12-04 08:55:11 +10:00
Damien Elmes
5cc261fce7 use QueryOp for unused media deletion
Closes #1517
2021-12-04 08:55:11 +10:00
Damien Elmes
42455eca64 QueryOp() was attempting to open progress window on background thread 2021-12-04 08:55:11 +10:00
Matthias Metelka
936323e430
Show downwards arrow on SelectButton (#1521)
* Show downwards arrow on SelectButton

The arrow wasn't showing because the button linear-gradient background overrides the background-image for the arrow.

Select can't have pseudo-elements, so I had to add an extra div.

* Remove height definition

to fix text cutting off on Windows.

* Hide default arrow in light theme

to keep consistency with dark theme, where the arrow has to be custom due to the button gradient.

* Use alternative approach to prevent text getting cropped

and add height definition back again.

Co-Authored-By: Hikaru Y. <47855854+hikaru-y@users.noreply.github.com>

* Adjust arrow position for rtl

Co-authored-by: Hikaru Y. <47855854+hikaru-y@users.noreply.github.com>
2021-12-04 08:08:20 +10:00
Matthias Metelka
3015ddd2c1
Fix bug(s) caused by deleting a notetype currently selected in AddCards (#1514)
* Remove unneeded old.note_type() call

Fixes TypeError thrown after deleting a notetype that's currently selected in the editor.

* Handle IndexError on notetype change

Occurs in the Add window when changing the notetype via NotetypeChooser from
- the notetype that's auto-selected after deleting the currently selected notetype
- to a notetype with fewer fields than the auto-selected one

* Add return to exception handler

to properly ignore the command.
2021-12-04 07:55:22 +10:00
Henrik Giesel
d0c6f0d7ba
Fix focus lost after adding note if non-sticky (#1523) 2021-12-03 21:41:12 +10:00
Damien Elmes
ae29c8c333 update PyOxidizer 2021-12-03 21:00:15 +10:00
Damien Elmes
661f769700 update Node deps
TypeScript is currently pinned. Before updating to 4.5, we will likely
need to use --preserveValueImports in svelte.ts:
https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#preserve-value-imports

There's also an issue with missing types when importing from bootstrap
.js files that will need investigating.
2021-12-03 20:35:53 +10:00
Damien Elmes
195361ed46 add script to put node/yarn on path 2021-12-03 20:35:53 +10:00
Damien Elmes
47b701688f fix update-licenses.sh 2021-12-03 20:35:53 +10:00
Damien Elmes
c2ab0de34f update Rust deps 2021-12-03 20:35:53 +10:00
Damien Elmes
67ee6f9c0e update to Rust 1.57 + latest rules_rust 2021-12-03 20:35:52 +10:00
Damien Elmes
8de3eaea65 fix Clippy lints in Rust 1.57 2021-12-03 19:53:37 +10:00
Damien Elmes
763932cbed update translations 2021-12-03 19:51:28 +10:00