refactor: reduce webview lock contention (#6271)

* refactor: replace handle::Handle::get_window() with WindowManager::get_main_window() in multiple files

* refactor: enhance WindowManager to return window state alongside the main window instance

* refactor: update useProfiles and ProfilePage to support profile overrides and improve patchProfilesConfig return type

* refactor: enhance handle_success to check main window existence before notifying profile changes

* refactor: simplify get_main_window_with_state by using pattern matching and improve window state handling

* refactor: fix window activation by removing unnecessary reference in activate_existing_main_window

* refactor: remove redundant macOS conditional for window_manager import
This commit is contained in:
Tunglies
2026-02-07 05:45:15 +00:00
committed by GitHub
parent 6c6e0812b8
commit c30eaa3678
11 changed files with 83 additions and 72 deletions
+5 -5
View File
@@ -1,6 +1,6 @@
use crate::{
config::Config,
core::{handle, timer::Timer, tray::Tray},
core::{timer::Timer, tray::Tray},
process::AsyncHandler,
};
@@ -143,7 +143,7 @@ pub async fn add_light_weight_timer() {
}
fn setup_window_close_listener() {
if let Some(window) = handle::Handle::get_window() {
if let Some(window) = WindowManager::get_main_window() {
let handler_id = window.listen("tauri://close-requested", move |_event| {
std::mem::drop(AsyncHandler::spawn(|| async {
if let Err(e) = setup_light_weight_timer().await {
@@ -161,7 +161,7 @@ fn setup_window_close_listener() {
}
fn cancel_window_close_listener() {
if let Some(window) = handle::Handle::get_window() {
if let Some(window) = WindowManager::get_main_window() {
let id = WINDOW_CLOSE_HANDLER_ID.swap(0, Ordering::AcqRel);
if id != 0 {
window.unlisten(id);
@@ -171,7 +171,7 @@ fn cancel_window_close_listener() {
}
fn setup_webview_focus_listener() {
if let Some(window) = handle::Handle::get_window() {
if let Some(window) = WindowManager::get_main_window() {
let handler_id = window.listen("tauri://focus", move |_event| {
logging_error!(Type::Lightweight, cancel_light_weight_timer());
logging!(debug, Type::Lightweight, "监听到窗口获得焦点,取消轻量模式计时");
@@ -181,7 +181,7 @@ fn setup_webview_focus_listener() {
}
fn cancel_webview_focus_listener() {
if let Some(window) = handle::Handle::get_window() {
if let Some(window) = WindowManager::get_main_window() {
let id = WEBVIEW_FOCUS_HANDLER_ID.swap(0, Ordering::AcqRel);
if id != 0 {
window.unlisten(id);