Restore desktop notification sounds by default, add a persisted Play sound setting, and group notification permission and testing in a dedicated Notifications section.
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import { useCallback, useMemo } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { View } from "react-native";
|
|
import { withUnistyles } from "react-native-unistyles";
|
|
import { RotateCw } from "lucide-react-native";
|
|
import { Button } from "@/components/ui/button";
|
|
import { DesktopPermissionRow } from "@/desktop/components/desktop-permission-row";
|
|
import { useDesktopPermissions } from "@/desktop/permissions/use-desktop-permissions";
|
|
import { settingsStyles } from "@/styles/settings";
|
|
import { SettingsSection } from "@/screens/settings/settings-section";
|
|
|
|
const ThemedRotateCw = withUnistyles(RotateCw, (theme) => ({
|
|
size: theme.iconSize.md,
|
|
color: theme.colors.foregroundMuted,
|
|
}));
|
|
|
|
export function DesktopPermissionsSection() {
|
|
const { t } = useTranslation();
|
|
const {
|
|
isDesktopApp,
|
|
snapshot,
|
|
isRefreshing,
|
|
requestingPermission,
|
|
refreshPermissions,
|
|
requestPermission,
|
|
} = useDesktopPermissions();
|
|
|
|
const handleRefreshPress = useCallback(() => {
|
|
void refreshPermissions();
|
|
}, [refreshPermissions]);
|
|
|
|
const handleRequestMicrophone = useCallback(() => {
|
|
void requestPermission("microphone");
|
|
}, [requestPermission]);
|
|
|
|
const isBusy = isRefreshing || requestingPermission !== null;
|
|
|
|
const refreshIcon = useMemo(() => <ThemedRotateCw />, []);
|
|
|
|
const refreshButton = useMemo(
|
|
() => (
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
leftIcon={refreshIcon}
|
|
onPress={handleRefreshPress}
|
|
disabled={isBusy}
|
|
accessibilityLabel={t("settings.permissions.refreshAccessibility")}
|
|
>
|
|
{isRefreshing ? t("settings.permissions.refreshing") : t("settings.permissions.refresh")}
|
|
</Button>
|
|
),
|
|
[refreshIcon, handleRefreshPress, isBusy, isRefreshing, t],
|
|
);
|
|
|
|
const permissionLabels = useMemo(
|
|
() => ({
|
|
granted: t("settings.permissions.actions.granted"),
|
|
request: t("settings.permissions.actions.request"),
|
|
requesting: t("settings.permissions.actions.requesting"),
|
|
}),
|
|
[t],
|
|
);
|
|
|
|
if (!isDesktopApp) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<SettingsSection title={t("settings.permissions.title")} trailing={refreshButton}>
|
|
<View style={settingsStyles.card}>
|
|
<DesktopPermissionRow
|
|
title={t("settings.permissions.microphone")}
|
|
status={snapshot?.microphone ?? null}
|
|
isRequesting={requestingPermission === "microphone"}
|
|
onRequest={handleRequestMicrophone}
|
|
labels={permissionLabels}
|
|
/>
|
|
</View>
|
|
</SettingsSection>
|
|
);
|
|
}
|