summaryrefslogtreecommitdiffhomepage
path: root/packages/desktop/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/desktop/src')
-rw-r--r--packages/desktop/src/index.tsx29
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsx
index 58aca8fd1..a36da4125 100644
--- a/packages/desktop/src/index.tsx
+++ b/packages/desktop/src/index.tsx
@@ -12,6 +12,8 @@ import { UPDATER_ENABLED } from "./updater"
import { createMenu } from "./menu"
import { check, Update } from "@tauri-apps/plugin-updater"
import { invoke } from "@tauri-apps/api/core"
+import { getCurrentWindow } from "@tauri-apps/api/window"
+import { isPermissionGranted, requestPermission } from "@tauri-apps/plugin-notification"
import { relaunch } from "@tauri-apps/plugin-process"
import pkg from "../package.json"
@@ -94,6 +96,33 @@ const platform: Platform = {
await relaunch()
},
+ notify: async (title, description, href) => {
+ const granted = await isPermissionGranted().catch(() => false)
+ const permission = granted ? "granted" : await requestPermission().catch(() => "denied")
+ if (permission !== "granted") return
+
+ const win = getCurrentWindow()
+ const focused = await win.isFocused().catch(() => document.hasFocus())
+ if (focused) return
+
+ await Promise.resolve()
+ .then(() => {
+ const notification = new Notification(title, { body: description ?? "" })
+ notification.onclick = () => {
+ const win = getCurrentWindow()
+ void win.show().catch(() => undefined)
+ void win.unminimize().catch(() => undefined)
+ void win.setFocus().catch(() => undefined)
+ if (href) {
+ window.history.pushState(null, "", href)
+ window.dispatchEvent(new PopStateEvent("popstate"))
+ }
+ notification.close()
+ }
+ })
+ .catch(() => undefined)
+ },
+
// @ts-expect-error
fetch: tauriFetch,
}