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:
@@ -1,7 +1,9 @@
|
||||
import { AppDataProvider } from "./providers/app-data-provider";
|
||||
import Layout from "./pages/_layout";
|
||||
import { useNotificationPermission } from "./hooks/useNotificationPermission";
|
||||
|
||||
function App() {
|
||||
useNotificationPermission();
|
||||
return (
|
||||
<AppDataProvider>
|
||||
<Layout />
|
||||
|
||||
8
src/hooks/useNotificationPermission.ts
Normal file
8
src/hooks/useNotificationPermission.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { setupNotificationPermission } from "../utils/notification-permission";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function useNotificationPermission() {
|
||||
useEffect(() => {
|
||||
setupNotificationPermission();
|
||||
}, []);
|
||||
}
|
||||
@@ -624,5 +624,19 @@
|
||||
"No (IP Banned By Disney+)": "No (IP Banned By Disney+)",
|
||||
"Unsupported Country/Region": "Unsupported Country/Region",
|
||||
"Failed (Network Connection)": "Failed (Network Connection)",
|
||||
"DashboardToggledTitle": "Dashboard Toggled",
|
||||
"DashboardToggledBody": "Dashboard visibility toggled by hotkey",
|
||||
"ClashModeChangedTitle": "Clash Mode Changed",
|
||||
"ClashModeChangedBody": "Switched to {mode} mode",
|
||||
"SystemProxyToggledTitle": "System Proxy Toggled",
|
||||
"SystemProxyToggledBody": "System proxy state toggled by hotkey",
|
||||
"TunModeToggledTitle": "TUN Mode Toggled",
|
||||
"TunModeToggledBody": "TUN mode toggled by hotkey",
|
||||
"LightweightModeEnteredTitle": "Lightweight Mode",
|
||||
"LightweightModeEnteredBody": "Entered lightweight mode by hotkey",
|
||||
"AppQuitTitle": "APP Quit",
|
||||
"AppQuitBody": "APP quit by hotkey",
|
||||
"AppHiddenTitle": "APP Hidden",
|
||||
"AppHiddenBody": "APP window hidden by hotkey",
|
||||
"Invalid Profile URL": "Invalid profile URL. Please enter a URL starting with http:// or https://"
|
||||
}
|
||||
|
||||
@@ -624,5 +624,19 @@
|
||||
"No (IP Banned By Disney+)": "不支持(IP被Disney+禁止)",
|
||||
"Unsupported Country/Region": "不支持的国家/地区",
|
||||
"Failed (Network Connection)": "测试失败(网络连接问题)",
|
||||
"DashboardToggledTitle": "仪表盘已切换",
|
||||
"DashboardToggledBody": "已通过快捷键切换仪表盘显示状态",
|
||||
"ClashModeChangedTitle": "Clash 模式切换",
|
||||
"ClashModeChangedBody": "已切换为 {mode} 模式",
|
||||
"SystemProxyToggledTitle": "系统代理切换",
|
||||
"SystemProxyToggledBody": "已通过快捷键切换系统代理状态",
|
||||
"TunModeToggledTitle": "TUN 模式切换",
|
||||
"TunModeToggledBody": "已通过快捷键切换 TUN 模式",
|
||||
"LightweightModeEnteredTitle": "轻量模式",
|
||||
"LightweightModeEnteredBody": "已通过快捷键进入轻量模式",
|
||||
"AppQuitTitle": "应用退出",
|
||||
"AppQuitBody": "已通过快捷键退出应用",
|
||||
"AppHiddenTitle": "应用隐藏",
|
||||
"AppHiddenBody": "已通过快捷键隐藏应用窗口",
|
||||
"Invalid Profile URL": "无效的订阅链接,请输入以 http:// 或 https:// 开头的地址"
|
||||
}
|
||||
|
||||
17
src/utils/notification-permission.ts
Normal file
17
src/utils/notification-permission.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
isPermissionGranted,
|
||||
requestPermission,
|
||||
} from "@tauri-apps/plugin-notification";
|
||||
|
||||
export async function setupNotificationPermission() {
|
||||
let permission = await isPermissionGranted();
|
||||
if (!permission) {
|
||||
const result = await requestPermission();
|
||||
permission = result === "granted";
|
||||
}
|
||||
if (permission) {
|
||||
console.log("通知权限已授予");
|
||||
} else {
|
||||
console.log("通知权限被拒绝");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user