Skip to content

Commit

Permalink
fix: dark mode flash in win
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Dec 26, 2023
1 parent 4345dc2 commit ffe2bde
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
5 changes: 4 additions & 1 deletion backend/tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ fn main() -> std::io::Result<()> {
#[allow(unused_mut)]
let mut builder = tauri::Builder::default()
.system_tray(SystemTray::new())
.setup(|app| Ok(resolve::resolve_setup(app)))
.setup(|app| {
resolve::resolve_setup(app);
Ok(())
})
.on_system_tray_event(core::tray::Tray::on_system_tray_event)
.invoke_handler(tauri::generate_handler![
// common
Expand Down
31 changes: 15 additions & 16 deletions backend/tauri/src/utils/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ pub fn create_window(app_handle: &AppHandle) {

#[cfg(target_os = "windows")]
{
use std::time::Duration;
use tokio::time::sleep;
use window_shadows::set_shadow;

match builder
Expand All @@ -161,6 +159,7 @@ pub fn create_window(app_handle: &AppHandle) {
trace_err!(win.set_fullscreen(true), "set win fullscreen");
}
}
trace_err!(set_shadow(&win, true), "set win shadow");
log::trace!("try to calculate the monitor size");
let center = (|| -> Result<bool> {
let mut center = false;
Expand All @@ -182,22 +181,22 @@ pub fn create_window(app_handle: &AppHandle) {
trace_err!(win.center(), "set win center");
}

log::trace!("try to create window");
let app_handle = app_handle.clone();
// log::trace!("try to create window");
// let app_handle = app_handle.clone();

// 加点延迟避免界面闪一下
tauri::async_runtime::spawn(async move {
// sleep(Duration::from_millis(888)).await;

if let Some(window) = app_handle.get_window("main") {
trace_err!(set_shadow(&window, true), "set win shadow");
trace_err!(window.show(), "set win visible");
trace_err!(window.unminimize(), "set win unminimize");
trace_err!(window.set_focus(), "set win focus");
} else {
log::error!(target: "app", "failed to create window, get_window is None")
}
});
// tauri::async_runtime::spawn(async move {
// // sleep(Duration::from_millis(888)).await;

// if let Some(window) = app_handle.get_window("main") {
// trace_err!(set_shadow(&window, true), "set win shadow");
// trace_err!(window.show(), "set win visible");
// trace_err!(window.unminimize(), "set win unminimize");
// trace_err!(window.set_focus(), "set win focus");
// } else {
// log::error!(target: "app", "failed to create window, get_window is None")
// }
// });
}
Err(err) => log::error!(target: "app", "failed to create window, {err}"),
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if (!window.ResizeObserver) {

import React from "react";
import { createRoot } from "react-dom/client";
import { RecoilRoot } from "recoil";
import { BrowserRouter } from "react-router-dom";
import { RecoilRoot } from "recoil";
import { BaseErrorBoundary } from "./components/base";
import Layout from "./pages/_layout";
import "./services/i18n";
Expand Down
6 changes: 6 additions & 0 deletions src/pages/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ export default function Layout() {
break;
}
});

setTimeout(() => {
appWindow.show();
appWindow.unminimize();
appWindow.setFocus();
}, 50);
}, []);

useEffect(() => {
Expand Down

0 comments on commit ffe2bde

Please sign in to comment.