🐛 整理下代码
This commit is contained in:
40
src-tauri/Cargo.lock
generated
40
src-tauri/Cargo.lock
generated
@@ -1353,12 +1353,46 @@ version = "0.5.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
|
checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libappindicator"
|
||||||
|
version = "0.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "db2d3cb96d092b4824cb306c9e544c856a4cb6210c1081945187f7f1924b47e8"
|
||||||
|
dependencies = [
|
||||||
|
"glib",
|
||||||
|
"gtk",
|
||||||
|
"gtk-sys",
|
||||||
|
"libappindicator-sys",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libappindicator-sys"
|
||||||
|
version = "0.7.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1b3b6681973cea8cc3bce7391e6d7d5502720b80a581c9a95c9cbaf592826aa"
|
||||||
|
dependencies = [
|
||||||
|
"gtk-sys",
|
||||||
|
"libloading",
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.139"
|
version = "0.2.139"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libloading"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "line-wrap"
|
name = "line-wrap"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@@ -2490,6 +2524,7 @@ dependencies = [
|
|||||||
"core-foundation",
|
"core-foundation",
|
||||||
"core-graphics",
|
"core-graphics",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
|
"dirs-next",
|
||||||
"dispatch",
|
"dispatch",
|
||||||
"gdk",
|
"gdk",
|
||||||
"gdk-pixbuf",
|
"gdk-pixbuf",
|
||||||
@@ -2503,6 +2538,7 @@ dependencies = [
|
|||||||
"instant",
|
"instant",
|
||||||
"jni",
|
"jni",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"libappindicator",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"ndk",
|
"ndk",
|
||||||
@@ -2536,9 +2572,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri"
|
name = "tauri"
|
||||||
version = "1.2.3"
|
version = "1.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5b48820ee3bb6a5031a83b2b6e11f8630bdc5a2f68cb841ab8ebc7a15a916679"
|
checksum = "fe7e0f1d535e7cbbbab43c82be4fc992b84f9156c16c160955617e0260ebc449"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cocoa",
|
"cocoa",
|
||||||
|
|||||||
@@ -17,20 +17,11 @@ tauri-build = { version = "1.2.1", features = [] }
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
serde_json = "1.0.89"
|
serde_json = "1.0.89"
|
||||||
serde = { version = "1.0.150", features = ["derive"] }
|
serde = { version = "1.0.150", features = ["derive"] }
|
||||||
tauri = { version = "1.2.3", features = [] }
|
tauri = { version = "1.2.4", features = ["system-tray"] }
|
||||||
image = "0.24.5"
|
image = "0.24.5"
|
||||||
home = "0.5"
|
home = "0.5"
|
||||||
tauri-utils = "1.2.1"
|
tauri-utils = "1.2.1"
|
||||||
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/tauri-plugin-window-state", branch = "dev"}
|
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/tauri-plugin-window-state", branch = "dev"}
|
||||||
# webbrowser = "0.8.2"
|
|
||||||
# wry = "0.23.4"
|
|
||||||
|
|
||||||
# [target.'cfg(target_os = "linux")'.dependencies]
|
|
||||||
# webkit2gtk = "0.18.0"
|
|
||||||
|
|
||||||
# [target.'cfg(target_os = "macos")'.dependencies]
|
|
||||||
# objc = "0.2.7"
|
|
||||||
# cocoa = {git = "https://github.com/servo/core-foundation-rs/"}
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# by default Tauri runs in production mode
|
# by default Tauri runs in production mode
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use tauri::MenuItem;
|
use tauri::MenuItem;
|
||||||
|
|
||||||
// #[cfg(target_os = "macos")]
|
|
||||||
// #[macro_use]
|
|
||||||
// extern crate objc;
|
|
||||||
|
|
||||||
use tauri::{
|
use tauri::{
|
||||||
window::PlatformWebview, App, Config, CustomMenuItem, Manager, Menu, Submenu, SystemTray,
|
App, Config, CustomMenuItem, Menu, Submenu, Window, WindowBuilder, WindowMenuEvent, WindowUrl,
|
||||||
SystemTrayEvent, SystemTrayMenu, Window, WindowBuilder, WindowMenuEvent, WindowUrl,
|
|
||||||
};
|
};
|
||||||
|
use tauri_utils::TitleBarStyle;
|
||||||
|
|
||||||
mod pake;
|
mod pake;
|
||||||
use pake::PakeConfig;
|
use pake::PakeConfig;
|
||||||
|
|
||||||
@@ -41,98 +38,15 @@ pub fn get_menu() -> Menu {
|
|||||||
.add_item(close)
|
.add_item(close)
|
||||||
.add_item(quit);
|
.add_item(quit);
|
||||||
let first_menu = Submenu::new("File", first_menu);
|
let first_menu = Submenu::new("File", first_menu);
|
||||||
// Hot Key
|
|
||||||
// let top = CustomMenuItem::new("top", "Top (↑)");
|
|
||||||
// let buttom = CustomMenuItem::new("buttom", "Bottom (↓)");
|
|
||||||
// let previous = CustomMenuItem::new("previous", "Previous (←)");
|
|
||||||
// let next = CustomMenuItem::new("next", "next (→)");
|
|
||||||
// let refresh = CustomMenuItem::new("refresh", "Refresh");
|
|
||||||
// let zoom_out = CustomMenuItem::new("zoom_out", "Zoom Out (125%)");
|
|
||||||
// let zoom_in = CustomMenuItem::new("zoom_in", "Zoom In (75%)");
|
|
||||||
// let zoom_reset = CustomMenuItem::new("reset", "Zoom Reset");
|
|
||||||
// let hot_key = Menu::new()
|
|
||||||
// .add_item(top)
|
|
||||||
// .add_item(buttom)
|
|
||||||
// .add_item(previous)
|
|
||||||
// .add_item(next)
|
|
||||||
// .add_item(refresh)
|
|
||||||
// .add_item(zoom_in)
|
|
||||||
// .add_item(zoom_out)
|
|
||||||
// .add_item(zoom_reset);
|
|
||||||
// let hot_key_menu = Submenu::new("Hot Key", hot_key);
|
|
||||||
|
|
||||||
// Help
|
|
||||||
// let instructions = CustomMenuItem::new("instruction", "Instruction");
|
|
||||||
// let about = CustomMenuItem::new("about", "About");
|
|
||||||
// let help = Menu::new()
|
|
||||||
// .add_item(instructions)
|
|
||||||
// .add_item(about);
|
|
||||||
// let help_menu = Submenu::new("Help", help);
|
|
||||||
Menu::new().add_submenu(first_menu)
|
Menu::new().add_submenu(first_menu)
|
||||||
// .add_submenu(hot_key_menu)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn set_zoom(webview: PlatformWebview, zoom_value: f64) {
|
|
||||||
// #[cfg(target_os = "linux")]
|
|
||||||
// {
|
|
||||||
// // see https://docs.rs/webkit2gtk/0.18.2/webkit2gtk/struct.WebView.html
|
|
||||||
// // and https://docs.rs/webkit2gtk/0.18.2/webkit2gtk/trait.WebViewExt.html
|
|
||||||
// use webkit2gtk::traits::WebViewExt;
|
|
||||||
// webview.inner().set_zoom_level(zoom_value);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[cfg(windows)]
|
|
||||||
// unsafe {
|
|
||||||
// // see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html
|
|
||||||
// webview.controller().SetZoomFactor(zoom_value).unwrap();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[cfg(target_os = "macos")]
|
|
||||||
// unsafe {
|
|
||||||
// let () = msg_send![webview.inner(), setPageZoom: zoom_value];
|
|
||||||
// let () = msg_send![webview.controller(), removeAllUserScripts];
|
|
||||||
// let bg_color: cocoa::base::id =
|
|
||||||
// msg_send![class!(NSColor), colorWithDeviceRed:0.5 green:0.2 blue:0.4 alpha:1.];
|
|
||||||
// let () = msg_send![webview.ns_window(), setBackgroundColor: bg_color];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn set_zoom_out(webview: PlatformWebview) {
|
|
||||||
// set_zoom(webview, 1.25);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn set_zoom_in(webview: PlatformWebview) {
|
|
||||||
// set_zoom(webview, 0.75);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn zoom_reset(webview: PlatformWebview) {
|
|
||||||
// set_zoom(webview, 1.0);
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub fn menu_event_handle(event: WindowMenuEvent) {
|
pub fn menu_event_handle(event: WindowMenuEvent) {
|
||||||
match event.menu_item_id() {
|
match event.menu_item_id() {
|
||||||
"hide" => event.window().hide().expect("can't hide window"),
|
"hide" => event.window().hide().expect("can't hide window"),
|
||||||
"show" => event.window().show().expect("can't show window"),
|
"show" => event.window().show().expect("can't show window"),
|
||||||
"close" => event.window().close().expect("can't close window"),
|
"close" => event.window().close().expect("can't close window"),
|
||||||
"quit" => std::process::exit(0),
|
"quit" => std::process::exit(0),
|
||||||
// "zoom_out" => {
|
|
||||||
// event
|
|
||||||
// .window()
|
|
||||||
// .with_webview(set_zoom_out)
|
|
||||||
// .expect("can't set zoom out");
|
|
||||||
// }
|
|
||||||
// "zoom_in" => {
|
|
||||||
// event
|
|
||||||
// .window()
|
|
||||||
// .with_webview(set_zoom_in)
|
|
||||||
// .expect("can't set zoom in");
|
|
||||||
// }
|
|
||||||
// "reset" => {
|
|
||||||
// event
|
|
||||||
// .window()
|
|
||||||
// .with_webview(zoom_reset)
|
|
||||||
// .expect("can't reset zoom");
|
|
||||||
// }
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,9 +165,12 @@ pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: std::path::PathB
|
|||||||
.user_agent(user_agent.macos.as_str())
|
.user_agent(user_agent.macos.as_str())
|
||||||
.resizable(window_config.resizable)
|
.resizable(window_config.resizable)
|
||||||
.fullscreen(window_config.fullscreen)
|
.fullscreen(window_config.fullscreen)
|
||||||
// .transparent(window_config.transparent)
|
|
||||||
//用于隐藏头部
|
//用于隐藏头部
|
||||||
// .title_bar_style(tauri_utils::TitleBarStyle::Overlay)
|
.title_bar_style(if window_config.transparent {
|
||||||
|
TitleBarStyle::Overlay
|
||||||
|
} else {
|
||||||
|
TitleBarStyle::Visible
|
||||||
|
})
|
||||||
.inner_size(window_config.width, window_config.height)
|
.inner_size(window_config.width, window_config.height)
|
||||||
.initialization_script(include_str!("pake.js"));
|
.initialization_script(include_str!("pake.js"));
|
||||||
|
|
||||||
|
|||||||
73
src-tauri/src/pake.js
vendored
73
src-tauri/src/pake.js
vendored
@@ -1,22 +1,13 @@
|
|||||||
/**
|
|
||||||
* @typedef {string} KeyboardKey `event.key` 的代号,
|
|
||||||
* 见 <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values>
|
|
||||||
* @typedef {() => void} OnKeyDown 使用者按下 [CtrlKey] 或者 ⌘ [KeyboardKey]时应该执行的行为
|
|
||||||
* 以 Ctrl键或者Meta 键 (⌘) 为首的快捷键清单。
|
|
||||||
* 每个写在这里的 shortcuts 都会运行 {@link Event.preventDefault}.
|
|
||||||
* @type {Record<KeyboardKey, OnKeyDown>}
|
|
||||||
*/
|
|
||||||
|
|
||||||
const metaKeyShortcuts = {
|
const metaKeyShortcuts = {
|
||||||
ArrowUp: () => scrollTo(0, 0),
|
ArrowUp: () => scrollTo(0, 0),
|
||||||
ArrowDown: () => scrollTo(0, document.body.scrollHeight),
|
ArrowDown: () => scrollTo(0, document.body.scrollHeight),
|
||||||
"[": () => window.history.back(),
|
'[': () => window.history.back(),
|
||||||
"]": () => window.history.forward(),
|
']': () => window.history.forward(),
|
||||||
r: () => window.location.reload(),
|
r: () => window.location.reload(),
|
||||||
"-": () => zoomOut(),
|
'-': () => zoomOut(),
|
||||||
"=": () => zoomIn(),
|
'=': () => zoomIn(),
|
||||||
"+": () => zoomIn(),
|
'+': () => zoomIn(),
|
||||||
0: () => zoomCommon(() => "100%"),
|
0: () => zoomCommon(() => '100%'),
|
||||||
};
|
};
|
||||||
|
|
||||||
const ctrlKeyShortcuts = {
|
const ctrlKeyShortcuts = {
|
||||||
@@ -25,14 +16,14 @@ const ctrlKeyShortcuts = {
|
|||||||
ArrowLeft: () => window.history.back(),
|
ArrowLeft: () => window.history.back(),
|
||||||
ArrowRight: () => window.history.forward(),
|
ArrowRight: () => window.history.forward(),
|
||||||
r: () => window.location.reload(),
|
r: () => window.location.reload(),
|
||||||
"-": () => zoomOut(),
|
'-': () => zoomOut(),
|
||||||
"=": () => zoomIn(),
|
'=': () => zoomIn(),
|
||||||
"+": () => zoomIn(),
|
'+': () => zoomIn(),
|
||||||
0: () => zoomCommon(() => "100%"),
|
0: () => zoomCommon(() => '100%'),
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", (_event) => {
|
window.addEventListener('DOMContentLoaded', (_event) => {
|
||||||
const style = document.createElement("style");
|
const style = document.createElement('style');
|
||||||
style.innerHTML = `
|
style.innerHTML = `
|
||||||
#page #footer-wrapper,
|
#page #footer-wrapper,
|
||||||
.drawing-board .toolbar .toolbar-action,
|
.drawing-board .toolbar .toolbar-action,
|
||||||
@@ -276,27 +267,27 @@ window.addEventListener("DOMContentLoaded", (_event) => {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
document.head.append(style);
|
document.head.append(style);
|
||||||
const topDom = document.createElement("div");
|
const topDom = document.createElement('div');
|
||||||
topDom.id = "pack-top-dom";
|
topDom.id = 'pack-top-dom';
|
||||||
document.body.appendChild(topDom);
|
document.body.appendChild(topDom);
|
||||||
|
|
||||||
const domEl = document.getElementById("pack-top-dom");
|
const domEl = document.getElementById('pack-top-dom');
|
||||||
|
|
||||||
domEl.addEventListener("mousedown", (e) => {
|
domEl.addEventListener('mousedown', (e) => {
|
||||||
if (e.buttons === 1 && e.detail !== 2) {
|
if (e.buttons === 1 && e.detail !== 2) {
|
||||||
window.ipc.postMessage("drag_window");
|
window.ipc.postMessage('drag_window');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
domEl.addEventListener("touchstart", () => {
|
domEl.addEventListener('touchstart', () => {
|
||||||
window.ipc.postMessage("drag_window");
|
window.ipc.postMessage('drag_window');
|
||||||
});
|
});
|
||||||
|
|
||||||
domEl.addEventListener("dblclick", () => {
|
domEl.addEventListener('dblclick', () => {
|
||||||
window.ipc.postMessage("fullscreen");
|
window.ipc.postMessage('fullscreen');
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("keyup", function (event) {
|
document.addEventListener('keyup', function (event) {
|
||||||
const preventDefault = (f) => {
|
const preventDefault = (f) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
f();
|
f();
|
||||||
@@ -313,12 +304,12 @@ window.addEventListener("DOMContentLoaded", (_event) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener("click", (e) => {
|
document.addEventListener('click', (e) => {
|
||||||
const origin = e.target.closest("a");
|
const origin = e.target.closest('a');
|
||||||
if (origin && origin.href) {
|
if (origin && origin.href) {
|
||||||
const target = origin.target
|
const target = origin.target;
|
||||||
origin.target = "_self";
|
origin.target = '_self';
|
||||||
const hrefUrl = new URL(origin.href)
|
const hrefUrl = new URL(origin.href);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
window.location.host !== hrefUrl.host && // 如果 a 标签内链接的域名和当前页面的域名不一致 且
|
window.location.host !== hrefUrl.host && // 如果 a 标签内链接的域名和当前页面的域名不一致 且
|
||||||
@@ -334,9 +325,9 @@ window.addEventListener("DOMContentLoaded", (_event) => {
|
|||||||
setDefaultZoom();
|
setDefaultZoom();
|
||||||
|
|
||||||
function setDefaultZoom() {
|
function setDefaultZoom() {
|
||||||
const htmlZoom = window.localStorage.getItem("htmlZoom");
|
const htmlZoom = window.localStorage.getItem('htmlZoom');
|
||||||
if (htmlZoom) {
|
if (htmlZoom) {
|
||||||
document.getElementsByTagName("html")[0].style.zoom = htmlZoom;
|
document.getElementsByTagName('html')[0].style.zoom = htmlZoom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,11 +335,11 @@ function setDefaultZoom() {
|
|||||||
* @param {(htmlZoom: string) => string} [zoomRule]
|
* @param {(htmlZoom: string) => string} [zoomRule]
|
||||||
*/
|
*/
|
||||||
function zoomCommon(zoomRule) {
|
function zoomCommon(zoomRule) {
|
||||||
const htmlZoom = window.localStorage.getItem("htmlZoom") || "100%";
|
const htmlZoom = window.localStorage.getItem('htmlZoom') || '100%';
|
||||||
const html = document.getElementsByTagName("html")[0];
|
const html = document.getElementsByTagName('html')[0];
|
||||||
const zoom = zoomRule(htmlZoom);
|
const zoom = zoomRule(htmlZoom);
|
||||||
html.style.zoom = zoom;
|
html.style.zoom = zoom;
|
||||||
window.localStorage.setItem("htmlZoom", zoom);
|
window.localStorage.setItem('htmlZoom', zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
function zoomIn() {
|
function zoomIn() {
|
||||||
|
|||||||
Reference in New Issue
Block a user