2018-10-06 18:50:06 +00:00
|
|
|
import * as fs from 'fs'
|
|
|
|
import * as path from 'path'
|
|
|
|
import * as yaml from 'js-yaml'
|
|
|
|
import { app } from 'electron'
|
|
|
|
|
2021-06-29 21:57:04 +00:00
|
|
|
export function migrateConfig (): void {
|
|
|
|
const configPath = path.join(app.getPath('userData'), 'config.yaml')
|
|
|
|
const legacyConfigPath = path.join(app.getPath('userData'), '../terminus', 'config.yaml')
|
|
|
|
if (fs.existsSync(legacyConfigPath) && (
|
|
|
|
!fs.existsSync(configPath) ||
|
|
|
|
fs.statSync(configPath).mtime < fs.statSync(legacyConfigPath).mtime
|
|
|
|
)) {
|
|
|
|
fs.writeFileSync(configPath, fs.readFileSync(legacyConfigPath))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-06 18:50:06 +00:00
|
|
|
export function loadConfig (): any {
|
2021-06-29 21:57:04 +00:00
|
|
|
migrateConfig()
|
|
|
|
|
2020-12-24 13:03:14 +00:00
|
|
|
const configPath = path.join(app.getPath('userData'), 'config.yaml')
|
2018-10-06 18:50:06 +00:00
|
|
|
if (fs.existsSync(configPath)) {
|
2021-01-28 20:52:11 +00:00
|
|
|
return yaml.load(fs.readFileSync(configPath, 'utf8'))
|
2018-10-06 18:50:06 +00:00
|
|
|
} else {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|