2023-03-06 07:21:29 -05:00
|
|
|
import { fs } from "@tauri-apps/api"
|
|
|
|
|
import { appConfigDir, join } from '@tauri-apps/api/path'
|
2023-03-06 08:32:00 -05:00
|
|
|
import { State } from '../../../src/state';
|
2023-03-06 07:21:29 -05:00
|
|
|
|
2023-03-06 08:32:00 -05:00
|
|
|
const configFile = appConfigDir().then(c => join(c, 'config.json'));
|
|
|
|
|
const profileDir = appConfigDir().then(c => join(c, 'profile'));
|
2023-03-06 07:21:29 -05:00
|
|
|
|
2023-03-06 08:32:00 -05:00
|
|
|
export type Profile = {
|
|
|
|
|
state: State,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type Config = {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const defaultConfig: Config = {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function initFiles() {
|
|
|
|
|
await fs.createDir(await profileDir, { recursive: true });
|
|
|
|
|
await configFile;
|
|
|
|
|
}
|
|
|
|
|
initFiles().catch(console.error);
|
|
|
|
|
|
|
|
|
|
export async function getConfig(): Promise<Config> {
|
|
|
|
|
const config = await fs.readTextFile(await configFile);
|
|
|
|
|
try {
|
|
|
|
|
return JSON.parse(config);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return defaultConfig;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-06 07:21:29 -05:00
|
|
|
|
2023-03-06 08:32:00 -05:00
|
|
|
export async function setConfig(config: Config) {
|
|
|
|
|
await fs.writeTextFile(await configFile, JSON.stringify(config));
|
2023-03-06 07:21:29 -05:00
|
|
|
}
|