mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: add notification system with hotkey events and permission handling (#3867)
* feat: add notification system with hotkey events and permission handling * Add macOS-specific handling for AppHidden notification Introduces conditional support for the AppHidden notification event, enabling macOS-specific behavior. Updates the enum and notification logic to include this platform-specific feature. Improves macOS user experience by accommodating system-level application hiding events. * Implement feature X to enhance user experience and fix bug Y in module Z * refactor(notification): update notification keys for consistency and clarity * chore(deps): update dependencies to latest versions
This commit is contained in:
70
src-tauri/src/utils/notification.rs
Normal file
70
src-tauri/src/utils/notification.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
use tauri::AppHandle;
|
||||
use tauri_plugin_notification::NotificationExt;
|
||||
|
||||
pub enum NotificationEvent<'a> {
|
||||
DashboardToggled,
|
||||
ClashModeChanged {
|
||||
mode: &'a str,
|
||||
},
|
||||
SystemProxyToggled,
|
||||
TunModeToggled,
|
||||
LightweightModeEntered,
|
||||
AppQuit,
|
||||
#[cfg(target_os = "macos")]
|
||||
AppHidden,
|
||||
}
|
||||
|
||||
fn notify(app: &AppHandle, title: &str, body: &str) {
|
||||
app.notification()
|
||||
.builder()
|
||||
.title(title)
|
||||
.body(body)
|
||||
.show()
|
||||
.ok();
|
||||
}
|
||||
|
||||
pub fn notify_event(app: &AppHandle, event: NotificationEvent) {
|
||||
use crate::utils::i18n::t;
|
||||
match event {
|
||||
NotificationEvent::DashboardToggled => {
|
||||
notify(app, &t("DashboardToggledTitle"), &t("DashboardToggledBody"));
|
||||
}
|
||||
NotificationEvent::ClashModeChanged { mode } => {
|
||||
notify(
|
||||
app,
|
||||
&t("ClashModeChangedTitle"),
|
||||
&t_with_args("ClashModeChangedBody", mode),
|
||||
);
|
||||
}
|
||||
NotificationEvent::SystemProxyToggled => {
|
||||
notify(
|
||||
app,
|
||||
&t("SystemProxyToggledTitle"),
|
||||
&t("SystemProxyToggledBody"),
|
||||
);
|
||||
}
|
||||
NotificationEvent::TunModeToggled => {
|
||||
notify(app, &t("TunModeToggledTitle"), &t("TunModeToggledBody"));
|
||||
}
|
||||
NotificationEvent::LightweightModeEntered => {
|
||||
notify(
|
||||
app,
|
||||
&t("LightweightModeEnteredTitle"),
|
||||
&t("LightweightModeEnteredBody"),
|
||||
);
|
||||
}
|
||||
NotificationEvent::AppQuit => {
|
||||
notify(app, &t("AppQuitTitle"), &t("AppQuitBody"));
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
NotificationEvent::AppHidden => {
|
||||
notify(app, &t("AppHiddenTitle"), &t("AppHiddenBody"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 辅助函数,带参数的i18n
|
||||
fn t_with_args(key: &str, mode: &str) -> String {
|
||||
use crate::utils::i18n::t;
|
||||
t(key).replace("{mode}", mode)
|
||||
}
|
||||
Reference in New Issue
Block a user