mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 05:52:22 -04:00
Make URL schemes dialog more ergonomic (#4002)
(originally merged into a PR branch) * Make URL schemes dialog more ergonomic * add name to contributors list * Title Case * Tweak build instructions so Cursor picks them up * Use a warning icon for the URL scheme pop-up * Default to cancelling
This commit is contained in:
parent
6427ff3db5
commit
f96c8c2ac8
7 changed files with 33 additions and 8 deletions
2
.cursor/rules/building.md
Normal file
2
.cursor/rules/building.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
- To build and check the project, use ./check in the root folder (or check.bat on Windows)
|
||||
- This will format files, then run lints and unit tests.
|
|
@ -1,2 +0,0 @@
|
|||
- To build and check the project, use ./check(.bat)
|
||||
- This will format files, then run lints and unit tests.
|
|
@ -227,6 +227,7 @@ JL710
|
|||
Matt Brubeck <mbrubeck@limpet.net>
|
||||
Yaoliang Chen <yaoliang.ch@gmail.com>
|
||||
KolbyML <https://github.com/KolbyML>
|
||||
Adnane Taghi <dev@soleuniverse.me>
|
||||
|
||||
********************
|
||||
|
||||
|
|
|
@ -89,6 +89,8 @@ preferences-url-scheme-prompt = Allowed { preferences-url-schemes } (space-separ
|
|||
preferences-url-scheme-warning = Blocked attempt to open `{ $link }`, which may be a security issue.
|
||||
|
||||
If you trust the deck author and wish to proceed, you can add `{ $scheme }` to your allowed { preferences-url-schemes }.
|
||||
preferences-url-scheme-allow-once = Allow Once
|
||||
preferences-url-scheme-always-allow = Always Allow
|
||||
|
||||
## NO NEED TO TRANSLATE. This text is no longer used by Anki, and will be removed in the future.
|
||||
|
||||
|
|
|
@ -221,6 +221,7 @@ def show(mw: aqt.AnkiQt) -> QDialog:
|
|||
"Yuki",
|
||||
"🦙 (siid)",
|
||||
"Mukunda Madhav Dey",
|
||||
"Adnane Taghi",
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -750,3 +750,11 @@ create table if not exists profiles
|
|||
|
||||
def set_allowed_url_schemes(self, schemes: list[str]) -> None:
|
||||
self.profile["allowedUrlSchemes"] = schemes
|
||||
|
||||
def always_allow_scheme(self, scheme: str) -> None:
|
||||
schemes = self.allowed_url_schemes()
|
||||
|
||||
if scheme not in schemes:
|
||||
schemes.append(scheme)
|
||||
|
||||
self.set_allowed_url_schemes(schemes)
|
||||
|
|
|
@ -5,8 +5,8 @@ from __future__ import annotations
|
|||
|
||||
from markdown import markdown
|
||||
|
||||
from aqt.qt import Qt, QUrl
|
||||
from aqt.utils import ask_user_dialog, getText, openLink, tr
|
||||
from aqt.qt import QMessageBox, Qt, QUrl
|
||||
from aqt.utils import MessageBox, getText, openLink, tr
|
||||
|
||||
|
||||
def show_url_schemes_dialog() -> None:
|
||||
|
@ -32,6 +32,13 @@ def is_supported_scheme(url: QUrl) -> bool:
|
|||
return scheme in allowed_schemes or scheme in ["http", "https"]
|
||||
|
||||
|
||||
def always_allow_scheme(url: QUrl) -> None:
|
||||
from aqt import mw
|
||||
|
||||
scheme = url.scheme().lower()
|
||||
mw.pm.always_allow_scheme(scheme)
|
||||
|
||||
|
||||
def open_url_if_supported_scheme(url: QUrl) -> None:
|
||||
from aqt import mw
|
||||
|
||||
|
@ -41,18 +48,24 @@ def open_url_if_supported_scheme(url: QUrl) -> None:
|
|||
|
||||
def on_button(idx: int) -> None:
|
||||
if idx == 0:
|
||||
show_url_schemes_dialog()
|
||||
openLink(url)
|
||||
elif idx == 1:
|
||||
always_allow_scheme(url)
|
||||
openLink(url)
|
||||
|
||||
msg = markdown(
|
||||
tr.preferences_url_scheme_warning(link=url.toString(), scheme=url.scheme())
|
||||
)
|
||||
ask_user_dialog(
|
||||
MessageBox(
|
||||
msg,
|
||||
buttons=[
|
||||
tr.actions_with_ellipsis(action=tr.preferences_url_schemes()),
|
||||
tr.actions_close(),
|
||||
tr.preferences_url_scheme_allow_once(),
|
||||
tr.preferences_url_scheme_always_allow(),
|
||||
(tr.actions_cancel(), QMessageBox.ButtonRole.RejectRole),
|
||||
],
|
||||
parent=mw,
|
||||
callback=on_button,
|
||||
textFormat=Qt.TextFormat.RichText,
|
||||
default_button=2,
|
||||
icon=QMessageBox.Icon.Warning,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue