@setoelkahfi / svara / commits / 971de98

feat!: added file watcher to settings file

mellbacon committed Jul 12, 2023 at 18:51 UTC 971de9868ba23ca0180da69184d2d3316cb474c4
1 file changed +16 -7
src/config/config.ts
+16 -7
@@ -5,6 +5,7 @@ import { fs, path } from "@tauri-apps/api";
5 import { loadTheme } from "./themehandler";
6 import { Store } from "tauri-plugin-store-api";
7 import { setEditorFontFamily, setEditorFontSize } from "../lib/Editor.svelte";
8 +import { watch } from "tauri-plugin-fs-watch-api";
9
10 export const systemfonts = writable([]);
11 export const editorfont = writable("");
@@ -59,10 +60,10 @@ async function fireAction(callback: () => Promise<void>, args = []) {
60
61 export let appSettings: Store;
62 export async function getSettings() {
62 - const settings = {
63 - "nucleus.theme": "dark",
63 + const settings = JSON.stringify({
64 + "nucleus.theme": "Dark",
65 "editor.fontSize": 14,
65 - "editor.fontFamily": "Uno",
66 + "editor.fontFamily": "monospace",
67 "editor.autosave": false,
68 "nucleus.showKeybinds": false,
69 "nucleus.useExternalTerminal": true,
@@ -72,13 +73,21 @@ export async function getSettings() {
73 "terminal.internal": {
74 "profile": "powershell"
75 },
75 - };
76 + }, null, 4);
77 const appdataLocal = await path.appLocalDataDir();
78 + const settingsPath = `${appdataLocal}settings.json`;
79
78 - if (!await fs.exists(`${appdataLocal}/settings.json`)) {
79 - await fs.writeFile(`${appdataLocal}/settings.json`, JSON.stringify(settings, null, " "));
80 + if (!await fs.exists(settingsPath)) {
81 + await fs.writeFile(settingsPath, settings);
82 }
81 - appSettings = new Store(`${appdataLocal}/settings.json`);
83 + appSettings = new Store(settingsPath);
84 +
85 + await watch(
86 + settingsPath,
87 + async () => {
88 + await appSettings.load();
89 + }
90 + )
91 }
92
93 export async function loadDefaultSettings() {