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:
Tunglies
2025-06-26 23:09:07 +08:00
committed by GitHub
parent ae187cc21a
commit f1192c95a8
13 changed files with 1167 additions and 783 deletions

View 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)
}