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

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!())