( onChange: (next: AppConfigPortable) => void )
| 597 | * the preload reads at startup returns real data. |
| 598 | */ |
| 599 | export async function initAppConfig( |
| 600 | onChange: (next: AppConfigPortable) => void |
| 601 | ): Promise<void> { |
| 602 | onChangeCb = onChange |
| 603 | const res = await readConfigFile() |
| 604 | if (res) { |
| 605 | cache = res.portable |
| 606 | // Normalize an existing file to the canonical, fully-documented form. Files |
| 607 | // written by older versions (or hand-trimmed) may be missing options, |
| 608 | // comments, or the example map tables — re-render so every option is shown. |
| 609 | // The user's set values are preserved; only presentation/missing keys change. |
| 610 | const canonical = serializeConfig(cache) |
| 611 | if (canonical !== res.text) { |
| 612 | lastKnownText = canonical |
| 613 | rememberOwnWrite(canonical) |
| 614 | try { |
| 615 | await writeFileAtomic(getConfigFilePath(), canonical) |
| 616 | } catch (err) { |
| 617 | console.error('Failed to normalize config.toml', err) |
| 618 | lastKnownText = res.text |
| 619 | } |
| 620 | } else { |
| 621 | lastKnownText = res.text |
| 622 | } |
| 623 | } else { |
| 624 | cache = {} |
| 625 | lastKnownText = null |
| 626 | } |
| 627 | startWatching() |
| 628 | } |
| 629 | |
| 630 | /** Synchronous snapshot for the preload's `sendSync` getter. */ |
| 631 | export function getPortableConfigSnapshot(): AppConfigPortable { |
no test coverage detected