🏷️ Search for custom tailnet name offers with keywords.
1import { useCallback, useEffect, useState } from 'react';
2
3export const useNotificationSettings = () => {
4 const [notificationsEnabled, setNotificationsEnabled] = useState<
5 boolean | null
6 >(null);
7
8 const fetchNotificationSettings = useCallback(() => {
9 browser.storage.local.get(['useSystemPush', 'useNtfyPush'], (result) => {
10 const enabled =
11 Boolean(result.useSystemPush) || Boolean(result.useNtfyPush);
12 setNotificationsEnabled(enabled);
13 });
14 }, []);
15
16 useEffect(() => {
17 fetchNotificationSettings();
18 }, [fetchNotificationSettings]);
19
20 useEffect(() => {
21 const handleStorageChange = (
22 changes: Record<string, Browser.storage.StorageChange>,
23 areaName: string,
24 ) => {
25 if (
26 areaName === 'local' &&
27 ('useSystemPush' in changes || 'useNtfyPush' in changes)
28 ) {
29 fetchNotificationSettings();
30 }
31 };
32 browser.storage.onChanged.addListener(handleStorageChange);
33 return () => {
34 browser.storage.onChanged.removeListener(handleStorageChange);
35 };
36 }, [fetchNotificationSettings]);
37
38 return notificationsEnabled;
39};