fix(desktop): restore notification sounds (#2582)

Restore desktop notification sounds by default, add a persisted Play sound setting, and group notification permission and testing in a dedicated Notifications section.
This commit is contained in:
Glen Stampoultzis
2026-08-08 22:28:37 +02:00
committed by GitHub
parent b19db9537c
commit b9b3a24d58
24 changed files with 451 additions and 123 deletions
@@ -14,13 +14,18 @@ export interface UseDesktopPermissionsReturn {
snapshot: DesktopPermissionSnapshot | null;
isRefreshing: boolean;
requestingPermission: DesktopPermissionKind | null;
isSendingTestNotification: boolean;
testNotificationError: string | null;
testNotificationState: TestNotificationState;
refreshPermissions: () => Promise<void>;
requestPermission: (kind: DesktopPermissionKind) => Promise<void>;
sendTestNotification: () => Promise<void>;
}
export type TestNotificationState =
| { status: "idle" }
| { status: "sending" }
| { status: "success" }
| { status: "error"; message: string };
export function useDesktopPermissions(): UseDesktopPermissionsReturn {
const { t } = useTranslation();
const isDesktopApp = shouldShowDesktopPermissionSection();
@@ -30,7 +35,9 @@ export function useDesktopPermissions(): UseDesktopPermissionsReturn {
const [requestingPermission, setRequestingPermission] = useState<DesktopPermissionKind | null>(
null,
);
const [isSendingTestNotification, setIsSendingTestNotification] = useState(false);
const [testNotificationState, setTestNotificationState] = useState<TestNotificationState>({
status: "idle",
});
useEffect(() => {
return () => {
@@ -111,28 +118,34 @@ export function useDesktopPermissions(): UseDesktopPermissionsReturn {
[isDesktopApp, refreshPermissions, t],
);
const [testNotificationError, setTestNotificationError] = useState<string | null>(null);
const sendTestNotification = useCallback(async () => {
if (!isDesktopApp) {
return;
}
setIsSendingTestNotification(true);
setTestNotificationError(null);
setTestNotificationState({ status: "sending" });
try {
const sent = await sendOsNotification({
title: t("desktop.permissions.testNotification.title"),
body: t("desktop.permissions.testNotification.body"),
});
if (!sent) {
setTestNotificationError(t("desktop.permissions.testNotification.notDelivered"));
if (!isMountedRef.current) {
return;
}
setTestNotificationState(
sent
? { status: "success" }
: {
status: "error",
message: t("desktop.permissions.testNotification.notDelivered"),
},
);
} catch {
setTestNotificationError(t("desktop.permissions.testNotification.failed"));
} finally {
if (isMountedRef.current) {
setIsSendingTestNotification(false);
setTestNotificationState({
status: "error",
message: t("desktop.permissions.testNotification.failed"),
});
}
}
}, [isDesktopApp, t]);
@@ -150,8 +163,7 @@ export function useDesktopPermissions(): UseDesktopPermissionsReturn {
snapshot,
isRefreshing,
requestingPermission,
isSendingTestNotification,
testNotificationError,
testNotificationState,
refreshPermissions,
requestPermission,
sendTestNotification,