Fix initial default app settings behavior when the user has no settings yet (#3601)
Fix initial default app settings behavior when the user has no settings yet. Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com>
This commit is contained in:
@ -441,21 +441,14 @@ export const readProjectSettingsFile = async (
|
|||||||
return configObj
|
return configObj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the app settings file, or creates an initial one if it doesn't exist.
|
||||||
|
*/
|
||||||
export const readAppSettingsFile = async () => {
|
export const readAppSettingsFile = async () => {
|
||||||
let settingsPath = await getAppSettingsFilePath()
|
let settingsPath = await getAppSettingsFilePath()
|
||||||
try {
|
|
||||||
await window.electron.stat(settingsPath)
|
|
||||||
} catch (e) {
|
|
||||||
if (e === 'ENOENT') {
|
|
||||||
const config = defaultAppSettings()
|
|
||||||
if (err(config)) return Promise.reject(config)
|
|
||||||
if (!config.settings?.app)
|
|
||||||
return Promise.reject(new Error('config.app is falsey'))
|
|
||||||
|
|
||||||
config.settings.app.project_directory = await getInitialDefaultDir()
|
// The file exists, read it and parse it.
|
||||||
return config
|
if (window.electron.exists(settingsPath)) {
|
||||||
}
|
|
||||||
}
|
|
||||||
const configToml = await window.electron.readFile(settingsPath)
|
const configToml = await window.electron.readFile(settingsPath)
|
||||||
const configObj = parseAppSettings(configToml)
|
const configObj = parseAppSettings(configToml)
|
||||||
if (err(configObj)) {
|
if (err(configObj)) {
|
||||||
@ -463,6 +456,19 @@ export const readAppSettingsFile = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return configObj
|
return configObj
|
||||||
|
}
|
||||||
|
|
||||||
|
// The file doesn't exist, create a new one.
|
||||||
|
// This defaultAppConfig is truly an empty object every time.
|
||||||
|
const defaultAppConfig = defaultAppSettings()
|
||||||
|
if (err(defaultAppConfig)) {
|
||||||
|
return Promise.reject(defaultAppConfig)
|
||||||
|
}
|
||||||
|
const initialDirConfig: DeepPartial<Configuration> = {
|
||||||
|
settings: { project: { directory: await getInitialDefaultDir() } },
|
||||||
|
}
|
||||||
|
const config = Object.assign(defaultAppConfig, initialDirConfig)
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
export const writeAppSettingsFile = async (tomlStr: string) => {
|
export const writeAppSettingsFile = async (tomlStr: string) => {
|
||||||
|
Reference in New Issue
Block a user