| 1 | import { ClientSettingsSchema, type ClientSettings } from "@t3tools/contracts"; |
| 2 | |
| 3 | import { getLocalStorageItem, setLocalStorageItem } from "./hooks/useLocalStorage"; |
| 4 | |
| 5 | const CLIENT_SETTINGS_STORAGE_KEY = "t3code:client-settings:v1"; |
| 6 | |
| 7 | function hasWindow(): boolean { |
| 8 | return typeof window !== "undefined"; |
| 9 | } |
| 10 | |
| 11 | export function readBrowserClientSettings(): ClientSettings | null { |
| 12 | if (!hasWindow()) { |
| 13 | return null; |
| 14 | } |
| 15 | |
| 16 | return getLocalStorageItem(CLIENT_SETTINGS_STORAGE_KEY, ClientSettingsSchema); |
| 17 | } |
| 18 | |
| 19 | export function writeBrowserClientSettings(settings: ClientSettings): void { |
| 20 | if (!hasWindow()) { |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | setLocalStorageItem(CLIENT_SETTINGS_STORAGE_KEY, settings, ClientSettingsSchema); |
| 25 | } |