mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 03:03:46 +08:00
feat: use tauri_plugin_window_state
This commit is contained in:
parent
2493f463f3
commit
12df415dfd
16
src-tauri/Cargo.lock
generated
16
src-tauri/Cargo.lock
generated
@ -1013,6 +1013,7 @@ dependencies = [
|
|||||||
"tauri-plugin-process",
|
"tauri-plugin-process",
|
||||||
"tauri-plugin-shell",
|
"tauri-plugin-shell",
|
||||||
"tauri-plugin-updater",
|
"tauri-plugin-updater",
|
||||||
|
"tauri-plugin-window-state",
|
||||||
"tokio",
|
"tokio",
|
||||||
"url",
|
"url",
|
||||||
"users",
|
"users",
|
||||||
@ -6603,6 +6604,21 @@ dependencies = [
|
|||||||
"zip",
|
"zip",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-plugin-window-state"
|
||||||
|
version = "2.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fd1cef203a15b4772898e7bc8e57c1f34696e39848987dfcd294d51ba0525650"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.6.0",
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"tauri",
|
||||||
|
"tauri-plugin",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-runtime"
|
name = "tauri-runtime"
|
||||||
version = "2.1.1"
|
version = "2.1.1"
|
||||||
|
@ -67,6 +67,7 @@ users = "0.11.0"
|
|||||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||||
tauri-plugin-global-shortcut = "2.0.0-rc"
|
tauri-plugin-global-shortcut = "2.0.0-rc"
|
||||||
tauri-plugin-updater = "2.0.0-rc"
|
tauri-plugin-updater = "2.0.0-rc"
|
||||||
|
tauri-plugin-window-state = "2.0.0-rc"
|
||||||
#openssl
|
#openssl
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
"permissions": [
|
"permissions": [
|
||||||
"global-shortcut:default",
|
"global-shortcut:default",
|
||||||
"updater:default",
|
"updater:default",
|
||||||
"deep-link:default"
|
"deep-link:default",
|
||||||
|
"window-state:default",
|
||||||
|
"window-state:default"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ use crate::core::hotkey;
|
|||||||
use crate::utils::{resolve, resolve::resolve_scheme, server};
|
use crate::utils::{resolve, resolve::resolve_scheme, server};
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use tauri::Listener;
|
use tauri::Listener;
|
||||||
|
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
// 单例检测
|
// 单例检测
|
||||||
@ -32,6 +33,7 @@ pub fn run() {
|
|||||||
|
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut builder = tauri::Builder::default()
|
let mut builder = tauri::Builder::default()
|
||||||
|
.plugin(tauri_plugin_window_state::Builder::new().build())
|
||||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||||
.plugin(tauri_plugin_clipboard_manager::init())
|
.plugin(tauri_plugin_clipboard_manager::init())
|
||||||
.plugin(tauri_plugin_process::init())
|
.plugin(tauri_plugin_process::init())
|
||||||
@ -41,6 +43,7 @@ pub fn run() {
|
|||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_shell::init())
|
||||||
.plugin(tauri_plugin_deep_link::init())
|
.plugin(tauri_plugin_deep_link::init())
|
||||||
|
.plugin(tauri_plugin_window_state::Builder::default().build())
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
@ -144,6 +147,8 @@ pub fn run() {
|
|||||||
tauri::WindowEvent::CloseRequested { api, .. } => {
|
tauri::WindowEvent::CloseRequested { api, .. } => {
|
||||||
println!("closing window...");
|
println!("closing window...");
|
||||||
api.prevent_close();
|
api.prevent_close();
|
||||||
|
let app_hanele = core::handle::Handle::global().app_handle().unwrap();
|
||||||
|
let _ = app_hanele.save_window_state(StateFlags::default());
|
||||||
let window = core::handle::Handle::global().get_window().unwrap();
|
let window = core::handle::Handle::global().get_window().unwrap();
|
||||||
log_err!(window.hide());
|
log_err!(window.hide());
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ use percent_encoding::percent_decode_str;
|
|||||||
use serde_yaml::Mapping;
|
use serde_yaml::Mapping;
|
||||||
use std::net::TcpListener;
|
use std::net::TcpListener;
|
||||||
use tauri::{App, Manager};
|
use tauri::{App, Manager};
|
||||||
|
use tauri_plugin_window_state::{StateFlags, WindowExt};
|
||||||
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
//#[cfg(not(target_os = "linux"))]
|
//#[cfg(not(target_os = "linux"))]
|
||||||
@ -143,22 +144,26 @@ pub fn create_window() {
|
|||||||
.transparent(true)
|
.transparent(true)
|
||||||
.inner_size(800.0, 636.0)
|
.inner_size(800.0, 636.0)
|
||||||
.visible(false)
|
.visible(false)
|
||||||
.build();
|
.build().unwrap();
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
let _ = builder
|
let window = builder
|
||||||
.decorations(true)
|
.decorations(true)
|
||||||
.hidden_title(true)
|
.hidden_title(true)
|
||||||
.title_bar_style(tauri::TitleBarStyle::Overlay)
|
.title_bar_style(tauri::TitleBarStyle::Overlay)
|
||||||
.inner_size(800.0, 642.0)
|
.inner_size(800.0, 642.0)
|
||||||
.build();
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
let _ = builder
|
let window = builder
|
||||||
.decorations(false)
|
.decorations(false)
|
||||||
.transparent(true)
|
.transparent(true)
|
||||||
.inner_size(800.0, 642.0)
|
.inner_size(800.0, 642.0)
|
||||||
.build();
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let _ = window.restore_state(StateFlags::all());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn resolve_scheme(param: String) -> Result<()> {
|
pub async fn resolve_scheme(param: String) -> Result<()> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user