diff --git a/bin/README.md b/bin/README.md index 68ecd5b..e7cd21e 100644 --- a/bin/README.md +++ b/bin/README.md @@ -2,7 +2,7 @@ ## Installation -Ensure that your Node.js version is 16.0 or higher (e.g., 16.8). Avoid using `sudo` for the installation. If you encounter permission issues with npm, refer to [How to fix npm throwing error without sudo](https://stackoverflow.com/questions/16151018/how-to-fix-npm-throwing-error-without-sudo). +Ensure that your Node.js version is 18.0 or higher (e.g., 18.20.2). Avoid using `sudo` for the installation. If you encounter permission issues with npm, refer to [How to fix npm throwing error without sudo](https://stackoverflow.com/questions/16151018/how-to-fix-npm-throwing-error-without-sudo). ```bash npm install pake-cli -g @@ -81,7 +81,7 @@ Various options are available for customization. You can pass corresponding argu Specify the application name. If not provided, you will be prompted to enter it. It is recommended to use English. ```shell ---name +--name ``` #### [icon] @@ -112,12 +112,12 @@ Set the width of the application window. Default is `1200px`. --width ``` -#### [transparent] +#### [hide-title-bar] Enable or disable immersive header. Default is `false`. Use the following command to enable this feature, macOS only. ```shell ---transparent +--hide-title-bar ``` #### [fullscreen] @@ -129,6 +129,15 @@ screen. --fullscreen ``` + +#### [activation-shortcut] + +Set the activation shortcut for the application. Default is ` `, it does not take effect, you can customize the activation shortcut with the following commands, e.g. `CmdOrControl+Shift+P`, use can refer to [available-modifiers](https://www.electronjs.org/docs/latest/api/accelerator#available-modifiers). + +```shell +--activation-shortcut +``` + #### [always-on-top] Sets whether the window is always at the top level, defaults to `false`. @@ -154,15 +163,15 @@ Package the application to support both Intel and M1 chips, exclusively for macO - Note: After enabling this option, Rust must be installed using rustup from the official Rust website. Installation via brew is not supported. - For Intel chip users, install the arm64 cross-platform package to support M1 chips using the following command: -```shell -rustup target add aarch64-apple-darwin -``` + ```shell + rustup target add aarch64-apple-darwin + ``` - For M1 chip users, install the x86 cross-platform package to support Intel chips using the following command: -```shell -rustup target add x86_64-apple-darwin -``` + ```shell + rustup target add x86_64-apple-darwin + ``` ##### Usage @@ -183,7 +192,7 @@ Select the output package format for Linux. Options include `deb`, `appimage`, o Customize the browser user agent. Default is empty. ```shell ---user-agent +--user-agent ``` #### [show-system-tray] diff --git a/bin/README_CN.md b/bin/README_CN.md index d5b9868..5a0dc08 100644 --- a/bin/README_CN.md +++ b/bin/README_CN.md @@ -2,7 +2,7 @@ ## 安装 -请确保您的 Node.js 版本为 16 或更高版本(例如 16.8)。请避免使用 `sudo` 进行安装。如果 npm 报告权限问题,请参考 [如何在不使用 sudo 的情况下修复 npm 报错](https://stackoverflow.com/questions/16151018/how-to-fix-npm-throwing-error-without-sudo)。 +请确保您的 Node.js 版本为 18 或更高版本(例如 18.7)。请避免使用 `sudo` 进行安装。如果 npm 报告权限问题,请参考 [如何在不使用 sudo 的情况下修复 npm 报错](https://stackoverflow.com/questions/16151018/how-to-fix-npm-throwing-error-without-sudo)。 ```bash npm install pake-cli -g @@ -79,10 +79,10 @@ pake [url] [options] #### [name] -指定应用程序的名称。如果在输入时未指定,系统会提示您输入。建议使用英文名称。 +指定应用程序的名称,如果在输入时未指定,系统会提示您输入,建议使用单个英文名称,不要出现下划线或者中文。 ```shell ---name +--name ``` #### [icon] @@ -114,12 +114,12 @@ pake [url] [options] --width ``` -#### [transparent] +#### [hide-title-bar] 设置是否启用沉浸式头部,默认为 `false`(不启用)。当前只对 macOS 上有效。 ```shell ---transparent +--hide-title-bar ``` #### [fullscreen] @@ -130,6 +130,14 @@ pake [url] [options] --fullscreen ``` +#### [activation-shortcut] + +设置应用程序的激活快捷键。默认为空,不生效,可以使用以下命令自定义激活快捷键,例如 `CmdOrControl+Shift+P`,使用可参考 [available-modifiers](https://www.electronjs.org/docs/latest/api/accelerator#available-modifiers)。 + +```shell +--activation-shortcut +``` + #### [always-on-top] 设置是否窗口一直在最顶层,默认为 `false`。 @@ -155,15 +163,15 @@ pake [url] [options] - 注意:启用此选项后,需要使用 rust 官网的 rustup 安装 rust,不支持通过 brew 安装。 - 对于 Intel 芯片用户,需要安装 arm64 跨平台包,以使安装包支持 M1 芯片。使用以下命令安装: -```shell -rustup target add aarch64-apple-darwin -``` + ```shell + rustup target add aarch64-apple-darwin + ``` - 对于 M1 芯片用户,需要安装 x86 跨平台包,以使安装包支持 Intel 芯片。使用以下命令安装: -```shell -rustup target add x86_64-apple-darwin -``` + ```shell + rustup target add x86_64-apple-darwin + ``` ##### 使用方法 @@ -177,7 +185,7 @@ rustup target add x86_64-apple-darwin Linux,默认为 `all`。 ```shell ---targets +--targets ``` #### [user-agent] @@ -185,7 +193,7 @@ Linux,默认为 `all`。 自定义浏览器的用户代理请求头,默认为空。 ```shell ---user-agent +--user-agent ``` #### [show-system-tray] diff --git a/bin/defaults.ts b/bin/defaults.ts index b75c4c7..445d5b1 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -9,6 +9,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { transparent: false, alwaysOnTop: false, disabledWebShortcuts: false, + activationShortcut: '', userAgent: '', showSystemTray: false, multiArch: false, diff --git a/bin/types.ts b/bin/types.ts index da11231..4b64210 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -30,6 +30,9 @@ export interface PakeCliOptions { // Disable web shortcuts, default false disabledWebShortcuts: boolean; + // Set a shortcut key to wake up the app, default empty + activationShortcut: string; + // Custom User-Agent, default off userAgent: string; diff --git a/src-tauri/pake.json b/src-tauri/pake.json index 06944b2..cb7b0e2 100644 --- a/src-tauri/pake.json +++ b/src-tauri/pake.json @@ -9,6 +9,7 @@ "height": 780, "resizable": true, "always_on_top": false, + "activation_shortcut": "", "disabled_web_shortcuts": false } ], diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rs index 4ce0ac3..e2ebb74 100644 --- a/src-tauri/src/app/config.rs +++ b/src-tauri/src/app/config.rs @@ -11,6 +11,7 @@ pub struct WindowConfig { pub url_type: String, pub always_on_top: bool, pub disabled_web_shortcuts: bool, + pub activation_shortcut: String, } #[derive(Debug, Serialize, Deserialize)] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 83426a6..0570dab 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -9,6 +9,7 @@ mod util; use app::{invoke, menu, window}; use invoke::{download_file, download_file_by_binary}; use menu::{get_system_tray, system_tray_handle}; +use tauri::{GlobalShortcutManager, Manager}; use tauri_plugin_window_state::Builder as windowStatePlugin; use util::{get_data_dir, get_pake_config}; use window::get_window; @@ -28,6 +29,9 @@ pub fn run_app() { .on_system_tray_event(system_tray_handle); } + // Save the value of toggle_app_shortcut before pake_config is moved + let activation_shortcut = pake_config.windows[0].activation_shortcut.clone(); + tauri_app .plugin(windowStatePlugin::default().build()) .plugin(tauri_plugin_oauth::init()) @@ -35,10 +39,28 @@ pub fn run_app() { download_file, download_file_by_binary ]) - .setup(|app| { + .setup(move |app| { let _window = get_window(app, pake_config, data_dir); // Prevent initial shaking _window.show().unwrap(); + + if !activation_shortcut.is_empty() { + let app_handle = app.app_handle().clone(); + app_handle + .global_shortcut_manager() + .register(activation_shortcut.as_str(), move || { + let window = app_handle.get_window("pake").unwrap(); + match window.is_visible().unwrap() { + true => window.hide().unwrap(), + false => { + window.show().unwrap(); + window.set_focus().unwrap(); + } + } + }) + .expect("Error registering global evoke shortcuts!"); + } + Ok(()) }) .on_window_event(|event| {