From 05b6e01dc89298f40b762982773729b0e0cc5f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Wed, 30 Sep 2026 15:38:22 +0200 Subject: [PATCH] Set the dock badge in one place The sidebar already follows the count, so the inbox and the poll don't need to set it too. --- src/components/AppSidebar.svelte | 26 ++++++++------------------ src/lib/notificationCount.svelte.ts | 13 +++++++++++++ src/views/Inbox.svelte | 24 +++++++----------------- tests/unit/notificationCount.test.ts | 11 +++++++++++ 4 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 tests/unit/notificationCount.test.ts diff --git a/src/components/AppSidebar.svelte b/src/components/AppSidebar.svelte index 0abf947e2..c59fd1048 100644 --- a/src/components/AppSidebar.svelte +++ b/src/components/AppSidebar.svelte @@ -10,9 +10,12 @@ import { checkRadicleCLI } from "@app/lib/checkRadicleCLI.svelte"; import { hints } from "@app/lib/hints"; import { dynamicInterval } from "@app/lib/interval"; - import { invoke } from "@app/lib/invoke"; import { modalStore, show } from "@app/lib/modal"; - import { notificationCount } from "@app/lib/notificationCount.svelte"; + import { + badgeCount, + notificationCount, + refreshNotificationCount, + } from "@app/lib/notificationCount.svelte"; import * as router from "@app/lib/router"; import type { SidebarData } from "@app/lib/router/definitions"; import { ariaKeyShortcuts, useShortcuts } from "@app/lib/shortcuts.svelte"; @@ -290,27 +293,14 @@ firstLaunchStorage.value = false; } - await updateNotificationCount(); - dynamicInterval("notificationCount", updateNotificationCount, 3_000); + await refreshNotificationCount(); + dynamicInterval("notificationCount", refreshNotificationCount, 3_000); }); - async function updateNotificationCount() { - notificationCount.value = await invoke("notification_count"); - if (window.__TAURI_INTERNALS__ && $badgeCounter) { - await getCurrentWindow().setBadgeCount( - notificationCount.value === 0 ? undefined : notificationCount.value, - ); - } else if (window.__TAURI_INTERNALS__) { - await getCurrentWindow().setBadgeCount(undefined); - } - } - $effect(() => { if (window.__TAURI_INTERNALS__) { void getCurrentWindow().setBadgeCount( - $badgeCounter && notificationCount.value > 0 - ? notificationCount.value - : undefined, + badgeCount(notificationCount.value, $badgeCounter), ); } }); diff --git a/src/lib/notificationCount.svelte.ts b/src/lib/notificationCount.svelte.ts index aec42b727..2ff714d33 100644 --- a/src/lib/notificationCount.svelte.ts +++ b/src/lib/notificationCount.svelte.ts @@ -1 +1,14 @@ +import { invoke } from "@app/lib/invoke"; + export const notificationCount = $state({ value: 0 }); + +export async function refreshNotificationCount() { + notificationCount.value = await invoke("notification_count"); +} + +export function badgeCount( + count: number, + enabled: boolean, +): number | undefined { + return enabled && count > 0 ? count : undefined; +} diff --git a/src/views/Inbox.svelte b/src/views/Inbox.svelte index 1756e340e..5ff8a38d2 100644 --- a/src/views/Inbox.svelte +++ b/src/views/Inbox.svelte @@ -1,13 +1,13 @@