MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / initAppConfig

Function initAppConfig

apps/desktop/src/main/app-config.ts:599–628  ·  view source on GitHub ↗
(
  onChange: (next: AppConfigPortable) => void
)

Source from the content-addressed store, hash-verified

597 * the preload reads at startup returns real data.
598 */
599export 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. */
631export function getPortableConfigSnapshot(): AppConfigPortable {

Callers 2

index.tsFile · 0.90
app-config.test.tsFile · 0.90

Calls 6

writeFileAtomicFunction · 0.90
serializeConfigFunction · 0.85
rememberOwnWriteFunction · 0.85
getConfigFilePathFunction · 0.85
startWatchingFunction · 0.85
readConfigFileFunction · 0.70

Tested by

no test coverage detected