import { merge } from "lodash"; import { readTomlFile, writeTomlFile } from "./utils/toml"; export const defaultSettings = { background: { background_color: "#202124" as string, background_color_popup: "#303134" as string, background_image_path: "" as string, }, style: { accent_color: "#8ab4f8" as string, blur_radius: 10 as number, dark_mode: true as boolean, font_family: "monospace" as string, font_scaling: 100, opacity: 0.8 as number, radius: 8 as number, transition_duration: 200 as number, window_height: 80 as number, window_width: 500 as number, }, window: { fullscreen_button: false as boolean, maximize_button: false as boolean, minimize_button: false as boolean, start_fullscreen: false as boolean, // TODO: this should be true on prod }, }; export type SettingsType = typeof defaultSettings; export const readConfigFile = async (): Promise => { let existingData: SettingsType = defaultSettings; try { const { appConfigDir } = await import("@tauri-apps/api/path"); const data = await readTomlFile((await appConfigDir()) + "/config.toml"); if (data) { existingData = data; console.log("existing data"); console.log(existingData); } } catch (error) { // file does not exist, called function will throw error console.error(`Failed to read settings file: ${error}, using default settings.`); existingData = defaultSettings; } // merge the existing data with the default settings // existing data will overwrite the default settings for the properties that exist const mergedSettings = merge({}, defaultSettings, existingData); return mergedSettings; }; export const writeConfigFile = async (settingsValues: SettingsType): Promise => { const { appConfigDir } = await import("@tauri-apps/api/path"); await writeTomlFile((await appConfigDir()) + "/config.toml", settingsValues); console.debug("Settings file written successfully."); };