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
+1 -5
View File
@@ -5,7 +5,7 @@ use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
};
use tauri::{AppHandle, Manager as _, WebviewWindow};
use tauri::AppHandle;
use tauri_plugin_mihomo::{Mihomo, MihomoExt as _};
use tokio::sync::RwLockReadGuard;
@@ -55,10 +55,6 @@ impl Handle {
Self::app_handle().mihomo().read().await
}
pub fn get_window() -> Option<WebviewWindow> {
Self::app_handle().get_webview_window("main")
}
pub fn refresh_clash() {
let handle = Self::global();
if handle.is_exiting() {
+5 -3
View File
@@ -1,6 +1,7 @@
use crate::process::AsyncHandler;
use crate::singleton;
use crate::utils::notification::{NotificationEvent, notify_event};
use crate::utils::window_manager::WindowManager;
use crate::{config::Config, core::handle, feat, module::lightweight::entry_lightweight_mode};
use anyhow::{Result, bail};
use arc_swap::ArcSwap;
@@ -243,7 +244,7 @@ impl Hotkey {
logging!(debug, Type::Hotkey, "Hotkey pressed: {:?}", hotkey_event);
let hotkey = hotkey_event.key;
if hotkey == Code::KeyQ && is_quit {
if let Some(window) = handle::Handle::get_window()
if let Some(window) = WindowManager::get_main_window()
&& window.is_focused().unwrap_or(false)
{
logging!(debug, Type::Hotkey, "Executing quit function");
@@ -260,8 +261,9 @@ impl Hotkey {
Self::execute_function(function);
} else {
use crate::utils::window_manager::WindowManager;
let is_visible = WindowManager::is_main_window_visible();
let is_focused = WindowManager::is_main_window_focused();
let window = WindowManager::get_main_window();
let is_visible = WindowManager::is_main_window_visible(window.as_ref());
let is_focused = WindowManager::is_main_window_focused(window.as_ref());
if is_focused && is_visible {
Self::execute_function(function);
+2 -2
View File
@@ -1,5 +1,5 @@
use super::handle::Handle;
use crate::constants::timing;
use crate::{constants::timing, utils::window_manager::WindowManager};
use clash_verge_logging::{Type, logging};
use smartstring::alias::String;
use std::{sync::mpsc, thread};
@@ -84,7 +84,7 @@ impl NotificationSystem {
None => return,
};
if let Some(window) = super::handle::Handle::get_window() {
if let Some(window) = WindowManager::get_main_window() {
system.emit_to_window(&window, event);
drop(binding);
thread::sleep(timing::EVENT_EMIT_DELAY);