fix: restore the window state first, then set the window size

This commit is contained in:
huzibaca 2024-11-23 06:39:25 +08:00
parent f08d2c998d
commit a14c3f81b0
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302
2 changed files with 16 additions and 5 deletions

View File

@ -121,7 +121,6 @@ pub fn quit(code: Option<i32>) {
handle::Handle::global().set_is_exiting();
resolve::resolve_reset();
log_err!(handle::Handle::global().get_window().unwrap().close());
println!("saving window state");
match app_handle.save_window_state(StateFlags::all()) {
Ok(_) => {
println!("window state saved successfully");

View File

@ -141,9 +141,9 @@ pub fn create_window() {
#[cfg(target_os = "windows")]
let window = builder
.decorations(false)
.maximizable(true)
.additional_browser_args("--enable-features=msWebView2EnableDraggableRegions --disable-features=OverscrollHistoryNavigation,msExperimentalScrolling")
.transparent(true)
.inner_size(800.0, 636.0)
.visible(false)
.build().unwrap();
@ -152,7 +152,6 @@ pub fn create_window() {
.decorations(true)
.hidden_title(true)
.title_bar_style(tauri::TitleBarStyle::Overlay)
.inner_size(800.0, 642.0)
.build()
.unwrap();
@ -160,11 +159,9 @@ pub fn create_window() {
let window = builder
.decorations(false)
.transparent(true)
.inner_size(800.0, 642.0)
.build()
.unwrap();
println!("restore window state");
match window.restore_state(StateFlags::all()) {
Ok(_) => {
println!("window state restored successfully");
@ -173,6 +170,21 @@ pub fn create_window() {
Err(e) => {
println!("failed to restore window state: {}", 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();
#[cfg(not(target_os = "macos"))]
window
.set_size(tauri::Size::Physical(tauri::PhysicalSize {
width: 800,
height: 642,
}))
.unwrap();
}
};
}