add new param hide-on-close

This commit is contained in:
Tw93
2025-08-05 15:17:02 +08:00
parent d8b8102367
commit 4a91c42e2e
16 changed files with 1223 additions and 1136 deletions

View File

@@ -91,6 +91,7 @@ npm run analyze
- **Window Management**: `src-tauri/src/app/window.rs` - Window creation, sizing, title bar handling
- **System Tray**: `src-tauri/src/app/setup.rs` - Cross-platform system tray integration
- **Window Close Behavior**: `src-tauri/src/lib.rs` - Configurable close behavior (hide vs exit)
- **Global Shortcuts**: Activation shortcuts for bringing app to foreground
- **Web Integration**: Custom user agents, proxy support, CSS/JS injection
- **Multi-platform**: Builds for macOS (Intel/M1), Windows, Linux (deb/appimage/rpm)

View File

@@ -198,7 +198,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 `hideTitleBar` 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), `hide_on_close` (hide window on close instead of exiting) 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

View File

@@ -196,7 +196,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 沉浸式头部,可以将 hideTitleBar 设置成 `true`,找到 Header 元素加一个 padding-top 样式即可,不想适配改成 `false` 也行。
3. 关于窗口属性设置,可以在 `pake.json` 修改 windows 属性对应的 `width/height`fullscreen 是否全屏resizable 是否可以调整大小,hide_on_close 关闭时是否隐藏窗口而不是退出,假如想适配 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)。
## 开发者

8
bin/README.md vendored
View File

@@ -208,6 +208,14 @@ Specify the system tray icon. This is only effective when the system tray is ena
--system-tray-icon <path>
```
#### [hide-on-close]
Hide the window instead of exiting when clicking the close button. Default is `true`. When enabled, the application will be minimized to the system tray (if available) or hidden when the close button is clicked, rather than actually closing the application.
```shell
--hide-on-close
```
#### [installer-language]
Set the Windows Installer language. Options include `zh-CN`, `ja-JP`, More at [Tauri Document](https://tauri.app/distribute/windows-installer/#internationalization). Default is `en-US`.

8
bin/README_CN.md vendored
View File

@@ -208,6 +208,14 @@ pake [url] [options]
--system-tray-icon <path>
```
#### [hide-on-close]
设置点击关闭按钮时隐藏窗口而不是退出应用。默认为 `true`。启用后,点击关闭按钮时应用会最小化到系统托盘(如果可用)或隐藏窗口,而不是直接关闭应用程序。
```shell
--hide-on-close
```
#### [installer-language]
设置 Windows 安装包语言。支持 `zh-CN`、`ja-JP`,更多在 [Tauri 文档](https://tauri.app/distribute/windows-installer/#internationalization)。默认为 `en-US`。

1
bin/cli.ts vendored
View File

@@ -44,6 +44,7 @@ program
)
.addOption(new Option('--show-system-tray', 'Show system tray in app').default(DEFAULT.showSystemTray).hideHelp())
.addOption(new Option('--system-tray-icon <string>', 'Custom system tray icon').default(DEFAULT.systemTrayIcon).hideHelp())
.addOption(new Option('--hide-on-close', 'Hide window on close instead of exiting').default(DEFAULT.hideOnClose).hideHelp())
.addOption(new Option('--installer-language <string>', 'Installer language').default(DEFAULT.installerLanguage).hideHelp())
.version(packageJson.version, '-v, --version', 'Output the current version')
.action(async (url: string, options: PakeCliOptions) => {

1
bin/defaults.ts vendored
View File

@@ -22,6 +22,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
debug: false,
inject: [],
installerLanguage: 'en-US',
hideOnClose: true,
};
// Just for cli development

View File

@@ -28,6 +28,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
inject,
proxyUrl,
installerLanguage,
hideOnClose,
} = options;
const { platform } = process;
@@ -43,6 +44,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
always_on_top: alwaysOnTop,
dark_mode: darkMode,
disabled_web_shortcuts: disabledWebShortcuts,
hide_on_close: hideOnClose,
};
Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });

3
bin/types.ts vendored
View File

@@ -68,6 +68,9 @@ export interface PakeCliOptions {
// Installer language, valid for Windows users, default is en-US
installerLanguage: string;
// Hide window on close instead of exiting, default false
hideOnClose: boolean;
}
export interface PakeAppOptions extends PakeCliOptions {

9
dist/cli.js vendored
View File

@@ -124,7 +124,7 @@ var packageJson = {
var windows = [
{
url: "https://weread.qq.com",
url: "https://weread.qq.com/",
url_type: "web",
hide_title_bar: true,
fullscreen: false,
@@ -147,6 +147,7 @@ var system_tray = {
linux: true,
windows: true
};
var hide_on_close = true;
var system_tray_path = "icons/icon.png";
var inject = [
];
@@ -155,6 +156,7 @@ var pakeConf = {
windows: windows,
user_agent: user_agent,
system_tray: system_tray,
hide_on_close: hide_on_close,
system_tray_path: system_tray_path,
inject: inject,
proxy_url: proxy_url
@@ -430,7 +432,7 @@ async function combineFiles(files, output) {
}
async function mergeConfig(url, options, tauriConf) {
const { width, height, fullscreen, hideTitleBar, alwaysOnTop, appVersion, darkMode, disabledWebShortcuts, activationShortcut, userAgent, showSystemTray, systemTrayIcon, useLocalFile, identifier, name, resizable = true, inject, proxyUrl, installerLanguage, } = options;
const { width, height, fullscreen, hideTitleBar, alwaysOnTop, appVersion, darkMode, disabledWebShortcuts, activationShortcut, userAgent, showSystemTray, systemTrayIcon, useLocalFile, identifier, name, resizable = true, inject, proxyUrl, installerLanguage, hideOnClose, } = options;
const { platform } = process;
// Set Windows parameters.
const tauriConfWindowOptions = {
@@ -488,6 +490,7 @@ async function mergeConfig(url, options, tauriConf) {
tauriConf.pake.user_agent[currentPlatform] = userAgent;
}
tauriConf.pake.system_tray[currentPlatform] = showSystemTray;
tauriConf.pake.hide_on_close = hideOnClose;
// Processing targets are currently only open to Linux.
if (platform === 'linux') {
delete tauriConf.bundle.linux.deb.files;
@@ -800,6 +803,7 @@ const DEFAULT_PAKE_OPTIONS = {
debug: false,
inject: [],
installerLanguage: 'en-US',
hideOnClose: true,
};
async function checkUpdateTips() {
@@ -994,6 +998,7 @@ program
.addOption(new Option('--activation-shortcut <string>', 'Shortcut key to active App').default(DEFAULT_PAKE_OPTIONS.activationShortcut).hideHelp())
.addOption(new Option('--show-system-tray', 'Show system tray in app').default(DEFAULT_PAKE_OPTIONS.showSystemTray).hideHelp())
.addOption(new Option('--system-tray-icon <string>', 'Custom system tray icon').default(DEFAULT_PAKE_OPTIONS.systemTrayIcon).hideHelp())
.addOption(new Option('--hide-on-close', 'Hide window on close instead of exiting').default(DEFAULT_PAKE_OPTIONS.hideOnClose).hideHelp())
.addOption(new Option('--installer-language <string>', 'Installer language').default(DEFAULT_PAKE_OPTIONS.installerLanguage).hideHelp())
.version(packageJson.version, '-v, --version', 'Output the current version')
.action(async (url, options) => {

2256
src-tauri/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -15,20 +15,20 @@ crate-type = ["staticlib", "cdylib", "lib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "2.0.4", features = [] }
tauri-build = { version = "2.3.1", features = [] }
[dependencies]
serde_json = "1.0.134"
serde = { version = "1.0.218", features = ["derive"] }
tokio = { version = "1.43.0", features = ["full"] }
tauri = { version = "2.2.5", features = ["tray-icon", "image-ico", "image-png", "macos-proxy"] }
tauri-plugin-window-state = "2.2.2"
serde_json = "1.0.142"
serde = { version = "1.0.219", features = ["derive"] }
tokio = { version = "1.47.1", features = ["full"] }
tauri = { version = "2.7.0", features = ["tray-icon", "image-ico", "image-png", "macos-proxy"] }
tauri-plugin-window-state = "2.4.0"
tauri-plugin-oauth = "2.0.0"
tauri-plugin-http = "2.3.0"
tauri-plugin-global-shortcut = { version = "2.2.1" }
tauri-plugin-shell = "2.2.1"
tauri-plugin-single-instance = "2.2.4"
tauri-plugin-notification = "2.2.2"
tauri-plugin-http = "2.5.1"
tauri-plugin-global-shortcut = { version = "2.3.0" }
tauri-plugin-shell = "2.3.0"
tauri-plugin-single-instance = "2.3.2"
tauri-plugin-notification = "2.3.0"
[features]
# this feature is used for development builds from development cli

View File

@@ -1,7 +1,7 @@
{
"windows": [
{
"url": "https://github.com",
"url": "https://weread.qq.com/",
"url_type": "web",
"hide_title_bar": true,
"fullscreen": false,
@@ -11,7 +11,8 @@
"always_on_top": false,
"dark_mode": false,
"activation_shortcut": "",
"disabled_web_shortcuts": false
"disabled_web_shortcuts": false,
"hide_on_close": false
}
],
"user_agent": {

View File

@@ -13,6 +13,7 @@ pub struct WindowConfig {
pub dark_mode: bool,
pub disabled_web_shortcuts: bool,
pub activation_shortcut: String,
pub hide_on_close: bool,
}
#[derive(Debug, Serialize, Deserialize)]

View File

@@ -284,6 +284,14 @@ window.addEventListener('DOMContentLoaded', _event => {
margin: 0;
display: inline;
}
.AppHeader .AppHeader-globalBar.js-global-bar {
padding-top: 35px;
}
.header-overlay .header-logged-out {
margin-top: 15px;
}
`;
const contentStyleElement = document.createElement('style');
contentStyleElement.innerHTML = contentCSS;

View File

@@ -21,6 +21,7 @@ pub fn run_app() {
let tauri_app = tauri::Builder::default();
let show_system_tray = pake_config.show_system_tray();
let hide_on_close = pake_config.windows[0].hide_on_close;
let activation_shortcut = pake_config.windows[0].activation_shortcut.clone();
let init_fullscreen = pake_config.windows[0].fullscreen;
@@ -54,19 +55,24 @@ pub fn run_app() {
window.show().unwrap();
Ok(())
})
.on_window_event(|_window, _event| {
#[cfg(target_os = "macos")]
.on_window_event(move |_window, _event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = _event {
let window = _window.clone();
tauri::async_runtime::spawn(async move {
if window.is_fullscreen().unwrap_or(false) {
window.set_fullscreen(false).unwrap();
tokio::time::sleep(Duration::from_millis(900)).await;
}
window.minimize().unwrap();
window.hide().unwrap();
});
api.prevent_close();
if hide_on_close {
let window = _window.clone();
tauri::async_runtime::spawn(async move {
#[cfg(target_os = "macos")]
{
if window.is_fullscreen().unwrap_or(false) {
window.set_fullscreen(false).unwrap();
tokio::time::sleep(Duration::from_millis(900)).await;
}
}
window.minimize().unwrap();
window.hide().unwrap();
});
api.prevent_close();
}
// If hide_on_close is false, allow normal close behavior
}
})
.run(tauri::generate_context!())