(keyValue: Record<T, Config[T]>)
| 18 | const firstUpdateRef = useRef(true); |
| 19 | |
| 20 | function safeSetConfig<T extends keyof Config>(keyValue: Record<T, Config[T]>) { |
| 21 | const entry = Object.entries(keyValue)[0]!; |
| 22 | const key = entry[0] as T; |
| 23 | const value = entry[1] as Config[T]; |
| 24 | |
| 25 | // Prevent flood-saving all config during mount |
| 26 | if (firstUpdateRef.current) return; |
| 27 | |
| 28 | if (isDev) console.log('save', key, value); |
| 29 | try { |
| 30 | configStore.set(key, value); |
| 31 | } catch (err) { |
| 32 | console.error('Failed to set config', key, err); |
| 33 | errorToast(i18n.t('Unable to save your preferences. Try to disable any anti-virus')); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | function safeGetConfig<T extends keyof Config>(key: T) { |
| 38 | const rawVal = configStore.get(key); |
no test coverage detected