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() {
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();
return;
} else {
let _ = window.show();
let _ = window.set_focus();
}
} else {
resolve::create_window();
}
resolve::create_window();
}
// 重启clash

View File

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