mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-06 00:33:44 +08:00
Update autostart capability permissions
Enable more precise control over autostart functionality and clean up logging code by removing unnecessary boolean parameters.
This commit is contained in:
parent
9070ef1dbe
commit
25d66a4eee
@ -16,6 +16,8 @@
|
||||
"deep-link:default",
|
||||
"window-state:default",
|
||||
"window-state:default",
|
||||
"autostart:default"
|
||||
"autostart:allow-enable",
|
||||
"autostart:allow-disable",
|
||||
"autostart:allow-is-enabled"
|
||||
]
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ impl Hotkey {
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Initializing hotkeys with enable: {}",
|
||||
"Initializing global hotkeys: {}",
|
||||
enable_global_hotkey
|
||||
);
|
||||
|
||||
@ -80,7 +80,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Successfully registered hotkey {} -> {}",
|
||||
key,
|
||||
func
|
||||
@ -103,7 +102,7 @@ impl Hotkey {
|
||||
}
|
||||
self.current.lock().clone_from(hotkeys);
|
||||
} else {
|
||||
logging!(debug, Type::Hotkey, true, "No hotkeys configured");
|
||||
logging!(debug, Type::Hotkey, "No hotkeys configured");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -123,7 +122,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Attempting to register hotkey: {} for function: {}",
|
||||
hotkey,
|
||||
func
|
||||
@ -133,7 +131,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Hotkey {} was already registered, unregistering first",
|
||||
hotkey
|
||||
);
|
||||
@ -145,7 +142,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Registering open_or_close_dashboard function"
|
||||
);
|
||||
|| {
|
||||
@ -158,22 +154,17 @@ impl Hotkey {
|
||||
|
||||
// 使用 spawn_blocking 来确保在正确的线程上执行
|
||||
async_runtime::spawn_blocking(|| {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Toggle dashboard window visibility"
|
||||
);
|
||||
logging!(debug, Type::Hotkey, "Toggle dashboard window visibility");
|
||||
|
||||
// 检查窗口是否存在
|
||||
if let Some(window) = handle::Handle::global().get_window() {
|
||||
// 如果窗口可见,则隐藏它
|
||||
if window.is_visible().unwrap_or(false) {
|
||||
logging!(info, Type::Window, true, "Window is visible, hiding it");
|
||||
logging!(info, Type::Window, "Window is visible, hiding it");
|
||||
let _ = window.hide();
|
||||
} else {
|
||||
// 如果窗口不可见,则显示它
|
||||
logging!(info, Type::Window, true, "Window is hidden, showing it");
|
||||
logging!(info, Type::Window, "Window is hidden, showing it");
|
||||
if window.is_minimized().unwrap_or(false) {
|
||||
let _ = window.unminimize();
|
||||
}
|
||||
@ -185,7 +176,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
info,
|
||||
Type::Window,
|
||||
true,
|
||||
"Window does not exist, creating a new one"
|
||||
);
|
||||
resolve::create_window(true);
|
||||
@ -195,7 +185,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"=== Hotkey Dashboard Window Operation End ==="
|
||||
);
|
||||
}
|
||||
@ -211,7 +200,7 @@ impl Hotkey {
|
||||
"hide" => || feat::hide(),
|
||||
|
||||
_ => {
|
||||
logging!(error, Type::Hotkey, true, "Invalid function: {}", func);
|
||||
logging!(error, Type::Hotkey, "Invalid function: {}", func);
|
||||
bail!("invalid function \"{func}\"");
|
||||
}
|
||||
};
|
||||
@ -220,18 +209,18 @@ impl Hotkey {
|
||||
|
||||
let _ = manager.on_shortcut(hotkey, move |app_handle, hotkey, event| {
|
||||
if event.state == ShortcutState::Pressed {
|
||||
logging!(debug, Type::Hotkey, true, "Hotkey pressed: {:?}", hotkey);
|
||||
logging!(debug, Type::Hotkey, "Hotkey pressed: {:?}", hotkey);
|
||||
|
||||
if hotkey.key == Code::KeyQ && is_quit {
|
||||
if let Some(window) = app_handle.get_webview_window("main") {
|
||||
if window.is_focused().unwrap_or(false) {
|
||||
logging!(debug, Type::Hotkey, true, "Executing quit function");
|
||||
logging!(debug, Type::Hotkey, "Executing quit function");
|
||||
f();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 直接执行函数,不做任何状态检查
|
||||
logging!(debug, Type::Hotkey, true, "Executing function directly");
|
||||
logging!(debug, Type::Hotkey, "Executing function directly");
|
||||
|
||||
// 获取全局热键状态
|
||||
let is_enable_global_hotkey = Config::verge()
|
||||
@ -257,7 +246,6 @@ impl Hotkey {
|
||||
logging!(
|
||||
debug,
|
||||
Type::Hotkey,
|
||||
true,
|
||||
"Successfully registered hotkey {} for {}",
|
||||
hotkey,
|
||||
func
|
||||
@ -269,7 +257,7 @@ impl Hotkey {
|
||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||
let manager = app_handle.global_shortcut();
|
||||
manager.unregister(hotkey)?;
|
||||
logging!(debug, Type::Hotkey, true, "Unregister hotkey {}", hotkey);
|
||||
logging!(debug, Type::Hotkey, "Unregister hotkey {}", hotkey);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -285,7 +273,7 @@ impl Hotkey {
|
||||
});
|
||||
|
||||
add.iter().for_each(|(key, func)| {
|
||||
logging_error!(Type::Hotkey, true, self.register(key, func));
|
||||
logging_error!(Type::Hotkey, self.register(key, func));
|
||||
});
|
||||
|
||||
*current = new_hotkeys;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
config::{Config, IVerge},
|
||||
core::handle::Handle,
|
||||
logging_error,
|
||||
logging, logging_error,
|
||||
utils::logging::Type,
|
||||
};
|
||||
use anyhow::Result;
|
||||
@ -16,8 +16,6 @@ use tokio::time::{sleep, Duration};
|
||||
pub struct Sysopt {
|
||||
update_sysproxy: Arc<TokioMutex<bool>>,
|
||||
reset_sysproxy: Arc<TokioMutex<bool>>,
|
||||
/// helps to auto launch the app
|
||||
auto_launch: Arc<Mutex<bool>>,
|
||||
/// record whether the guard async is running or not
|
||||
guard_state: Arc<Mutex<bool>>,
|
||||
}
|
||||
@ -58,7 +56,6 @@ impl Sysopt {
|
||||
SYSOPT.get_or_init(|| Sysopt {
|
||||
update_sysproxy: Arc::new(TokioMutex::new(false)),
|
||||
reset_sysproxy: Arc::new(TokioMutex::new(false)),
|
||||
auto_launch: Arc::new(Mutex::new(false)),
|
||||
guard_state: Arc::new(false.into()),
|
||||
})
|
||||
}
|
||||
@ -216,34 +213,17 @@ impl Sysopt {
|
||||
|
||||
/// update the startup
|
||||
pub fn update_launch(&self) -> Result<()> {
|
||||
let _lock = self.auto_launch.lock();
|
||||
let enable = { Config::verge().latest().enable_auto_launch };
|
||||
let enable = enable.unwrap_or(false);
|
||||
let enable_auto_launch = { Config::verge().latest().enable_auto_launch };
|
||||
let app_handle = Handle::global().app_handle().unwrap();
|
||||
let autostart_manager = app_handle.autolaunch();
|
||||
|
||||
log::info!(target: "app", "Setting auto launch to: {}", enable);
|
||||
|
||||
match enable {
|
||||
true => {
|
||||
let result = autostart_manager.enable();
|
||||
if let Err(ref e) = result {
|
||||
log::error!(target: "app", "Failed to enable auto launch: {}", e);
|
||||
} else {
|
||||
log::info!(target: "app", "Auto launch enabled successfully");
|
||||
}
|
||||
logging_error!(Type::System, true, result);
|
||||
}
|
||||
false => {
|
||||
let result = autostart_manager.disable();
|
||||
if let Err(ref e) = result {
|
||||
log::error!(target: "app", "Failed to disable auto launch: {}", e);
|
||||
} else {
|
||||
log::info!(target: "app", "Auto launch disabled successfully");
|
||||
}
|
||||
logging_error!(Type::System, true, result);
|
||||
}
|
||||
};
|
||||
let is_enable = enable_auto_launch.unwrap_or(false);
|
||||
logging!(info, true, "Setting auto-launch state to: {:?}", is_enable);
|
||||
if is_enable {
|
||||
logging_error!(Type::System, true, "{:?}", autostart_manager.enable());
|
||||
} else {
|
||||
logging_error!(Type::System, true, "{:?}", autostart_manager.disable());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -63,7 +63,6 @@ fn setup_webview_focus_listener() -> u32 {
|
||||
logging!(
|
||||
info,
|
||||
Type::Lightweight,
|
||||
true,
|
||||
"监听到窗口获得焦点,取消轻量模式计时"
|
||||
);
|
||||
});
|
||||
|
@ -198,7 +198,6 @@ pub fn create_window(is_showup: bool) {
|
||||
Ok(window) => {
|
||||
logging!(info, Type::Window, true, "Window created successfully");
|
||||
if is_showup {
|
||||
println!("is showup");
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
} else {
|
||||
@ -215,12 +214,7 @@ pub fn create_window(is_showup: bool) {
|
||||
tauri::async_runtime::spawn(async move {
|
||||
use tauri::Emitter;
|
||||
|
||||
logging!(
|
||||
info,
|
||||
Type::Window,
|
||||
true,
|
||||
"标记前端UI已准备就绪,开始处理启动错误队列"
|
||||
);
|
||||
logging!(info, Type::Window, true, "UI gets ready.");
|
||||
handle::Handle::global().mark_startup_completed();
|
||||
|
||||
if let Some(window) = app_handle_clone.get_webview_window("main") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user