1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-02 11:44:01 +03:00
tabby/app/lib/config.ts

36 lines
1.2 KiB
TypeScript
Raw Normal View History

import * as fs from 'mz/fs'
2018-10-06 21:50:06 +03:00
import * as path from 'path'
import * as yaml from 'js-yaml'
import { app } from 'electron'
import writeFileAtomic from 'write-file-atomic'
2018-10-06 21:50:06 +03:00
2022-05-31 00:27:01 +03:00
export function migrateConfig (): void {
2021-06-30 00:57:04 +03:00
const configPath = path.join(app.getPath('userData'), 'config.yaml')
const legacyConfigPath = path.join(app.getPath('userData'), '../terminus', 'config.yaml')
2022-05-31 00:27:01 +03:00
if (fs.existsSync(legacyConfigPath) && (
!fs.existsSync(configPath) ||
fs.statSync(configPath).mtime < fs.statSync(legacyConfigPath).mtime
2021-06-30 00:57:04 +03:00
)) {
2022-05-31 00:27:01 +03:00
fs.writeFileSync(configPath, fs.readFileSync(legacyConfigPath))
2021-06-30 00:57:04 +03:00
}
}
2022-05-31 00:27:01 +03:00
export function loadConfig (): any {
migrateConfig()
2021-06-30 00:57:04 +03:00
2020-12-24 16:03:14 +03:00
const configPath = path.join(app.getPath('userData'), 'config.yaml')
2022-05-31 00:27:01 +03:00
if (fs.existsSync(configPath)) {
return yaml.load(fs.readFileSync(configPath, 'utf8'))
2018-10-06 21:50:06 +03:00
} else {
return {}
}
}
const configPath = path.join(app.getPath('userData'), 'config.yaml')
export async function saveConfig (content: string): Promise<void> {
await writeFileAtomic(configPath, content, { encoding: 'utf8' })
await writeFileAtomic(configPath + '.backup', content, { encoding: 'utf8' })
}