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