Support setting activationShortcut

This commit is contained in:
Tw93
2024-05-09 19:47:08 +08:00
parent 2e95f46498
commit bb3b1b3d59
7 changed files with 70 additions and 25 deletions

31
bin/README.md vendored
View File

@@ -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 <value>
--name <string>
```
#### [icon]
@@ -112,12 +112,12 @@ Set the width of the application window. Default is `1200px`.
--width <number>
```
#### [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 <string>
```
#### [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 <value>
--user-agent <string>
```
#### [show-system-tray]

34
bin/README_CN.md vendored
View File

@@ -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 <value>
--name <string>
```
#### [icon]
@@ -114,12 +114,12 @@ pake [url] [options]
--width <number>
```
#### [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 <string>
```
#### [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 <value>
--targets <string>
```
#### [user-agent]
@@ -185,7 +193,7 @@ Linux默认为 `all`。
自定义浏览器的用户代理请求头,默认为空。
```shell
--user-agent <value>
--user-agent <string>
```
#### [show-system-tray]

1
bin/defaults.ts vendored
View File

@@ -9,6 +9,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
transparent: false,
alwaysOnTop: false,
disabledWebShortcuts: false,
activationShortcut: '',
userAgent: '',
showSystemTray: false,
multiArch: false,

3
bin/types.ts vendored
View File

@@ -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;

View File

@@ -9,6 +9,7 @@
"height": 780,
"resizable": true,
"always_on_top": false,
"activation_shortcut": "",
"disabled_web_shortcuts": false
}
],

View File

@@ -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)]

View File

@@ -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| {