diff --git a/apps/frontend/src/ui/hooks/useNotifications.ts b/apps/frontend/src/ui/hooks/useNotifications.ts index 97c3bc62..0846143a 100644 --- a/apps/frontend/src/ui/hooks/useNotifications.ts +++ b/apps/frontend/src/ui/hooks/useNotifications.ts @@ -1,12 +1,14 @@ +import type { UnlistenFn } from '@tauri-apps/api/event'; import type { NotificationData } from '~ui/components/overlay/notifications/NotificationComponent'; import { events } from '@onelauncher/client/bindings'; -import { createSignal, onMount, type Signal } from 'solid-js'; +import { createSignal, onCleanup, onMount, type Signal } from 'solid-js'; type Notifications = Record; type OnUpdateFn = () => unknown; function useNotifications(onUpdate?: OnUpdateFn): Signal { const [notifications, setNotifications] = createSignal({}); + let unlisten: UnlistenFn | undefined; async function update(id: string, data: NotificationData) { setNotifications((notifications) => { @@ -25,7 +27,11 @@ function useNotifications(onUpdate?: OnUpdateFn): Signal { title: e.payload.event.type.replaceAll('_', ' '), message: e.payload.message, fraction: e.payload.fraction ?? undefined, - })); + })).then(u => unlisten = u); + }); + + onCleanup(() => { + unlisten?.(); }); return [notifications, setNotifications];