diff --git a/.gitignore b/.gitignore index ce0407d4..1dd7a4ff 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,7 @@ coverage.xml #Ignore gui build items /gui/dist /gui/release -/gui/dist-electron \ No newline at end of file +/gui/dist-electron + +#Ignore GUI config +/gui/config/config.json \ No newline at end of file diff --git a/gui/config/example.json b/gui/config/example.json new file mode 100644 index 00000000..fdff55d3 --- /dev/null +++ b/gui/config/example.json @@ -0,0 +1,13 @@ +{ + "local": { + "host": "127.0.0.1", + "port": "5000", + "enable_fft": true, + "spectrum": "waterfall", + "wf_theme": 2, + "theme": "default_light", + "high_graphics": true, + "update_channel": "alpha", + "enable_sys_notification": false + } +} \ No newline at end of file diff --git a/gui/package.json b/gui/package.json index 66f51263..60ab89e4 100644 --- a/gui/package.json +++ b/gui/package.json @@ -51,6 +51,7 @@ "file-saver": "2.0.5", "gridstack": "10.0.0", "mime": "4.0.0", + "nconf": "^0.12.1", "pinia": "2.1.6", "pouchdb": "8.0.1", "pouchdb-browser": "8.0.1", @@ -65,6 +66,7 @@ "vuemoji-picker": "0.2.0" }, "devDependencies": { + "@types/nconf": "^0.10.6", "@typescript-eslint/eslint-plugin": "6.7.4", "@vitejs/plugin-vue": "4.5.2", "electron": "28.0.0", diff --git a/gui/src/store/settingsStore.js b/gui/src/store/settingsStore.js index 7b5ced0d..a04ac320 100644 --- a/gui/src/store/settingsStore.js +++ b/gui/src/store/settingsStore.js @@ -2,17 +2,43 @@ import { reactive, ref, watch } from "vue"; import { getConfig, setConfig } from "../js/api"; +var nconf = require( "nconf"); +nconf.file({file: 'config/config.json'}); + + +// +++ +//GUI DEFAULT SETTINGS........ +//Set GUI defaults here, they will be used if not found in config/config.json +//They should be an exact mirror (variable wise) of settingsStore.local +//Nothing else should be needed aslong as components are using v-bind +// +++ +nconf.defaults({ + local: { + host: "127.0.0.1", + port: "5000", + enable_fft: true, + spectrum: "waterfall", + wf_theme: 2, + theme: "default_light", + high_graphics: true, + update_channel: "alpha", + enable_sys_notification: false, + } +}); + +nconf.required(['local:host','local:port']); + export const settingsStore = reactive({ local: { host: "127.0.0.1", port: "5000", - enable_fft: false, + enable_fft: true, spectrum: "waterfall", - wf_theme: 0, + wf_theme: 2, theme: "default_light", high_graphics: true, update_channel: "alpha", - enable_sys_notification: true, + enable_sys_notification: false, }, remote: { AUDIO: { @@ -73,6 +99,10 @@ export const settingsStore = reactive({ }, }); +//Save settings for GUI to config file +settingsStore.local = nconf.get('local'); +saveSettingsToConfig(); + export function onChange() { setConfig(settingsStore.remote).then((conf) => { settingsStore.remote = conf; @@ -86,6 +116,13 @@ export function getRemote() { } watch(settingsStore.local, (oldValue, newValue) => { - // TODO handle local file saving - const cenas = newValue; + //This function watches for changes, and triggers a save of local settings + saveSettingsToConfig(); }); + +function saveSettingsToConfig() { + nconf.set('local',settingsStore.local); + nconf.save(); + console.log("Settings saved!"); +}; +