diff --git a/README.md b/README.md index c272470..875b44b 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,19 @@ 更多常用 App 下载可以去 [Releases](https://github.com/tw93/Pake/releases) 中看看。 -## 快捷键 +## 快捷键(Windows/Linux) +1. Ctrl + :返回上一个页面 +2. Ctrl + :去下一个页面 +3. Ctrl + :自动滚动到页面顶部 +4. Ctrl + :自动滚动到页面底部 +5. Ctrl + r:刷新页面 +6. Ctrl + -:缩小页面 +7. Ctrl + +:放大页面 +8. Ctrl + =:放大页面 +9. Ctrl + 0:重置页面缩放 + +## 快捷键(Mac) 1. + [:返回上一个页面 2. + ]:去下一个页面 3. + :自动滚动到页面顶部 diff --git a/README_EN.md b/README_EN.md index 0990d3c..99efdfe 100644 --- a/README_EN.md +++ b/README_EN.md @@ -63,7 +63,20 @@ More common apps can be downloaded from [Releases](https://github.com/tw93/Pake/releases). -## Shortcuts + +## Shortcuts(Windows/Linux) + +1. Ctrl + :Return to the previous page +2. Ctrl + :Go to the next page +3. Ctrl + :Auto scroll to top of page +4. Ctrl + :Auto scroll to bottom of page +5. Ctrl + r:Refresh Page +6. Ctrl + -:Zoom out the page +7. Ctrl + +:Zoom in the Page +8. Ctrl + =:Zoom in the Page +9. Ctrl + 0:Reset the page zoom + +## Shortcuts(Mac) 1. + [:Return to the previous page 2. + ]:Go to the next page diff --git a/package.json b/package.json index d8c176e..e846685 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "dev:debug": "npm run tauri dev -- --features devtools", "build": "npm run tauri build -- --target universal-apple-darwin", "build:windows": "npm run tauri build -- --target x86_64-pc-windows-msvc", + "build:linux": "npm run tauri build --release", "tauri": "tauri" }, "license": "MIT", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index c29bb4a..7e124cc 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -57,6 +57,7 @@ checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" name = "app" version = "0.1.0" dependencies = [ + "image", "serde", "serde_json", "tauri", @@ -118,6 +119,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "bit_field" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" + [[package]] name = "bitflags" version = "1.3.2" @@ -395,6 +402,30 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + [[package]] name = "crossbeam-utils" version = "0.8.10" @@ -405,6 +436,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.3" @@ -514,15 +551,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "deflate" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f" -dependencies = [ - "adler32", -] - [[package]] name = "derive_more" version = "0.99.17" @@ -594,6 +622,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c" +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + [[package]] name = "embed_plist" version = "1.2.2" @@ -609,6 +643,21 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "exr" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb5f255b5980bb0c8cf676b675d1a99be40f316881444f44e0462eaf5df5ded" +dependencies = [ + "bit_field", + "flume", + "half", + "lebe", + "miniz_oxide 0.6.2", + "smallvec", + "threadpool", +] + [[package]] name = "fastrand" version = "1.7.0" @@ -647,7 +696,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" dependencies = [ "crc32fast", - "miniz_oxide", + "miniz_oxide 0.5.3", +] + +[[package]] +name = "flume" +version = "0.10.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +dependencies = [ + "futures-core", + "futures-sink", + "nanorand", + "pin-project", + "spin", ] [[package]] @@ -734,6 +796,12 @@ dependencies = [ "syn", ] +[[package]] +name = "futures-sink" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" + [[package]] name = "futures-task" version = "0.3.21" @@ -876,8 +944,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "gif" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" +dependencies = [ + "color_quant", + "weezl", ] [[package]] @@ -1040,6 +1120,15 @@ dependencies = [ "syn", ] +[[package]] +name = "half" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad6a9459c9c30b177b925162351f97e7d967c7ea8bab3b8352805327daf45554" +dependencies = [ + "crunchy", +] + [[package]] name = "hashbrown" version = "0.12.1" @@ -1148,16 +1237,21 @@ dependencies = [ [[package]] name = "image" -version = "0.24.2" +version = "0.24.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28edd9d7bc256be2502e325ac0628bde30b7001b9b52e0abe31a1a9dc2701212" +checksum = "69b7ea949b537b0fd0af141fff8c77690f2ce96f4f41f042ccb6c69c6c965945" dependencies = [ "bytemuck", "byteorder", "color_quant", - "num-iter", + "exr", + "gif", + "jpeg-decoder", "num-rational", "num-traits", + "png 0.17.7", + "scoped_threadpool", + "tiff", ] [[package]] @@ -1266,6 +1360,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" +[[package]] +name = "jpeg-decoder" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" +dependencies = [ + "rayon", +] + [[package]] name = "js-sys" version = "0.3.58" @@ -1304,6 +1407,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lebe" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" + [[package]] name = "libc" version = "0.2.126" @@ -1443,6 +1552,24 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + +[[package]] +name = "nanorand" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" +dependencies = [ + "getrandom 0.2.7", +] + [[package]] name = "native-tls" version = "0.2.10" @@ -1887,6 +2014,26 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1926,21 +2073,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0b0cabbbd20c2d7f06dbf015e06aad59b6ca3d9ed14848783e98af9aaf19925" dependencies = [ "bitflags", - "deflate 0.7.20", + "deflate", "inflate", "num-iter", ] [[package]] name = "png" -version = "0.17.5" +version = "0.17.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc38c0ad57efb786dd57b9864e5b18bae478c00c824dc55a38bbc9da95dde3ba" +checksum = "5d708eaf860a19b19ce538740d2b4bdeeb8337fa53f7738455e706623ad5c638" dependencies = [ "bitflags", "crc32fast", - "deflate 1.0.0", - "miniz_oxide", + "flate2", + "miniz_oxide 0.6.2", ] [[package]] @@ -2103,6 +2250,30 @@ dependencies = [ "cty", ] +[[package]] +name = "rayon" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "redox_syscall" version = "0.2.13" @@ -2243,6 +2414,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" + [[package]] name = "scopeguard" version = "1.1.0" @@ -2503,6 +2680,15 @@ dependencies = [ "system-deps 5.0.0", ] +[[package]] +name = "spin" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +dependencies = [ + "lock_api", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -2643,7 +2829,7 @@ dependencies = [ "once_cell", "parking_lot", "paste", - "png 0.17.5", + "png 0.17.7", "raw-window-handle", "scopeguard", "serde", @@ -2689,7 +2875,7 @@ dependencies = [ "once_cell", "parking_lot", "paste", - "png 0.17.5", + "png 0.17.7", "raw-window-handle", "scopeguard", "serde", @@ -2791,7 +2977,7 @@ dependencies = [ "ico", "json-patch", "plist", - "png 0.17.5", + "png 0.17.7", "proc-macro2", "quote", "regex", @@ -2948,6 +3134,26 @@ dependencies = [ "once_cell", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "tiff" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17def29300a156c19ae30814710d9c63cd50288a49c6fd3a10ccfbe4cf886fd" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + [[package]] name = "time" version = "0.3.11" @@ -3369,6 +3575,12 @@ dependencies = [ "windows-metadata", ] +[[package]] +name = "weezl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + [[package]] name = "widestring" version = "1.0.2" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 01ae264..74c3d4e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -12,14 +12,16 @@ rust-version = "1.61.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] -tauri-build = { version = "1.1.1", features = [] } +tauri-build = { version = "1.2.0", features = [] } + [dependencies] serde_json = "1.0.86" serde = { version = "1.0.145", features = ["derive"] } -tauri = { version = "1.1.1", features = ["api-all"] } +tauri = { version = "1.2.0", features = ["api-all"] } +image = "0.24.5" wry = "0.21.1" -tauri-utils = "1.1.1" +tauri-utils = "1.2.0" webbrowser = "0.8.2" [features] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 4f54c31..1876aeb 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,22 +1,23 @@ +// at the top of main.rs - that will prevent the console from showing +#![windows_subsystem = "windows"] +extern crate image; use tauri_utils::config::{Config, WindowConfig}; -#[cfg(target_os = "macos")] -use wry::application::platform::macos::WindowBuilderExtMacOS; -#[cfg(target_os = "windows")] -use wry::application::platform::windows::WindowBuilderExtWindows; + +use wry::{ + application::{ + accelerator::{Accelerator, SysMods}, + event::{Event, StartCause, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + keyboard::KeyCode, + menu::{MenuBar as Menu, MenuItem, MenuItemAttributes, MenuType}, + window::{Fullscreen, Window, WindowBuilder, Icon}, + }, + webview::WebViewBuilder, +}; + fn main() -> wry::Result<()> { - use wry::{ - application::{ - accelerator::{Accelerator, SysMods}, - event::{Event, StartCause, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, - keyboard::KeyCode, - menu::{MenuBar as Menu, MenuItem, MenuItemAttributes, MenuType}, - window::{Fullscreen, Window, WindowBuilder}, - }, - webview::WebViewBuilder, - }; - + let mut menu_bar_menu = Menu::new(); let mut first_menu = Menu::new(); @@ -44,7 +45,6 @@ fn main() -> wry::Result<()> { width, height, resizable, - transparent, fullscreen, .. } = get_windows_config().unwrap_or(WindowConfig::default()); @@ -58,13 +58,23 @@ fn main() -> wry::Result<()> { None }) .with_inner_size(wry::application::dpi::LogicalSize::new(width, height)); + let icon_path = concat!(env!("CARGO_MANIFEST_DIR"), "/icons/icon.ico"); + let icon = load_icon(std::path::Path::new(icon_path)); + #[cfg(target_os = "windows")] let window = common_window - .with_decorations(false) + .with_decorations(true) .with_title("") + .with_window_icon(Some(icon)) .build(&event_loop) .unwrap(); + #[cfg(target_os = "linux")] + let window = common_window + .with_title("") + .build(&event_loop) + .with_menu(menu_bar_menu) + .unwrap(); #[cfg(target_os = "macos")] let window = common_window .with_fullsize_content_view(true) @@ -89,13 +99,29 @@ 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")) + .with_initialization_script(include_str!("pake.js")) + .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(); @@ -131,3 +157,17 @@ fn get_windows_config() -> Option { config.tauri.windows.iter().next().cloned() } + + +fn load_icon(path: &std::path::Path) -> Icon { + let (icon_rgba, icon_width, icon_height) = { + // alternatively, you can embed the icon in the binary through `include_bytes!` macro and use `image::load_from_memory` + let image = image::open(path) + .expect("Failed to open icon path") + .into_rgba8(); + let (width, height) = image.dimensions(); + let rgba = image.into_raw(); + (rgba, width, height) + }; + Icon::from_rgba(icon_rgba, icon_width, icon_height).expect("Failed to open icon") + } diff --git a/src-tauri/src/pake-mac.js b/src-tauri/src/pake-mac.js new file mode 100644 index 0000000..51cb51e --- /dev/null +++ b/src-tauri/src/pake-mac.js @@ -0,0 +1,175 @@ +/** + * @typedef {string} KeyboardKey `event.key` 的代号, + * 见 + * @typedef {() => void} OnKeyDown 使用者按下 ⌘ [KeyboardKey] 时应该执行的行为 + * 以 Meta 键 (⌘) 为首的快捷键清单。 + * 每个写在这里的 shortcuts 都会运行 {@link Event.preventDefault}. + * @type {Record} + */ + const metaKeyShortcuts = { + 'ArrowUp': () => scrollTo(0, 0), + 'ArrowDown': () => scrollTo(0, document.body.scrollHeight), + '[': () => window.history.back(), + ']': () => window.history.forward(), + 'r': () => window.location.reload(), + '-': () => zoomOut(), + '=': () => zoomIn(), + '0': () => zoomCommon(() => '100%'), +} + +window.addEventListener('DOMContentLoaded', (_event) => { + const style = document.createElement('style'); + style.innerHTML = ` + #page #footer-wrapper, + .drawing-board .toolbar .toolbar-action, + .c-swiper-container, + .download_entry, + .lang, .copyright, + .wwads-cn, .adsbygoogle, + #Bottom > div.content > div.inner, + #Rightbar .sep20:nth-of-type(5), + #Rightbar > div.box:nth-child(4), + #Main > div.box:nth-child(8) > div + #Wrapper > div.sep20, + #Main > div.box:nth-child(8), + #masthead-ad, + #Rightbar > div:nth-child(6) > div.sidebar_compliance { + display: none !important; + } + + #page .main_header { + padding-top: 20px; + } + + .panel.give_me .nav_view { + top: 154px !important; + } + + .columns .column #header{ + padding-top: 30px; + } + + ytd-masthead>#container.style-scope.ytd-masthead { + padding-top: 12px !important; + } + + .wrap.h1body-exist.max-container > div.menu-tocs > div.menu-btn{ + top: 28px; + } + + #Wrapper{ + background-color: #F8F8F8 !important; + background-image:none !important; + } + + #Top { + border-bottom: none; + } + + .container-with-note #home, .container-with-note #switcher{ + top: 30px; + } + + .geist-page nav.dashboard_nav__PRmJv { + padding-top:10px; + } + + .geist-page .submenu button{ + margin-top:24px; + } + + #pack-top-dom:active { + cursor: grabbing; + cursor: -webkit-grabbing; + } + + #pack-top-dom{ + position:fixed; + background:transparent; + top:0; + width: 100%; + height: 20px; + cursor: grab; + cursor: -webkit-grab; + z-index: 90000; + } + `; + document.head.append(style); + const topDom = document.createElement('div'); + topDom.id = 'pack-top-dom'; + document.body.appendChild(topDom); + + const domEl = document.getElementById('pack-top-dom'); + + domEl.addEventListener('mousedown', (e) => { + if (e.buttons === 1 && e.detail !== 2) { + window.ipc.postMessage('drag_window'); + } + }); + + domEl.addEventListener('touchstart', () => { + window.ipc.postMessage('drag_window'); + }); + + domEl.addEventListener('dblclick', () => { + window.ipc.postMessage('fullscreen'); + }); + + document.addEventListener('keyup', function (event) { + const preventDefault = (f) => { + event.preventDefault(); + f(); + }; + + if (event.metaKey && event.key in metaKeyShortcuts) { + preventDefault(metaKeyShortcuts[event.key]); + } + }); + + document.addEventListener('click', (e) => { + const origin = e.target.closest('a'); + if (origin && origin.href) { + origin.target = '_self'; + + //额外处理下 twitter 的外跳,对于其他需要外跳的可以改这里成对应域名 + const href = origin.href; + if(location.host === "twitter.com" && href.indexOf("twitter.com")===-1){ + e.preventDefault(); + window.ipc.postMessage(`open_browser:${href}`); + } + } + }); +}); + +setDefaultZoom(); + +function setDefaultZoom() { + const htmlZoom = window.localStorage.getItem('htmlZoom'); + if (htmlZoom) { + document.getElementsByTagName('html')[0].style.zoom = htmlZoom; + } +} + +/** + * @param {(htmlZoom: string) => string} [zoomRule] + */ +function zoomCommon(zoomRule) { + const htmlZoom = window.localStorage.getItem('htmlZoom') || '100%'; + const html = document.getElementsByTagName('html')[0]; + const zoom = zoomRule(htmlZoom); + html.style.zoom = zoom; + window.localStorage.setItem('htmlZoom', zoom); +} + +function zoomIn() { + zoomCommon((htmlZoom) => + `${Math.min(parseInt(htmlZoom) + 10, 200)}%` + ); +} + +function zoomOut() { + zoomCommon((htmlZoom) => + `${Math.max(parseInt(htmlZoom) - 10, 30)}%` + ); +} + diff --git a/src-tauri/src/pake.js b/src-tauri/src/pake.js index 5c0adcc..8f03af6 100644 --- a/src-tauri/src/pake.js +++ b/src-tauri/src/pake.js @@ -1,19 +1,20 @@ /** * @typedef {string} KeyboardKey `event.key` 的代号, * 见 - * @typedef {() => void} OnKeyDown 使用者按下 ⌘ [KeyboardKey] 时应该执行的行为 - * 以 Meta 键 (⌘) 为首的快捷键清单。 + * @typedef {() => void} OnKeyDown 使用者按下 [CtrlKey] 时应该执行的行为 + * 以 Ctrl 键 为首的快捷键清单。 * 每个写在这里的 shortcuts 都会运行 {@link Event.preventDefault}. * @type {Record} */ -const metaKeyShortcuts = { +const ctrlKeyShortcuts = { 'ArrowUp': () => scrollTo(0, 0), 'ArrowDown': () => scrollTo(0, document.body.scrollHeight), - '[': () => window.history.back(), - ']': () => window.history.forward(), + 'ArrowLeft': () => window.history.back(), + 'ArrowRight': () => window.history.forward(), 'r': () => window.location.reload(), '-': () => zoomOut(), '=': () => zoomIn(), + '+': () => zoomIn(), '0': () => zoomCommon(() => '100%'), } @@ -121,8 +122,8 @@ window.addEventListener('DOMContentLoaded', (_event) => { f(); }; - if (event.metaKey && event.key in metaKeyShortcuts) { - preventDefault(metaKeyShortcuts[event.key]); + if (event.ctrlKey && event.key in ctrlKeyShortcuts) { + preventDefault(ctrlKeyShortcuts[event.key]); } }); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 0cb34c9..3b9754d 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -27,7 +27,16 @@ "category": "DeveloperTool", "copyright": "", "deb": { - "depends": [] + "depends": [ + "libwebkit2gtk-4.0-dev", + "build-essential", + "curl", + "wget", + "libssl-dev", + "libgtk-3-dev", + "libayatana-appindicator3-dev", + "librsvg2-dev" + ] }, "externalBin": [], "longDescription": "", @@ -44,7 +53,10 @@ "windows": { "certificateThumbprint": null, "digestAlgorithm": "sha256", - "timestampUrl": "" + "timestampUrl": "", + "wix": { + "language": ["en-US", "zh-CN"] + } } }, "security": {