mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
feat(hotkey): add global reactivate_profiles shortcut (#5527)
* feat(hotkey): add global reactivate_profiles shortcut * feat(profile): expose validation state for reactivation shortcuts
This commit is contained in:
@@ -36,14 +36,29 @@ pub async fn get_profiles() -> CmdResult<IProfiles> {
|
||||
#[tauri::command]
|
||||
pub async fn enhance_profiles() -> CmdResult {
|
||||
match feat::enhance_profiles().await {
|
||||
Ok(_) => {}
|
||||
Ok((true, _)) => {
|
||||
handle::Handle::refresh_clash();
|
||||
Ok(())
|
||||
}
|
||||
Ok((false, msg)) => {
|
||||
let message: String = if msg.is_empty() {
|
||||
"Failed to reactivate profiles".into()
|
||||
} else {
|
||||
msg
|
||||
};
|
||||
logging!(
|
||||
warn,
|
||||
Type::Cmd,
|
||||
"Reactivate profiles command failed validation: {}",
|
||||
message.as_str()
|
||||
);
|
||||
Err(message)
|
||||
}
|
||||
Err(e) => {
|
||||
logging!(error, Type::Cmd, "{}", e);
|
||||
return Err(e.to_string().into());
|
||||
Err(e.to_string().into())
|
||||
}
|
||||
}
|
||||
handle::Handle::refresh_clash();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 导入配置文件
|
||||
|
||||
@@ -21,6 +21,7 @@ pub enum HotkeyFunction {
|
||||
ToggleSystemProxy,
|
||||
ToggleTunMode,
|
||||
EntryLightweightMode,
|
||||
ReactivateProfiles,
|
||||
Quit,
|
||||
#[cfg(target_os = "macos")]
|
||||
Hide,
|
||||
@@ -36,6 +37,7 @@ impl fmt::Display for HotkeyFunction {
|
||||
Self::ToggleSystemProxy => "toggle_system_proxy",
|
||||
Self::ToggleTunMode => "toggle_tun_mode",
|
||||
Self::EntryLightweightMode => "entry_lightweight_mode",
|
||||
Self::ReactivateProfiles => "reactivate_profiles",
|
||||
Self::Quit => "quit",
|
||||
#[cfg(target_os = "macos")]
|
||||
Self::Hide => "hide",
|
||||
@@ -56,6 +58,7 @@ impl FromStr for HotkeyFunction {
|
||||
"toggle_system_proxy" => Ok(Self::ToggleSystemProxy),
|
||||
"toggle_tun_mode" => Ok(Self::ToggleTunMode),
|
||||
"entry_lightweight_mode" => Ok(Self::EntryLightweightMode),
|
||||
"reactivate_profiles" => Ok(Self::ReactivateProfiles),
|
||||
"quit" => Ok(Self::Quit),
|
||||
#[cfg(target_os = "macos")]
|
||||
"hide" => Ok(Self::Hide),
|
||||
@@ -149,6 +152,40 @@ impl Hotkey {
|
||||
notify_event(NotificationEvent::LightweightModeEntered).await;
|
||||
});
|
||||
}
|
||||
HotkeyFunction::ReactivateProfiles => {
|
||||
AsyncHandler::spawn(async move || match feat::enhance_profiles().await {
|
||||
Ok((true, _)) => {
|
||||
handle::Handle::refresh_clash();
|
||||
notify_event(NotificationEvent::ProfilesReactivated).await;
|
||||
}
|
||||
Ok((false, msg)) => {
|
||||
let message = if msg.is_empty() {
|
||||
"Failed to reactivate profiles.".to_string()
|
||||
} else {
|
||||
msg.to_string()
|
||||
};
|
||||
logging!(
|
||||
warn,
|
||||
Type::Hotkey,
|
||||
"Hotkey profile reactivation failed validation: {}",
|
||||
message.as_str()
|
||||
);
|
||||
handle::Handle::notice_message("reactivate_profiles::error", message);
|
||||
}
|
||||
Err(err) => {
|
||||
logging!(
|
||||
error,
|
||||
Type::Hotkey,
|
||||
"Failed to reactivate subscriptions via hotkey: {}",
|
||||
err
|
||||
);
|
||||
handle::Handle::notice_message(
|
||||
"reactivate_profiles::error",
|
||||
err.to_string(),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
HotkeyFunction::Quit => {
|
||||
AsyncHandler::spawn(async move || {
|
||||
notify_event(NotificationEvent::AppQuit).await;
|
||||
|
||||
@@ -259,9 +259,6 @@ pub async fn update_profile(
|
||||
}
|
||||
|
||||
/// 增强配置
|
||||
pub async fn enhance_profiles() -> Result<()> {
|
||||
crate::core::CoreManager::global()
|
||||
.update_config()
|
||||
.await
|
||||
.map(|_| ())
|
||||
pub async fn enhance_profiles() -> Result<(bool, String)> {
|
||||
crate::core::CoreManager::global().update_config().await
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ pub enum NotificationEvent<'a> {
|
||||
SystemProxyToggled,
|
||||
TunModeToggled,
|
||||
LightweightModeEntered,
|
||||
ProfilesReactivated,
|
||||
AppQuit,
|
||||
#[cfg(target_os = "macos")]
|
||||
AppHidden,
|
||||
@@ -54,6 +55,11 @@ pub async fn notify_event<'a>(event: NotificationEvent<'a>) {
|
||||
let body = rust_i18n::t!("notifications.lightweightModeEntered.body").to_string();
|
||||
notify(&title, &body);
|
||||
}
|
||||
NotificationEvent::ProfilesReactivated => {
|
||||
let title = rust_i18n::t!("notifications.profilesReactivated.title").to_string();
|
||||
let body = rust_i18n::t!("notifications.profilesReactivated.body").to_string();
|
||||
notify(&title, &body);
|
||||
}
|
||||
NotificationEvent::AppQuit => {
|
||||
let title = rust_i18n::t!("notifications.appQuit.title").to_string();
|
||||
let body = rust_i18n::t!("notifications.appQuit.body").to_string();
|
||||
|
||||
Reference in New Issue
Block a user