合并js代码

This commit is contained in:
Tlntin
2022-11-20 10:34:12 +08:00
parent 22c7d4f4a3
commit 5b9e5a7228
2 changed files with 25 additions and 21 deletions

View File

@@ -165,16 +165,7 @@ fn main() -> wry::Result<()> {
webbrowser::open(&href).expect("no browser");
}
};
#[cfg(target_os = "windows")]
let webview = WebViewBuilder::new(window)?
.with_url(&url.to_string())?
.with_devtools(cfg!(feature = "devtools"))
.with_initialization_script(include_str!("pake.js"))
.with_ipc_handler(handler)
.build()?;
#[cfg(target_os = "linux")]
let webview = WebViewBuilder::new(window)?
.with_url(&url.to_string())?
.with_devtools(cfg!(feature = "devtools"))
@@ -182,13 +173,6 @@ fn main() -> wry::Result<()> {
.with_ipc_handler(handler)
.build()?;
#[cfg(target_os = "macos")]
let webview = WebViewBuilder::new(window)?
.with_url(&url.to_string())?
.with_devtools(cfg!(feature = "devtools"))
.with_initialization_script(include_str!("pake-mac.js"))
.with_ipc_handler(handler)
.build()?;
#[cfg(feature = "devtools")] {
webview.open_devtools();

View File

@@ -1,11 +1,25 @@
/**
* @typedef {string} KeyboardKey `event.key` 的代号,
* 见 <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values>
* @typedef {() => void} OnKeyDown 使用者按下 [CtrlKey] 时应该执行的行为
* 以 Ctrl 键 为首的快捷键清单。
* @typedef {() => void} OnKeyDown 使用者按下 [CtrlKey] 或者 ⌘ [KeyboardKey]时应该执行的行为
* 以 Ctrl键或者Meta 键 (⌘) 为首的快捷键清单。
* 每个写在这里的 shortcuts 都会运行 {@link Event.preventDefault}.
* @type {Record<KeyboardKey, OnKeyDown>}
*/
const metaKeyShortcuts = {
'ArrowUp': () => scrollTo(0, 0),
'ArrowDown': () => scrollTo(0, document.body.scrollHeight),
'[': () => window.history.back(),
']': () => window.history.forward(),
'r': () => window.location.reload(),
'-': () => zoomOut(),
'=': () => zoomIn(),
'+': () => zoomIn(),
'0': () => zoomCommon(() => '100%'),
}
const ctrlKeyShortcuts = {
'ArrowUp': () => scrollTo(0, 0),
'ArrowDown': () => scrollTo(0, document.body.scrollHeight),
@@ -121,9 +135,15 @@ window.addEventListener('DOMContentLoaded', (_event) => {
event.preventDefault();
f();
};
if (event.ctrlKey && event.key in ctrlKeyShortcuts) {
preventDefault(ctrlKeyShortcuts[event.key]);
if (/windows|linux/i.test(navigator.userAgent)) {
if (event.ctrlKey && event.key in ctrlKeyShortcuts) {
preventDefault(ctrlKeyShortcuts[event.key]);
}
}
if (/macintosh|mac os x/i.test(navigator.userAgent)) {
if (event.metaKey && event.key in metaKeyShortcuts) {
preventDefault(ctrlKeyShortcuts[event.key]);
}
}
});