fix: kernel-caused silent mode failure to start windows

This commit is contained in:
huzibaca 2024-11-26 05:50:56 +08:00
parent 1cc6472002
commit 71cb2a97c0
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302
2 changed files with 42 additions and 36 deletions

View File

@ -20,12 +20,16 @@ use tauri_plugin_window_state::{AppHandleExt, StateFlags};
// 打开面板 // 打开面板
pub fn open_or_close_dashboard() { pub fn open_or_close_dashboard() {
if let Some(window) = handle::Handle::global().get_window() { if let Some(window) = handle::Handle::global().get_window() {
if let Ok(true) = window.is_focused() { // 如果窗口存在,则切换其显示状态
if window.is_visible().unwrap_or(false) {
let _ = window.hide(); let _ = window.hide();
return; } else {
} let _ = window.show();
let _ = window.set_focus();
} }
} else {
resolve::create_window(); resolve::create_window();
}
} }
// 重启clash // 重启clash

View File

@ -37,7 +37,7 @@ pub fn find_unused_port() -> Result<u16> {
/// handle something when start app /// handle something when start app
pub async fn resolve_setup(app: &mut App) { pub async fn resolve_setup(app: &mut App) {
error::redirect_panic_to_log(); error::redirect_panic_to_log();
// #[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
app.set_activation_policy(tauri::ActivationPolicy::Accessory); app.set_activation_policy(tauri::ActivationPolicy::Accessory);
let version = app.package_info().version.to_string(); let version = app.package_info().version.to_string();
@ -128,7 +128,11 @@ pub fn create_window() {
return; return;
} }
let builder = tauri::WebviewWindowBuilder::new( #[cfg(target_os = "windows")]
let window = {
let app_handle = app_handle.clone();
std::thread::spawn(move || {
tauri::WebviewWindowBuilder::new(
&app_handle, &app_handle,
"main".to_string(), "main".to_string(),
tauri::WebviewUrl::App("index.html".into()), tauri::WebviewUrl::App("index.html".into()),
@ -136,29 +140,25 @@ pub fn create_window() {
.title("Clash Verge") .title("Clash Verge")
.visible(false) .visible(false)
.fullscreen(false) .fullscreen(false)
.min_inner_size(600.0, 520.0); .min_inner_size(600.0, 520.0)
#[cfg(target_os = "windows")]
let window = builder
.decorations(false) .decorations(false)
.maximizable(true) .maximizable(true)
.additional_browser_args("--enable-features=msWebView2EnableDraggableRegions --disable-features=OverscrollHistoryNavigation,msExperimentalScrolling") .additional_browser_args("--enable-features=msWebView2EnableDraggableRegions --disable-features=OverscrollHistoryNavigation,msExperimentalScrolling")
.transparent(true) .transparent(true)
.visible(false)
.build().unwrap();
#[cfg(target_os = "macos")]
let window = builder
.decorations(true)
.hidden_title(true)
.title_bar_style(tauri::TitleBarStyle::Overlay)
.build() .build()
.unwrap(); }).join().unwrap()
}.unwrap();
#[cfg(target_os = "linux")] #[cfg(not(target_os = "windows"))]
let window = builder let window = tauri::WebviewWindowBuilder::new(
.decorations(false) &app_handle,
.transparent(true) "main".to_string(),
tauri::WebviewUrl::App("index.html".into()),
)
.title("Clash Verge")
.visible(false)
.fullscreen(false)
.min_inner_size(600.0, 520.0)
.build() .build()
.unwrap(); .unwrap();
@ -169,12 +169,14 @@ pub fn create_window() {
Err(e) => { Err(e) => {
log::error!(target: "app", "failed to restore window state: {}", e); log::error!(target: "app", "failed to restore window state: {}", e);
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
window {
.set_size(tauri::Size::Physical(tauri::PhysicalSize { window.clone().on_window_event(move |_event| {
let _ = window.set_size(tauri::Size::Physical(tauri::PhysicalSize {
width: 800, width: 800,
height: 636, height: 636,
})) }));
.unwrap(); });
}
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
window window