合并js代码
This commit is contained in:
@@ -165,16 +165,7 @@ fn main() -> wry::Result<()> {
|
|||||||
webbrowser::open(&href).expect("no browser");
|
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)?
|
let webview = WebViewBuilder::new(window)?
|
||||||
.with_url(&url.to_string())?
|
.with_url(&url.to_string())?
|
||||||
.with_devtools(cfg!(feature = "devtools"))
|
.with_devtools(cfg!(feature = "devtools"))
|
||||||
@@ -182,13 +173,6 @@ fn main() -> wry::Result<()> {
|
|||||||
.with_ipc_handler(handler)
|
.with_ipc_handler(handler)
|
||||||
.build()?;
|
.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")] {
|
#[cfg(feature = "devtools")] {
|
||||||
webview.open_devtools();
|
webview.open_devtools();
|
||||||
|
|||||||
@@ -1,11 +1,25 @@
|
|||||||
/**
|
/**
|
||||||
* @typedef {string} KeyboardKey `event.key` 的代号,
|
* @typedef {string} KeyboardKey `event.key` 的代号,
|
||||||
* 见 <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values>
|
* 见 <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values>
|
||||||
* @typedef {() => void} OnKeyDown 使用者按下 [CtrlKey] 时应该执行的行为
|
* @typedef {() => void} OnKeyDown 使用者按下 [CtrlKey] 或者 ⌘ [KeyboardKey]时应该执行的行为
|
||||||
* 以 Ctrl 键 为首的快捷键清单。
|
* 以 Ctrl键或者Meta 键 (⌘) 为首的快捷键清单。
|
||||||
* 每个写在这里的 shortcuts 都会运行 {@link Event.preventDefault}.
|
* 每个写在这里的 shortcuts 都会运行 {@link Event.preventDefault}.
|
||||||
* @type {Record<KeyboardKey, OnKeyDown>}
|
* @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 = {
|
const ctrlKeyShortcuts = {
|
||||||
'ArrowUp': () => scrollTo(0, 0),
|
'ArrowUp': () => scrollTo(0, 0),
|
||||||
'ArrowDown': () => scrollTo(0, document.body.scrollHeight),
|
'ArrowDown': () => scrollTo(0, document.body.scrollHeight),
|
||||||
@@ -121,9 +135,15 @@ window.addEventListener('DOMContentLoaded', (_event) => {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
f();
|
f();
|
||||||
};
|
};
|
||||||
|
if (/windows|linux/i.test(navigator.userAgent)) {
|
||||||
if (event.ctrlKey && event.key in ctrlKeyShortcuts) {
|
if (event.ctrlKey && event.key in ctrlKeyShortcuts) {
|
||||||
preventDefault(ctrlKeyShortcuts[event.key]);
|
preventDefault(ctrlKeyShortcuts[event.key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (/macintosh|mac os x/i.test(navigator.userAgent)) {
|
||||||
|
if (event.metaKey && event.key in metaKeyShortcuts) {
|
||||||
|
preventDefault(ctrlKeyShortcuts[event.key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user