From d50b22356a222a388001031b88fc19315734c1b0 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Tue, 7 May 2024 20:45:00 +0800 Subject: [PATCH 01/12] :construction: Update Syntax --- src-tauri/src/app/menu.rs | 2 +- src-tauri/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rs index 47f191a..0d03dd6 100644 --- a/src-tauri/src/app/menu.rs +++ b/src-tauri/src/app/menu.rs @@ -1,4 +1,4 @@ -use tauri::{CustomMenuItem,Manager, SystemTray, SystemTrayEvent, SystemTrayMenu}; +use tauri::{CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu}; use tauri_plugin_window_state::{AppHandleExt, StateFlags}; pub fn get_system_tray() -> SystemTray { diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index aa9eb70..a061e6c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -6,7 +6,7 @@ windows_subsystem = "windows" mod app; mod util; -use app::{invoke, window, menu}; +use app::{invoke, menu, window}; use invoke::{download_file, download_file_by_binary}; use menu::{get_system_tray, system_tray_handle}; use tauri_plugin_window_state::Builder as windowStatePlugin; From f5319394f5dab61159d4f0d4b61dae8b38320f49 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Wed, 8 May 2024 17:15:50 +0800 Subject: [PATCH 02/12] :art: Just code formatting --- src-tauri/src/inject/event.js | 2 +- src-tauri/src/main.rs | 4 ++-- src-tauri/src/util.rs | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js index 31ae81f..8a05bb0 100644 --- a/src-tauri/src/inject/event.js +++ b/src-tauri/src/inject/event.js @@ -63,7 +63,7 @@ document.addEventListener('DOMContentLoaded', () => { const appWindow = tauri.window.appWindow; const invoke = tauri.tauri.invoke; - if(!document.getElementById('pake-top-dom')){ + if (!document.getElementById('pake-top-dom')) { const topDom = document.createElement('div'); topDom.id = 'pake-top-dom'; document.body.appendChild(topDom); diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index a061e6c..83426a6 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr( -all(not(debug_assertions), target_os = "windows"), -windows_subsystem = "windows" + all(not(debug_assertions), target_os = "windows"), + windows_subsystem = "windows" )] mod app; diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rs index 4b82e87..ec8242f 100644 --- a/src-tauri/src/util.rs +++ b/src-tauri/src/util.rs @@ -7,12 +7,15 @@ pub fn get_pake_config() -> (PakeConfig, Config) { #[cfg(feature = "cli-build")] let pake_config: PakeConfig = serde_json::from_str(include_str!("../.pake/pake.json")) .expect("Failed to parse pake config"); + #[cfg(not(feature = "cli-build"))] let pake_config: PakeConfig = serde_json::from_str(include_str!("../pake.json")).expect("Failed to parse pake config"); + #[cfg(feature = "cli-build")] let tauri_config: Config = serde_json::from_str(include_str!("../.pake/tauri.conf.json")) .expect("Failed to parse tauri config"); + #[cfg(not(feature = "cli-build"))] let tauri_config: Config = serde_json::from_str(include_str!("../tauri.conf.json")) .expect("Failed to parse tauri config"); From a1e34a00e60b5a0136bc8e464616c2bc6d9dc061 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Wed, 8 May 2024 17:59:38 +0800 Subject: [PATCH 03/12] :sparkles: Add alwaysOnTop feature --- bin/README.md | 7 +++++++ bin/README_CN.md | 10 ++++++++++ bin/defaults.ts | 1 + bin/helpers/merge.ts | 2 ++ bin/types.ts | 3 +++ src-tauri/pake.json | 3 ++- src-tauri/src/app/config.rs | 1 + src-tauri/src/app/window.rs | 1 + 8 files changed, 27 insertions(+), 1 deletion(-) diff --git a/bin/README.md b/bin/README.md index e0131b7..deace75 100644 --- a/bin/README.md +++ b/bin/README.md @@ -121,6 +121,13 @@ Enable or disable immersive header. Default is `false`. Use the following comman --transparent ``` +#### [always-on-top] +Enable the always-on-top feature. Default is `false`. + +```shell +--always-on-top +``` + #### [fullscreen] Determine whether the application launches in full screen. Default is `false`. Use the following command to enable full screen. diff --git a/bin/README_CN.md b/bin/README_CN.md index f23ef78..981a255 100644 --- a/bin/README_CN.md +++ b/bin/README_CN.md @@ -122,6 +122,16 @@ pake [url] [options] --transparent ``` +#### [always-on-top] +设置是否窗口一直在最顶层,默认为 `false`。 + +```shell +--always-on-top +``` + + +```shell + #### [fullscreen] 设置应用程序是否在启动时自动全屏,默认为 `false`。使用以下命令可以设置应用程序启动时自动全屏。 diff --git a/bin/defaults.ts b/bin/defaults.ts index 8403d89..cfaff8b 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -7,6 +7,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { fullscreen: false, resizable: true, transparent: false, + alwaysOnTop: false, userAgent: '', showSystemTray: false, multiArch: false, diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts index 6883dea..9d306e6 100644 --- a/bin/helpers/merge.ts +++ b/bin/helpers/merge.ts @@ -13,6 +13,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon height, fullscreen, transparent, + alwaysOnTop, userAgent, showSystemTray, systemTrayIcon, @@ -32,6 +33,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon height, fullscreen, transparent, + alwaysOnTop, resizable, }; Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); diff --git a/bin/types.ts b/bin/types.ts index 74e2b58..f555ed4 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -24,6 +24,9 @@ export interface PakeCliOptions { // Enable immersive header, default false transparent: boolean; + // Enable windows always on top, default false + alwaysOnTop: boolean; + // Custom User-Agent, default off userAgent: string; diff --git a/src-tauri/pake.json b/src-tauri/pake.json index 9d36efe..49e85bb 100644 --- a/src-tauri/pake.json +++ b/src-tauri/pake.json @@ -7,7 +7,8 @@ "width": 1200, "height": 780, "resizable": true, - "url_type": "web" + "url_type": "web", + "always_on_top": false } ], "user_agent": { diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rs index 1460ca8..0610b72 100644 --- a/src-tauri/src/app/config.rs +++ b/src-tauri/src/app/config.rs @@ -9,6 +9,7 @@ pub struct WindowConfig { pub height: f64, pub resizable: bool, pub url_type: String, + pub always_on_top: bool, } #[derive(Debug, Deserialize)] diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index 64c5db9..fde4f5a 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -27,6 +27,7 @@ pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> Wind .fullscreen(window_config.fullscreen) .inner_size(window_config.width, window_config.height) .disable_file_drop_handler() + .always_on_top(window_config.always_on_top) .initialization_script(include_str!("../inject/component.js")) .initialization_script(include_str!("../inject/event.js")) .initialization_script(include_str!("../inject/style.js")) From 5f678ebd102156e54091cb995f0617a1e1e64e71 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 9 May 2024 15:29:58 +0800 Subject: [PATCH 04/12] :sparkles: Adding new commands and hiding less frequently used commands --- bin/cli.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/cli.ts b/bin/cli.ts index 6c87d59..e94cd0c 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -1,5 +1,5 @@ import chalk from 'chalk'; -import { program } from 'commander'; +import { program, Option } from 'commander'; import log from 'loglevel'; import packageJson from '../package.json'; import BuilderProvider from './builders/BuilderProvider'; @@ -10,7 +10,7 @@ import handleInputOptions from './options/index'; import { PakeCliOptions } from './types'; import { validateNumberInput, validateUrlInput } from './utils/validate'; -const { green, yellow }= chalk; +const { green, yellow } = chalk; const logo = `${chalk.green(' ____ _')} ${green('| _ \\ __ _| | _____')} ${green('| |_) / _` | |/ / _ \\')} @@ -31,15 +31,17 @@ program .option('--height ', 'Window height', validateNumberInput, DEFAULT.height) .option('--transparent', 'Only for Mac, hide title bar', DEFAULT.transparent) .option('--fullscreen', 'Start in full screen', DEFAULT.fullscreen) - .option('--user-agent ', 'Custom user agent', DEFAULT.userAgent) .option('--show-system-tray', 'Show system tray in app', DEFAULT.showSystemTray) .option('--system-tray-icon ', 'Custom system tray icon', DEFAULT.systemTrayIcon) .option('--iter-copy-file', 'Copy files when URL is a local file', DEFAULT.iterCopyFile) .option('--multi-arch', 'Only for Mac, supports both Intel and M1', DEFAULT.multiArch) - .option('--targets ', 'Only for Linux, option "deb" or "appimage"', DEFAULT.targets) .option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT.inject) .option('--safe-domain [domains...]', 'Domains that Require Security Configuration"', DEFAULT.safeDomain) - .option('--debug', 'Debug mode', DEFAULT.debug) + .option('--debug', 'Debug build and more output', DEFAULT.debug) + .addOption(new Option('--user-agent ', 'Custom user agent').default(DEFAULT.userAgent).hideHelp()) + .addOption(new Option('--targets ', 'Only for Linux, option "deb" or "appimage"').default(DEFAULT.targets).hideHelp()) + .addOption(new Option('--always-on-top', 'Always on the top level').default(DEFAULT.alwaysOnTop).hideHelp()) + .addOption(new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts').default(DEFAULT.disabledWebShortcuts).hideHelp()) .version(packageJson.version, '-v, --version', 'Output the current version') .action(async (url: string, options: PakeCliOptions) => { await checkUpdateTips(); From 7bcaeb6d7e84f184234075b0475977aa0a9e949a Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 9 May 2024 15:31:19 +0800 Subject: [PATCH 05/12] :sparkles: Support always-one-top and disabled-web-shortcuts --- bin/README.md | 32 +++++++++++++++++++++++++------- bin/README_CN.md | 36 +++++++++++++++++++++++++----------- bin/defaults.ts | 1 + bin/helpers/merge.ts | 4 +++- bin/types.ts | 3 +++ 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/bin/README.md b/bin/README.md index deace75..68ecd5b 100644 --- a/bin/README.md +++ b/bin/README.md @@ -52,12 +52,11 @@ export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & {url: string} = { then - ```bash yarn cli:dev ``` -The script will reads the above configuration and packages the specified `app` using `watch` mode, and changes to the `pake-cli` code and `pake` are hot updated in real time. +The script will read the above configuration and packages the specified `app` using `watch` mode, and changes to the `pake-cli` code and `pake` are hot updated in real time. ### CLI Usage @@ -121,19 +120,29 @@ Enable or disable immersive header. Default is `false`. Use the following comman --transparent ``` +#### [fullscreen] + +Determine whether the application launches in full screen. Default is `false`. Use the following command to enable full +screen. + +```shell +--fullscreen +``` + #### [always-on-top] -Enable the always-on-top feature. Default is `false`. + +Sets whether the window is always at the top level, defaults to `false`. ```shell --always-on-top ``` -#### [fullscreen] +#### [disabled-web-shortcuts] -Determine whether the application launches in full screen. Default is `false`. Use the following command to enable full screen. +Sets whether to disable web shortcuts in the original Pake container, defaults to `false`. ```shell ---fullscreen +--disabled-web-shortcuts ``` #### [multi-arch] @@ -202,6 +211,7 @@ Enable recursive copying. When the URL is a local file path, enabling this optio ``` #### [inject] + Using `inject`, you can inject local absolute and relative path `css` and `js` files into the page you specify the `url` to customize it. For example, an adblock script that can be applied to any web page, or a `css` that optimizes the `UI` of a page, you can write it once to customize it. would only need to write the `app` once to generalize it to any other page. ```shell @@ -209,15 +219,23 @@ Using `inject`, you can inject local absolute and relative path `css` and `js` f ``` #### [safe-domain] + This secure domain is a domain other than your currently configured `url` to which you may be redirected or jumped to, and only in domains that have been configured as secure can you use `tauri` to expose `api` to browsers to ensure that pake's built-in enhancements work correctly. Only in a domain that has been configured as secure can you use the `tauri` to expose the `api` to the browser, ensuring that `pake's` built-in enhancements work correctly. PS: Secure domains do not need to carry protocols. - ```shell --safe-domain weread.qq.com,google.com ``` +#### [debug] + +The typed package has dev-tools for debugging, in addition to outputting more log messages for debugging. + +```shell +--debug +``` + ## Conclusion After completing the above steps, your application should be successfully packaged. Please note that the packaging process may take some time depending on your system configuration and network conditions. Be patient, and once the packaging is complete, you can find the application installer in the specified directory. diff --git a/bin/README_CN.md b/bin/README_CN.md index 981a255..d5b9868 100644 --- a/bin/README_CN.md +++ b/bin/README_CN.md @@ -40,6 +40,7 @@ npm install pake-cli -g ## 使用方法 ### 开发 + 开发时可以修改 `bin/defaults.ts` 中 `DEFAULT_DEV_PAKE_OPTIONS` 配置,配置项和 `pake-cli` 配置说明保持一致 ```typescript @@ -58,7 +59,6 @@ yarn cli:dev 脚本会读取上述配置并使用 `watch` 模式打包指定的 `app`,对 `pake-cli` 代码和 `pake` 的修改都会实时热更新。 - ### 使用 CLI ```bash @@ -122,16 +122,6 @@ pake [url] [options] --transparent ``` -#### [always-on-top] -设置是否窗口一直在最顶层,默认为 `false`。 - -```shell ---always-on-top -``` - - -```shell - #### [fullscreen] 设置应用程序是否在启动时自动全屏,默认为 `false`。使用以下命令可以设置应用程序启动时自动全屏。 @@ -140,6 +130,22 @@ pake [url] [options] --fullscreen ``` +#### [always-on-top] + +设置是否窗口一直在最顶层,默认为 `false`。 + +```shell +--always-on-top +``` + +#### [disabled-web-shortcuts] + +设置是否禁用原有 Pake 容器里面的网页操作快捷键,默认为 `false`。 + +```shell +--disabled-web-shortcuts +``` + #### [multi-arch] 设置打包结果同时支持 Intel 和 M1 芯片,仅适用于 macOS,默认为 `false`。 @@ -232,6 +238,14 @@ PS: 安全域名不需要携带协议。 --safe-domain weread.qq.com,google.com ``` +#### [debug] + +打出来的包具备 deb-tools 的调试模式,此外还会输出更多的日志信息用于调试。 + +```shell +--debug +``` + ## 结语 完成上述步骤后,您的应用程序应该已经成功打包。请注意,根据您的系统配置和网络状况,打包过程可能需要一些时间。请耐心等待,一旦打包完成,您就可以在指定的目录中找到应用程序安装包。 diff --git a/bin/defaults.ts b/bin/defaults.ts index cfaff8b..b75c4c7 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -8,6 +8,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { resizable: true, transparent: false, alwaysOnTop: false, + disabledWebShortcuts: false, userAgent: '', showSystemTray: false, multiArch: false, diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts index 9d306e6..820a688 100644 --- a/bin/helpers/merge.ts +++ b/bin/helpers/merge.ts @@ -14,6 +14,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon fullscreen, transparent, alwaysOnTop, + disabledWebShortcuts, userAgent, showSystemTray, systemTrayIcon, @@ -34,6 +35,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon fullscreen, transparent, alwaysOnTop, + disabledWebShortcuts, resizable, }; Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); @@ -193,7 +195,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon logger.error('The injected file must be in either CSS or JS format.'); return; } - const files = inject.map(filepath => path.isAbsolute(filepath) ? filepath : path.join(process.cwd(), filepath)); + const files = inject.map(filepath => path.isAbsolute(filepath) ? filepath : path.join(process.cwd(), filepath)); tauriConf.pake.inject = files; await combineFiles(files, injectFilePath); } else { diff --git a/bin/types.ts b/bin/types.ts index f555ed4..da11231 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -27,6 +27,9 @@ export interface PakeCliOptions { // Enable windows always on top, default false alwaysOnTop: boolean; + // Disable web shortcuts, default false + disabledWebShortcuts: boolean; + // Custom User-Agent, default off userAgent: string; From 161ec7f247854f19f3ae272629c8f7f7f16cf46f Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 9 May 2024 15:32:16 +0800 Subject: [PATCH 06/12] :sparkles: Pass pakeConfig to web --- src-tauri/pake.json | 5 +++-- src-tauri/src/app/config.rs | 9 +++++---- src-tauri/src/app/window.rs | 12 ++++++------ src-tauri/src/inject/event.js | 18 ++++++++++-------- src-tauri/src/inject/style.js | 2 +- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src-tauri/pake.json b/src-tauri/pake.json index 49e85bb..06944b2 100644 --- a/src-tauri/pake.json +++ b/src-tauri/pake.json @@ -2,13 +2,14 @@ "windows": [ { "url": "https://weread.qq.com", + "url_type": "web", "transparent": true, "fullscreen": false, "width": 1200, "height": 780, "resizable": true, - "url_type": "web", - "always_on_top": false + "always_on_top": false, + "disabled_web_shortcuts": false } ], "user_agent": { diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rs index 0610b72..4ce0ac3 100644 --- a/src-tauri/src/app/config.rs +++ b/src-tauri/src/app/config.rs @@ -1,6 +1,6 @@ -use serde::Deserialize; +use serde::{Deserialize, Serialize}; -#[derive(Debug, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct WindowConfig { pub url: String, pub transparent: bool, @@ -10,9 +10,10 @@ pub struct WindowConfig { pub resizable: bool, pub url_type: String, pub always_on_top: bool, + pub disabled_web_shortcuts: bool, } -#[derive(Debug, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct PlatformSpecific { pub macos: T, pub linux: T, @@ -44,7 +45,7 @@ where pub type UserAgent = PlatformSpecific; pub type FunctionON = PlatformSpecific; -#[derive(Debug, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct PakeConfig { pub windows: Vec, pub user_agent: UserAgent, diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index fde4f5a..77b54bb 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -19,6 +19,11 @@ pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> Wind _ => panic!("url type can only be web or local"), }; + let config_script = format!( + "window.pakeConfig = {}", + serde_json::to_string(&window_config).unwrap() + ); + let mut window_builder = WindowBuilder::new(app, "pake", url) .title("") .user_agent(user_agent) @@ -28,18 +33,13 @@ pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> Wind .inner_size(window_config.width, window_config.height) .disable_file_drop_handler() .always_on_top(window_config.always_on_top) + .initialization_script(&config_script) .initialization_script(include_str!("../inject/component.js")) .initialization_script(include_str!("../inject/event.js")) .initialization_script(include_str!("../inject/style.js")) //This is necessary to allow for file injection by external developers for customization purposes. .initialization_script(include_str!("../inject/custom.js")); - // For dynamic display of header styles - if window_config.transparent { - let transparent_script = "window.pakeWindowTitleTransparent = true;"; - window_builder = window_builder.initialization_script(transparent_script); - } - #[cfg(target_os = "macos")] { let title_bar_style = if window_config.transparent { diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js index 8a05bb0..d3131ea 100644 --- a/src-tauri/src/inject/event.js +++ b/src-tauri/src/inject/event.js @@ -88,14 +88,16 @@ document.addEventListener('DOMContentLoaded', () => { }); }); - document.addEventListener('keyup', (event) => { - if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) { - handleShortcut(event); - } - if (/macintosh|mac os x/i.test(navigator.userAgent) && event.metaKey) { - handleShortcut(event); - } - }); + if (window['pakeConfig']?.disabled_web_shortcuts !== true) { + document.addEventListener('keyup', (event) => { + if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) { + handleShortcut(event); + } + if (/macintosh|mac os x/i.test(navigator.userAgent) && event.metaKey) { + handleShortcut(event); + } + }); + } // Collect blob urls to blob by overriding window.URL.createObjectURL function collectUrlToBlobs() { diff --git a/src-tauri/src/inject/style.js b/src-tauri/src/inject/style.js index 62da1a7..e6b4320 100644 --- a/src-tauri/src/inject/style.js +++ b/src-tauri/src/inject/style.js @@ -412,7 +412,7 @@ window.addEventListener('DOMContentLoaded', _event => { } `; const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; - if (window.pakeWindowTitleTransparent && isMac) { + if (window['pakeConfig']?.transparent && isMac) { const topPaddingStyleElement = document.createElement('style'); topPaddingStyleElement.innerHTML = topPaddingCSS; document.head.appendChild(topPaddingStyleElement); From 6ed942883ed5a80d8c54d8bd2d4c61d2243b8026 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 9 May 2024 15:57:41 +0800 Subject: [PATCH 07/12] :fire: Remove a useless packaging configuration --- apps.conf.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps.conf.json b/apps.conf.json index 62f7578..b40a876 100644 --- a/apps.conf.json +++ b/apps.conf.json @@ -18,12 +18,6 @@ "name_zh": "YouTube", "url": "https://www.youtube.com" }, - { - "name": "reference", - "title": "Reference", - "name_zh": "Reference", - "url": "https://quickref.me/zh-CN/" - }, { "name": "coderunner", "title": "CodeRunner", From 2e95f4649879aefd86fe57c61c1022aec8477623 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 9 May 2024 19:46:27 +0800 Subject: [PATCH 08/12] :art: Hide uncommon commands --- bin/cli.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/cli.ts b/bin/cli.ts index e94cd0c..76e0894 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -29,11 +29,9 @@ program .option('--icon ', 'Application icon', DEFAULT.icon) .option('--width ', 'Window width', validateNumberInput, DEFAULT.width) .option('--height ', 'Window height', validateNumberInput, DEFAULT.height) - .option('--transparent', 'Only for Mac, hide title bar', DEFAULT.transparent) .option('--fullscreen', 'Start in full screen', DEFAULT.fullscreen) - .option('--show-system-tray', 'Show system tray in app', DEFAULT.showSystemTray) - .option('--system-tray-icon ', 'Custom system tray icon', DEFAULT.systemTrayIcon) - .option('--iter-copy-file', 'Copy files when URL is a local file', DEFAULT.iterCopyFile) + .option('--hide-title-bar', 'Only for Mac, hide title bar', DEFAULT.transparent) + .option('--activation-shortcut ', 'Shortcut key to active App', DEFAULT.activationShortcut) .option('--multi-arch', 'Only for Mac, supports both Intel and M1', DEFAULT.multiArch) .option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT.inject) .option('--safe-domain [domains...]', 'Domains that Require Security Configuration"', DEFAULT.safeDomain) @@ -42,6 +40,9 @@ program .addOption(new Option('--targets ', 'Only for Linux, option "deb" or "appimage"').default(DEFAULT.targets).hideHelp()) .addOption(new Option('--always-on-top', 'Always on the top level').default(DEFAULT.alwaysOnTop).hideHelp()) .addOption(new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts').default(DEFAULT.disabledWebShortcuts).hideHelp()) + .addOption(new Option('--show-system-tray', 'Show system tray in app').default(DEFAULT.showSystemTray).hideHelp()) + .addOption(new Option('--system-tray-icon ', 'Custom system tray icon').default(DEFAULT.systemTrayIcon).hideHelp()) + .addOption(new Option('--transparent', 'Only for Mac, hide title bar').default(DEFAULT.transparent).hideHelp()) .version(packageJson.version, '-v, --version', 'Output the current version') .action(async (url: string, options: PakeCliOptions) => { await checkUpdateTips(); From bb3b1b3d5937495ad0aeabd5eeaabee216e3487d Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 9 May 2024 19:47:08 +0800 Subject: [PATCH 09/12] :sparkles: Support setting activationShortcut --- bin/README.md | 31 ++++++++++++++++++++----------- bin/README_CN.md | 34 +++++++++++++++++++++------------- bin/defaults.ts | 1 + bin/types.ts | 3 +++ src-tauri/pake.json | 1 + src-tauri/src/app/config.rs | 1 + src-tauri/src/main.rs | 24 +++++++++++++++++++++++- 7 files changed, 70 insertions(+), 25 deletions(-) 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| { From 4df5a667d7eb1be552cdebc408eae5757e52ecfc Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 9 May 2024 20:00:16 +0800 Subject: [PATCH 10/12] :wrench: Improve china mirroring speed --- bin/builders/BaseBuilder.ts | 4 ++-- src-tauri/rust_proxy.toml | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/bin/builders/BaseBuilder.ts b/bin/builders/BaseBuilder.ts index 608e4b7..d19e1bf 100644 --- a/bin/builders/BaseBuilder.ts +++ b/bin/builders/BaseBuilder.ts @@ -49,7 +49,7 @@ export default abstract class BaseBuilder { const isChina = await isChinaDomain('www.npmjs.com'); const spinner = getSpinner('Installing package...'); const rustProjectDir = path.join(tauriSrcPath, '.cargo'); - const projectConf = path.join(rustProjectDir, 'config'); + const projectConf = path.join(rustProjectDir, 'config.toml'); await fsExtra.ensureDir(rustProjectDir); if (isChina) { @@ -73,7 +73,7 @@ export default abstract class BaseBuilder { async start(url: string) { await mergeConfig(url, this.options, tauriConfig); - } + } async buildAndCopy(url: string, target: string) { const { name } = this.options; diff --git a/src-tauri/rust_proxy.toml b/src-tauri/rust_proxy.toml index dbd564d..e5ab562 100644 --- a/src-tauri/rust_proxy.toml +++ b/src-tauri/rust_proxy.toml @@ -1,14 +1,10 @@ [source.crates-io] -# To use sparse index, change 'rsproxy' to 'rsproxy-sparse' -replace-with = 'rsproxy' - +replace-with = 'rsproxy-sparse' [source.rsproxy] registry = "https://rsproxy.cn/crates.io-index" [source.rsproxy-sparse] registry = "sparse+https://rsproxy.cn/index/" - [registries.rsproxy] index = "https://rsproxy.cn/crates.io-index" - [net] git-fetch-with-cli = true From 3473db73127a7d5348102f0715948edf61996b76 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 9 May 2024 20:50:11 +0800 Subject: [PATCH 11/12] :bug: Remove transparent and use hideTitleBar --- .github/workflows/pake-cli.yaml | 6 ++--- README.md | 4 +-- README_CN.md | 4 +-- bin/builders/BaseBuilder.ts | 3 ++- bin/cli.ts | 3 +-- bin/defaults.ts | 10 ++++---- bin/helpers/merge.ts | 10 +++++--- bin/types.ts | 4 +-- dist/cli.js | 44 +++++++++++++++++++++------------ package.json | 2 +- script/build_with_pake_cli.js | 6 ++--- src-tauri/pake.json | 2 +- src-tauri/src/app/config.rs | 2 +- src-tauri/src/app/window.rs | 2 +- src-tauri/src/inject/style.js | 2 +- 15 files changed, 59 insertions(+), 45 deletions(-) diff --git a/.github/workflows/pake-cli.yaml b/.github/workflows/pake-cli.yaml index 3a8a945..db00064 100644 --- a/.github/workflows/pake-cli.yaml +++ b/.github/workflows/pake-cli.yaml @@ -28,8 +28,8 @@ on: description: '[Height, Optional]' required: false default: '780' - transparent: - description: '[Transparent, Optional, MacOS only]' + hide_title_bar: + description: '[Hide TitleBar, Optional, MacOS only]' required: false type: boolean default: false @@ -124,7 +124,7 @@ jobs: ICON: ${{ inputs.icon }} HEIGHT: ${{ inputs.height }} WIDTH: ${{ inputs.width }} - TRANSPARENT: ${{ inputs.transparent }} + HIDE_TITLE_BAR: ${{ inputs.hide_title_bar }} FULLSCREEN: ${{ inputs.fullscreen }} RESIZE: ${{ inputs.resize }} MULTI_ARCH: ${{ inputs.multi_arch }} diff --git a/README.md b/README.md index 5cb5cef..2091f77 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ npm install -g pake-cli pake url [OPTIONS]... # Feel free to play with Pake! It might take a while to prepare the environment the first time you launch Pake. -pake https://weekly.tw93.fun --name Weekly --transparent +pake https://weekly.tw93.fun --name Weekly --hide-title-bar ``` If you are new to the command line, you can compile packages online with _GitHub Actions_. See the [Tutorial]() for more information. @@ -197,7 +197,7 @@ npm run build 1. You can refer to the [codebase structure](https://github.com/tw93/Pake/wiki/Description-of-Pake's-code-structure) before working on Pake, which will help you much in development. 2. Modify the `url` and `productName` fields in the `pake.json` file under the src-tauri directory, the "domain" field in the `tauri.config.json` file needs to be modified synchronously, as well as the `icon` and `identifier` fields in the `tauri.xxx.conf.json` file. You can select an `icon` from the `icons` directory or download one from [macOSicons](https://macosicons.com/#/) to match your product needs. -3. For configurations on window properties, you can modify the `pake.json` file to change the value of `width`, `height`, `fullscreen` (or not), `resizable` (or not) of the `windows` property. To adapt to the immersive header on Mac, change `transparent` to `true`, look for the `Header` element, and add the `padding-top` property. +3. For configurations on window properties, you can modify the `pake.json` file to change the value of `width`, `height`, `fullscreen` (or not), `resizable` (or not) of the `windows` property. To adapt to the immersive header on Mac, change `hideTitleBar` to `true`, look for the `Header` element, and add the `padding-top` property. 4. For advanced usages such as style rewriting, advertisement removal, JS injection, container message communication, and user-defined shortcut keys, see [Advanced Usage of Pake](https://github.com/tw93/Pake/wiki/Advanced-Usage-of-Pake). ## Developers diff --git a/README_CN.md b/README_CN.md index a3c883e..7e8726a 100644 --- a/README_CN.md +++ b/README_CN.md @@ -174,7 +174,7 @@ npm install -g pake-cli pake url [OPTIONS]... # 随便玩玩,首次由于安装环境会有些慢,后面就快了 -pake https://weekly.tw93.fun --name Weekly --transparent +pake https://weekly.tw93.fun --name Weekly --hide-title-bar ``` 假如你不太会使用命令行,或许使用 **GitHub Actions 在线编译多系统版本** 是一个不错的选择,可查看 [文档](https://github.com/tw93/Pake/wiki/%E5%9C%A8%E7%BA%BF%E7%BC%96%E8%AF%91%EF%BC%88%E6%99%AE%E9%80%9A%E7%94%A8%E6%88%B7%E4%BD%BF%E7%94%A8%EF%BC%89)。 @@ -199,7 +199,7 @@ npm run build 1. 代码结构可参考 [文档](https://github.com/tw93/Pake/wiki/Pake-%E7%9A%84%E4%BB%A3%E7%A0%81%E7%BB%93%E6%9E%84%E8%AF%B4%E6%98%8E),便于你在开发前了解更多。 2. 修改 src-tauri 目录下 `pake.json` 中的 `url` 和 `productName` 字段,需同步修改下 `tauri.config.json` 中的 `domain` 字段,以及 `tauri.xxx.conf.json` 中的 `icon` 和 `identifier` 字段,其中 `icon` 可以从 icons 目录选择一个,也可以去 [macOSicons](https://macosicons.com/#/) 下载符合效果的。 -3. 关于窗口属性设置,可以在 `pake.json` 修改 windows 属性对应的 `width/height`,fullscreen 是否全屏,resizable 是否可以调整大小,假如想适配 Mac 沉浸式头部,可以将 transparent 设置成 `true`,找到 Header 元素加一个 padding-top 样式即可,不想适配改成 `false` 也行。 +3. 关于窗口属性设置,可以在 `pake.json` 修改 windows 属性对应的 `width/height`,fullscreen 是否全屏,resizable 是否可以调整大小,假如想适配 Mac 沉浸式头部,可以将 hideTitleBar 设置成 `true`,找到 Header 元素加一个 padding-top 样式即可,不想适配改成 `false` 也行。 4. 此外样式改写、屏蔽广告、逻辑代码注入、容器消息通信、自定义快捷键可见 [高级用法](https://github.com/tw93/Pake/wiki/Pake-%E7%9A%84%E9%AB%98%E7%BA%A7%E7%94%A8%E6%B3%95)。 ## 开发者 diff --git a/bin/builders/BaseBuilder.ts b/bin/builders/BaseBuilder.ts index d19e1bf..ec679db 100644 --- a/bin/builders/BaseBuilder.ts +++ b/bin/builders/BaseBuilder.ts @@ -107,7 +107,8 @@ export default abstract class BaseBuilder { } protected getBasePath(): string { - return 'src-tauri/target/release/bundle/'; + const basePath = this.options.debug ? 'debug' : 'release'; + return `src-tauri/target/${basePath}/bundle/`; } protected getBuildAppPath(npmDirectory: string, fileName: string, fileType: string): string { diff --git a/bin/cli.ts b/bin/cli.ts index 76e0894..be4b2f6 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -30,7 +30,7 @@ program .option('--width ', 'Window width', validateNumberInput, DEFAULT.width) .option('--height ', 'Window height', validateNumberInput, DEFAULT.height) .option('--fullscreen', 'Start in full screen', DEFAULT.fullscreen) - .option('--hide-title-bar', 'Only for Mac, hide title bar', DEFAULT.transparent) + .option('--hide-title-bar', 'Only for Mac, hide title bar', DEFAULT.hideTitleBar) .option('--activation-shortcut ', 'Shortcut key to active App', DEFAULT.activationShortcut) .option('--multi-arch', 'Only for Mac, supports both Intel and M1', DEFAULT.multiArch) .option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT.inject) @@ -42,7 +42,6 @@ program .addOption(new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts').default(DEFAULT.disabledWebShortcuts).hideHelp()) .addOption(new Option('--show-system-tray', 'Show system tray in app').default(DEFAULT.showSystemTray).hideHelp()) .addOption(new Option('--system-tray-icon ', 'Custom system tray icon').default(DEFAULT.systemTrayIcon).hideHelp()) - .addOption(new Option('--transparent', 'Only for Mac, hide title bar').default(DEFAULT.transparent).hideHelp()) .version(packageJson.version, '-v, --version', 'Output the current version') .action(async (url: string, options: PakeCliOptions) => { await checkUpdateTips(); diff --git a/bin/defaults.ts b/bin/defaults.ts index 445d5b1..ef356da 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -6,7 +6,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { width: 1200, fullscreen: false, resizable: true, - transparent: false, + hideTitleBar: false, alwaysOnTop: false, disabledWebShortcuts: false, activationShortcut: '', @@ -22,10 +22,10 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { }; // Just for cli development -export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & {url: string} = { +export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & { url: string } = { ...DEFAULT_PAKE_OPTIONS, url: 'https://weread.qq.com', name: 'WeRead', - safeDomain:['weread.qq.com'], - transparent: true, -} + safeDomain: ['weread.qq.com'], + hideTitleBar: true, +}; diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts index 820a688..e1a30e6 100644 --- a/bin/helpers/merge.ts +++ b/bin/helpers/merge.ts @@ -12,9 +12,10 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon width, height, fullscreen, - transparent, + hideTitleBar, alwaysOnTop, disabledWebShortcuts, + activationShortcut, userAgent, showSystemTray, systemTrayIcon, @@ -33,10 +34,11 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon width, height, fullscreen, - transparent, - alwaysOnTop, - disabledWebShortcuts, resizable, + hide_title_bar: hideTitleBar, + activation_shortcut: activationShortcut, + always_on_top: alwaysOnTop, + disabled_web_shortcuts: disabledWebShortcuts, }; Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); diff --git a/bin/types.ts b/bin/types.ts index 4b64210..f1eda57 100644 --- a/bin/types.ts +++ b/bin/types.ts @@ -21,8 +21,8 @@ export interface PakeCliOptions { // Whether the window can be fullscreen, default false fullscreen: boolean; - // Enable immersive header, default false - transparent: boolean; + // Enable immersive header, default false. + hideTitleBar: boolean; // Enable windows always on top, default false alwaysOnTop: boolean; diff --git a/dist/cli.js b/dist/cli.js index 046be55..048bd6b 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1,5 +1,5 @@ import chalk from 'chalk'; -import { InvalidArgumentError, program } from 'commander'; +import { InvalidArgumentError, program, Option } from 'commander'; import log from 'loglevel'; import path from 'path'; import fsExtra from 'fs-extra'; @@ -20,7 +20,7 @@ import psl from 'psl'; import isUrl from 'is-url'; var name = "pake-cli"; -var version = "2.3.8"; +var version = "2.4.0-beta1"; var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。"; var engines = { node: ">=16.0.0" @@ -126,12 +126,15 @@ var packageJson = { var windows = [ { url: "https://weread.qq.com", - transparent: true, + url_type: "web", + hide_title_bar: true, fullscreen: false, width: 1200, height: 780, resizable: true, - url_type: "web" + always_on_top: false, + activation_shortcut: "", + disabled_web_shortcuts: false } ]; var user_agent = { @@ -471,15 +474,18 @@ async function combineFiles(files, output) { } async function mergeConfig(url, options, tauriConf) { - const { width, height, fullscreen, transparent, userAgent, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, resizable = true, inject, safeDomain, } = options; + const { width, height, fullscreen, hideTitleBar, alwaysOnTop, disabledWebShortcuts, activationShortcut, userAgent, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, resizable = true, inject, safeDomain, } = options; const { platform } = process; // Set Windows parameters. const tauriConfWindowOptions = { width, height, fullscreen, - transparent, resizable, + hide_title_bar: hideTitleBar, + activation_shortcut: activationShortcut, + always_on_top: alwaysOnTop, + disabled_web_shortcuts: disabledWebShortcuts, }; Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions }); tauriConf.package.productName = name; @@ -682,7 +688,7 @@ class BaseBuilder { const isChina = await isChinaDomain('www.npmjs.com'); const spinner = getSpinner('Installing package...'); const rustProjectDir = path.join(tauriSrcPath, '.cargo'); - const projectConf = path.join(rustProjectDir, 'config'); + const projectConf = path.join(rustProjectDir, 'config.toml'); await fsExtra.ensureDir(rustProjectDir); if (isChina) { logger.info('✺ Located in China, using npm/rsProxy CN mirror.'); @@ -729,7 +735,8 @@ class BaseBuilder { return this.options.debug ? 'npm run build:debug' : 'npm run build'; } getBasePath() { - return 'src-tauri/target/release/bundle/'; + const basePath = this.options.debug ? 'debug' : 'release'; + return `src-tauri/target/${basePath}/bundle/`; } getBuildAppPath(npmDirectory, fileName, fileType) { return path.join(npmDirectory, this.getBasePath(), fileType.toLowerCase(), `${fileName}.${fileType}`); @@ -823,7 +830,10 @@ const DEFAULT_PAKE_OPTIONS = { width: 1200, fullscreen: false, resizable: true, - transparent: false, + hideTitleBar: false, + alwaysOnTop: false, + disabledWebShortcuts: false, + activationShortcut: '', userAgent: '', showSystemTray: false, multiArch: false, @@ -1014,17 +1024,19 @@ program .option('--icon ', 'Application icon', DEFAULT_PAKE_OPTIONS.icon) .option('--width ', 'Window width', validateNumberInput, DEFAULT_PAKE_OPTIONS.width) .option('--height ', 'Window height', validateNumberInput, DEFAULT_PAKE_OPTIONS.height) - .option('--transparent', 'Only for Mac, hide title bar', DEFAULT_PAKE_OPTIONS.transparent) .option('--fullscreen', 'Start in full screen', DEFAULT_PAKE_OPTIONS.fullscreen) - .option('--user-agent ', 'Custom user agent', DEFAULT_PAKE_OPTIONS.userAgent) - .option('--show-system-tray', 'Show system tray in app', DEFAULT_PAKE_OPTIONS.showSystemTray) - .option('--system-tray-icon ', 'Custom system tray icon', DEFAULT_PAKE_OPTIONS.systemTrayIcon) - .option('--iter-copy-file', 'Copy files when URL is a local file', DEFAULT_PAKE_OPTIONS.iterCopyFile) + .option('--hide-title-bar', 'Only for Mac, hide title bar', DEFAULT_PAKE_OPTIONS.hideTitleBar) + .option('--activation-shortcut ', 'Shortcut key to active App', DEFAULT_PAKE_OPTIONS.activationShortcut) .option('--multi-arch', 'Only for Mac, supports both Intel and M1', DEFAULT_PAKE_OPTIONS.multiArch) - .option('--targets ', 'Only for Linux, option "deb" or "appimage"', DEFAULT_PAKE_OPTIONS.targets) .option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT_PAKE_OPTIONS.inject) .option('--safe-domain [domains...]', 'Domains that Require Security Configuration"', DEFAULT_PAKE_OPTIONS.safeDomain) - .option('--debug', 'Debug mode', DEFAULT_PAKE_OPTIONS.debug) + .option('--debug', 'Debug build and more output', DEFAULT_PAKE_OPTIONS.debug) + .addOption(new Option('--user-agent ', 'Custom user agent').default(DEFAULT_PAKE_OPTIONS.userAgent).hideHelp()) + .addOption(new Option('--targets ', 'Only for Linux, option "deb" or "appimage"').default(DEFAULT_PAKE_OPTIONS.targets).hideHelp()) + .addOption(new Option('--always-on-top', 'Always on the top level').default(DEFAULT_PAKE_OPTIONS.alwaysOnTop).hideHelp()) + .addOption(new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts').default(DEFAULT_PAKE_OPTIONS.disabledWebShortcuts).hideHelp()) + .addOption(new Option('--show-system-tray', 'Show system tray in app').default(DEFAULT_PAKE_OPTIONS.showSystemTray).hideHelp()) + .addOption(new Option('--system-tray-icon ', 'Custom system tray icon').default(DEFAULT_PAKE_OPTIONS.systemTrayIcon).hideHelp()) .version(packageJson.version, '-v, --version', 'Output the current version') .action(async (url, options) => { await checkUpdateTips(); diff --git a/package.json b/package.json index 8073af2..03a7256 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pake-cli", - "version": "2.3.8", + "version": "2.4.0", "description": "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。", "engines": { "node": ">=16.0.0" diff --git a/script/build_with_pake_cli.js b/script/build_with_pake_cli.js index fede4d0..621eec8 100644 --- a/script/build_with_pake_cli.js +++ b/script/build_with_pake_cli.js @@ -13,7 +13,7 @@ console.log('name: ', process.env.NAME); console.log('icon: ', process.env.ICON); console.log('height: ', process.env.HEIGHT); console.log('width: ', process.env.WIDTH); -console.log('transparent: ', process.env.TRANSPARENT); +console.log('hide-title-bar: ', process.env.HIDE_TITLE_BAR); console.log('resize: ', process.env.RESIZE); console.log('is multi arch? only for Mac: ', process.env.MULTI_ARCH); console.log('targets type? only for Linux: ', process.env.TARGETS); @@ -22,8 +22,8 @@ console.log('===========================\n'); cd('node_modules/pake-cli'); let params = `node cli.js ${process.env.URL} --name ${process.env.NAME} --height ${process.env.HEIGHT} --width ${process.env.WIDTH}`; -if (process.env.TRANSPARENT === 'true') { - params = `${params} --transparent`; +if (process.env.HIDE_TITLE_BAR === 'true') { + params = `${params} --hide-title-bar`; } if (process.env.FULLSCREEN === 'true') { diff --git a/src-tauri/pake.json b/src-tauri/pake.json index cb7b0e2..382b34b 100644 --- a/src-tauri/pake.json +++ b/src-tauri/pake.json @@ -3,7 +3,7 @@ { "url": "https://weread.qq.com", "url_type": "web", - "transparent": true, + "hide_title_bar": true, "fullscreen": false, "width": 1200, "height": 780, diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rs index e2ebb74..5280875 100644 --- a/src-tauri/src/app/config.rs +++ b/src-tauri/src/app/config.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct WindowConfig { pub url: String, - pub transparent: bool, + pub hide_title_bar: bool, pub fullscreen: bool, pub width: f64, pub height: f64, diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index 77b54bb..44cdf84 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -42,7 +42,7 @@ pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> Wind #[cfg(target_os = "macos")] { - let title_bar_style = if window_config.transparent { + let title_bar_style = if window_config.hide_title_bar { TitleBarStyle::Overlay } else { TitleBarStyle::Visible diff --git a/src-tauri/src/inject/style.js b/src-tauri/src/inject/style.js index e6b4320..816963e 100644 --- a/src-tauri/src/inject/style.js +++ b/src-tauri/src/inject/style.js @@ -412,7 +412,7 @@ window.addEventListener('DOMContentLoaded', _event => { } `; const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0; - if (window['pakeConfig']?.transparent && isMac) { + if (window['pakeConfig']?.hide_title_bar && isMac) { const topPaddingStyleElement = document.createElement('style'); topPaddingStyleElement.innerHTML = topPaddingCSS; document.head.appendChild(topPaddingStyleElement); From b37b06ea61f482f711ca8ae069d320f79572b16c Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 9 May 2024 20:58:21 +0800 Subject: [PATCH 12/12] :bookmark: npm 2.4.0 --- dist/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/cli.js b/dist/cli.js index 048bd6b..9478f3c 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -20,7 +20,7 @@ import psl from 'psl'; import isUrl from 'is-url'; var name = "pake-cli"; -var version = "2.4.0-beta1"; +var version = "2.4.0"; var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。"; var engines = { node: ">=16.0.0"