2023-06-12 21:15:23 +10:00
|
|
|
import { atom } from 'jotai';
|
|
|
|
|
|
|
|
|
|
const STORAGE_KEY = 'settings';
|
2026-03-27 06:20:10 -04:00
|
|
|
export type DateFormat =
|
|
|
|
|
| 'D MMM YYYY'
|
|
|
|
|
| 'DD/MM/YYYY'
|
|
|
|
|
| 'MM/DD/YYYY'
|
|
|
|
|
| 'YYYY/MM/DD'
|
|
|
|
|
| 'YYYY-MM-DD'
|
|
|
|
|
| '';
|
2023-10-06 13:44:06 +11:00
|
|
|
export type MessageSpacing = '0' | '100' | '200' | '300' | '400' | '500';
|
2026-05-21 20:49:33 -04:00
|
|
|
export type ChatBackground =
|
|
|
|
|
| 'none'
|
|
|
|
|
| 'blueprint'
|
|
|
|
|
| 'carbon'
|
|
|
|
|
| 'stars'
|
|
|
|
|
| 'topographic'
|
|
|
|
|
| 'herringbone'
|
|
|
|
|
| 'crosshatch'
|
|
|
|
|
| 'chevron'
|
|
|
|
|
| 'polka'
|
|
|
|
|
| 'triangles'
|
|
|
|
|
| 'plaid'
|
|
|
|
|
| 'tactical'
|
|
|
|
|
| 'circuit'
|
|
|
|
|
| 'hexgrid'
|
|
|
|
|
| 'waves'
|
|
|
|
|
| 'neon'
|
|
|
|
|
| 'aurora';
|
2025-02-10 16:49:47 +11:00
|
|
|
export enum MessageLayout {
|
|
|
|
|
Modern = 0,
|
|
|
|
|
Compact = 1,
|
|
|
|
|
Bubble = 2,
|
|
|
|
|
}
|
2023-10-19 17:43:16 +11:00
|
|
|
|
2023-06-12 21:15:23 +10:00
|
|
|
export interface Settings {
|
2025-02-10 16:49:47 +11:00
|
|
|
themeId?: string;
|
2023-06-12 21:15:23 +10:00
|
|
|
useSystemTheme: boolean;
|
2025-02-10 16:49:47 +11:00
|
|
|
lightThemeId?: string;
|
|
|
|
|
darkThemeId?: string;
|
2025-08-25 18:49:14 +05:30
|
|
|
monochromeMode?: boolean;
|
2023-06-12 21:15:23 +10:00
|
|
|
isMarkdown: boolean;
|
|
|
|
|
editorToolbar: boolean;
|
2023-10-26 09:09:27 +11:00
|
|
|
twitterEmoji: boolean;
|
2024-07-23 19:22:53 +05:30
|
|
|
pageZoom: number;
|
2025-02-26 21:44:53 +11:00
|
|
|
hideActivity: boolean;
|
2026-05-28 19:28:52 -04:00
|
|
|
hidePresence: boolean;
|
2026-05-30 23:29:29 -04:00
|
|
|
presenceStatus: 'auto' | 'online' | 'idle' | 'dnd' | 'invisible';
|
2023-06-12 21:15:23 +10:00
|
|
|
|
2023-10-19 17:43:16 +11:00
|
|
|
isPeopleDrawer: boolean;
|
|
|
|
|
memberSortFilterIndex: number;
|
2023-10-18 13:15:30 +11:00
|
|
|
enterForNewline: boolean;
|
2023-10-06 13:44:06 +11:00
|
|
|
messageLayout: MessageLayout;
|
|
|
|
|
messageSpacing: MessageSpacing;
|
2023-06-12 21:15:23 +10:00
|
|
|
hideMembershipEvents: boolean;
|
|
|
|
|
hideNickAvatarEvents: boolean;
|
2023-10-06 13:44:06 +11:00
|
|
|
mediaAutoLoad: boolean;
|
2023-10-30 07:14:58 +11:00
|
|
|
urlPreview: boolean;
|
|
|
|
|
encUrlPreview: boolean;
|
2023-10-06 13:44:06 +11:00
|
|
|
showHiddenEvents: boolean;
|
2025-03-23 22:09:29 +11:00
|
|
|
legacyUsernameColor: boolean;
|
2023-06-12 21:15:23 +10:00
|
|
|
|
|
|
|
|
showNotifications: boolean;
|
|
|
|
|
isNotificationSounds: boolean;
|
2025-02-10 16:49:47 +11:00
|
|
|
|
2025-07-27 15:13:00 +03:00
|
|
|
hour24Clock: boolean;
|
|
|
|
|
dateFormatString: string;
|
|
|
|
|
|
2025-02-10 16:49:47 +11:00
|
|
|
developerTools: boolean;
|
2026-05-13 22:22:06 -04:00
|
|
|
lotusTerminal: boolean;
|
2026-05-13 21:17:59 -04:00
|
|
|
|
|
|
|
|
chatBackground: ChatBackground;
|
|
|
|
|
perMessageProfiles: boolean;
|
2026-05-14 11:07:10 -04:00
|
|
|
|
|
|
|
|
cameraOnJoin: boolean;
|
|
|
|
|
callNoiseSuppression: boolean;
|
|
|
|
|
pttMode: boolean;
|
|
|
|
|
pttKey: string;
|
2023-06-12 21:15:23 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const defaultSettings: Settings = {
|
2025-02-10 16:49:47 +11:00
|
|
|
themeId: undefined,
|
2023-06-12 21:15:23 +10:00
|
|
|
useSystemTheme: true,
|
2025-02-10 16:49:47 +11:00
|
|
|
lightThemeId: undefined,
|
|
|
|
|
darkThemeId: undefined,
|
2025-08-25 18:49:14 +05:30
|
|
|
monochromeMode: false,
|
2023-10-27 21:27:22 +11:00
|
|
|
isMarkdown: true,
|
2023-06-12 21:15:23 +10:00
|
|
|
editorToolbar: false,
|
2023-10-26 09:09:27 +11:00
|
|
|
twitterEmoji: false,
|
2024-07-23 19:22:53 +05:30
|
|
|
pageZoom: 100,
|
2025-02-26 21:44:53 +11:00
|
|
|
hideActivity: false,
|
2026-05-28 19:28:52 -04:00
|
|
|
hidePresence: false,
|
2026-05-30 23:29:29 -04:00
|
|
|
presenceStatus: 'auto',
|
2023-06-12 21:15:23 +10:00
|
|
|
|
2023-10-19 17:43:16 +11:00
|
|
|
isPeopleDrawer: true,
|
|
|
|
|
memberSortFilterIndex: 0,
|
2023-10-18 13:15:30 +11:00
|
|
|
enterForNewline: false,
|
2023-10-06 13:44:06 +11:00
|
|
|
messageLayout: 0,
|
|
|
|
|
messageSpacing: '400',
|
2023-06-12 21:15:23 +10:00
|
|
|
hideMembershipEvents: false,
|
|
|
|
|
hideNickAvatarEvents: true,
|
2023-10-06 13:44:06 +11:00
|
|
|
mediaAutoLoad: true,
|
2023-10-30 07:14:58 +11:00
|
|
|
urlPreview: true,
|
|
|
|
|
encUrlPreview: false,
|
2023-10-06 13:44:06 +11:00
|
|
|
showHiddenEvents: false,
|
2025-03-23 22:09:29 +11:00
|
|
|
legacyUsernameColor: false,
|
2023-06-12 21:15:23 +10:00
|
|
|
|
|
|
|
|
showNotifications: true,
|
|
|
|
|
isNotificationSounds: true,
|
2025-02-10 16:49:47 +11:00
|
|
|
|
2025-07-27 15:13:00 +03:00
|
|
|
hour24Clock: false,
|
|
|
|
|
dateFormatString: 'D MMM YYYY',
|
|
|
|
|
|
2025-02-10 16:49:47 +11:00
|
|
|
developerTools: false,
|
2026-05-13 22:22:06 -04:00
|
|
|
lotusTerminal: false,
|
2026-05-13 21:17:59 -04:00
|
|
|
|
|
|
|
|
chatBackground: 'none',
|
|
|
|
|
perMessageProfiles: false,
|
2026-05-14 11:07:10 -04:00
|
|
|
|
|
|
|
|
cameraOnJoin: false,
|
|
|
|
|
callNoiseSuppression: true,
|
|
|
|
|
pttMode: false,
|
|
|
|
|
pttKey: 'Space',
|
2023-06-12 21:15:23 +10:00
|
|
|
};
|
|
|
|
|
|
2026-05-20 21:11:38 -04:00
|
|
|
export const getSettings = (): Settings => {
|
|
|
|
|
try {
|
|
|
|
|
const settings = localStorage.getItem(STORAGE_KEY);
|
|
|
|
|
if (settings === null) return defaultSettings;
|
|
|
|
|
return { ...defaultSettings, ...(JSON.parse(settings) as Settings) };
|
|
|
|
|
} catch {
|
|
|
|
|
localStorage.removeItem(STORAGE_KEY);
|
|
|
|
|
return defaultSettings;
|
|
|
|
|
}
|
2023-06-12 21:15:23 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const setSettings = (settings: Settings) => {
|
2026-05-21 20:49:33 -04:00
|
|
|
try {
|
|
|
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
|
|
|
|
|
} catch {
|
|
|
|
|
/* quota */
|
|
|
|
|
}
|
2023-06-12 21:15:23 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const baseSettings = atom<Settings>(getSettings());
|
2024-01-21 23:50:56 +11:00
|
|
|
export const settingsAtom = atom<Settings, [Settings], undefined>(
|
2023-06-12 21:15:23 +10:00
|
|
|
(get) => get(baseSettings),
|
|
|
|
|
(get, set, update) => {
|
|
|
|
|
set(baseSettings, update);
|
|
|
|
|
setSettings(update);
|
2026-05-21 23:30:50 -04:00
|
|
|
},
|
2023-06-12 21:15:23 +10:00
|
|
|
);
|