Skip to content

Commit

Permalink
Cache default value if the config file is not found, or if it contain…
Browse files Browse the repository at this point in the history
…s an invalid value
  • Loading branch information
mon-jai committed Aug 28, 2023
1 parent 043bbd3 commit ce1d3a9
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 ce1d3a9

Please sign in to comment.