()
| 7416 | * external edits for live reload. |
| 7417 | */ |
| 7418 | export function initConfigSync(): void { |
| 7419 | if (configSyncInitialized) return |
| 7420 | const bridge = typeof window !== 'undefined' ? window.zen : undefined |
| 7421 | if (!bridge || typeof bridge.getConfigSync !== 'function') return |
| 7422 | if (!configFileEnabled) return |
| 7423 | configSyncInitialized = true |
| 7424 | |
| 7425 | // Migration for existing users: no config file yet → create one from their |
| 7426 | // current preferences so the dotfile starts as an exact mirror of today's |
| 7427 | // setup, no reconfiguration needed. |
| 7428 | if (!configFileHadContent && typeof bridge.setConfig === 'function') { |
| 7429 | try { |
| 7430 | const prefs = collectPrefs(useStore.getState()) |
| 7431 | void bridge.setConfig(pickPortablePrefs(prefs as unknown as Record<string, unknown>)) |
| 7432 | } catch { |
| 7433 | /* ignore */ |
| 7434 | } |
| 7435 | } |
| 7436 | |
| 7437 | if (typeof bridge.onConfigChange === 'function') { |
| 7438 | try { |
| 7439 | bridge.onConfigChange((nextCfg) => applyPortableConfig(nextCfg)) |
| 7440 | } catch { |
| 7441 | /* ignore */ |
| 7442 | } |
| 7443 | } |
| 7444 | } |
| 7445 | |
| 7446 | function applyCustomThemes(themes: CustomTheme[]): void { |
| 7447 | useStore.setState({ customThemes: themes }) |
no test coverage detected