Skip to content

Commit

Permalink
Cache the default value if the config file is not found, or if it con…
Browse files Browse the repository at this point in the history
…tains an invalid value
  • Loading branch information
mon-jai authored and shiftkey committed Sep 2, 2023
1 parent 9876013 commit 4dd2c4c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions app/src/lib/get-title-bar-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@ export function readTitleBarConfigFileSync(): TitleBarConfig {
const titleBarConfigPath = getTitleBarConfigPath()

if (existsSync(titleBarConfigPath)) {
const titleBarConfig = JSON.parse(
readFileSync(getTitleBarConfigPath(), 'utf8')
const storedTitleBarConfig = JSON.parse(
readFileSync(titleBarConfigPath, 'utf8')
)

// Return if we found valid values
if (
titleBarConfig.titleBarStyle === 'native' ||
titleBarConfig.titleBarStyle === 'custom'
storedTitleBarConfig.titleBarStyle === 'native' ||
storedTitleBarConfig.titleBarStyle === 'custom'
) {
cachedTitleBarConfig = titleBarConfig
return titleBarConfig
cachedTitleBarConfig = storedTitleBarConfig
}
}

// Return the default value if the config file is not found, or if it contains an invalid value.
return { titleBarStyle: 'native' }
// Cache the default value if the config file is not found, or if it contains an invalid value.
if (cachedTitleBarConfig == null) {
cachedTitleBarConfig = { titleBarStyle: 'native' }
}

return cachedTitleBarConfig
}

export function saveTitleBarConfigFile(config: TitleBarConfig) {
Expand Down

0 comments on commit 4dd2c4c

Please sign in to comment.