Apply an externally-changed portable config (synced dotfile / hand-edit) * to the live store and the localStorage cache. Uses setState directly so it * doesn't re-trigger a write back out to the file.
(next: AppConfigPortable)
| 7390 | * to the live store and the localStorage cache. Uses setState directly so it |
| 7391 | * doesn't re-trigger a write back out to the file. */ |
| 7392 | function applyPortableConfig(next: AppConfigPortable): void { |
| 7393 | if (!next || typeof next !== 'object') return |
| 7394 | const current = collectPrefs(useStore.getState()) |
| 7395 | const merged = normalizePrefs({ ...current, ...(next as Partial<Prefs>) }) |
| 7396 | cachedInitialPrefs = merged |
| 7397 | try { |
| 7398 | localStorage.setItem(PREFS_KEY, JSON.stringify(merged)) |
| 7399 | } catch { |
| 7400 | /* ignore */ |
| 7401 | } |
| 7402 | const patch: Record<string, unknown> = {} |
| 7403 | const mergedRecord = merged as unknown as Record<string, unknown> |
| 7404 | for (const key of PORTABLE_PREF_KEYS) { |
| 7405 | patch[key] = mergedRecord[key] |
| 7406 | } |
| 7407 | useStore.setState(patch as Partial<Store>) |
| 7408 | } |
| 7409 | |
| 7410 | let configSyncInitialized = false |
| 7411 |
no test coverage detected