From ec34a690e9abbdd60a5e51944e57c332d625bcf0 Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Sat, 10 Feb 2024 13:57:18 +0100 Subject: [PATCH] improved gui reconnecting --- gui/src/js/api.js | 7 +++++-- gui/src/js/eventHandler.js | 11 +++++++++-- gui/src/store/settingsStore.js | 35 ++++++++++++++++------------------ 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/gui/src/js/api.js b/gui/src/js/api.js index e51c006b..e34b7ba6 100644 --- a/gui/src/js/api.js +++ b/gui/src/js/api.js @@ -69,8 +69,11 @@ export async function getVersion() { let data = await apiGet("/version").then((res) => { return res; }); - return data.version; - //return data["version"]; + + if (typeof data !== "undefined" && typeof data.version !== "undefined") { + return data.version; + } + return 0; } export async function getConfig() { diff --git a/gui/src/js/eventHandler.js b/gui/src/js/eventHandler.js index 0d8ca817..e0b4cd0c 100644 --- a/gui/src/js/eventHandler.js +++ b/gui/src/js/eventHandler.js @@ -24,7 +24,7 @@ setActivePinia(pinia); import { useStateStore } from "../store/stateStore.js"; const stateStore = useStateStore(pinia); -import { settingsStore as settings } from "../store/settingsStore.js"; +import { settingsStore as settings, getRemote } from "../store/settingsStore.js"; export function connectionFailed(endpoint, event) { stateStore.modem_connection = "disconnected"; @@ -128,9 +128,16 @@ export function eventDispatcher(data) { message = "Connected to server"; displayToast("success", "bi-ethernet", message, 5000); stateStore.modem_connection = "connected"; + + + getRemote().then(() => { + //initConnections(); + getModemState(); + }); + + //getConfig(); getModemState(); getOverallHealth(); - getConfig(); getAudioDevices(); getSerialDevices(); getFreedataMessages(); diff --git a/gui/src/store/settingsStore.js b/gui/src/store/settingsStore.js index f7ff0865..d3a480bc 100644 --- a/gui/src/store/settingsStore.js +++ b/gui/src/store/settingsStore.js @@ -29,23 +29,8 @@ nconf.file({ file: configPath }); //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", - spectrum: "waterfall", - wf_theme: 2, - update_channel: "alpha", - enable_sys_notification: false, - grid_layout: "[]", - grid_preset: "[]", - grid_enabled: true, - }, -}); -nconf.required(["local:host", "local:port"]); - -export const settingsStore = reactive({ +const defaultConfig = { local: { host: "127.0.0.1", port: "5000", @@ -104,7 +89,7 @@ export const settingsStore = reactive({ STATION: { enable_explorer: false, enable_stats: false, - mycall: "", + mycall: "DEFAULT", myssid: 0, mygrid: "", ssid_list: [], @@ -114,7 +99,12 @@ export const settingsStore = reactive({ tci_port: 0, }, }, -}); +} + +nconf.defaults(defaultConfig.local); +nconf.required(["local:host", "local:port"]); + +export const settingsStore = reactive(defaultConfig); //Save settings for GUI to config file settingsStore.local = nconf.get("local"); @@ -128,10 +118,17 @@ export function onChange() { export function getRemote() { return getConfig().then((conf) => { - settingsStore.remote = conf; + if (typeof conf !== 'undefined') { + settingsStore.remote = conf; + onChange(); + } else { + console.warn('Received undefined configuration, using default!'); + settingsStore.remote = defaultConfig.remote; + } }); } + watch(settingsStore.local, (oldValue, newValue) => { //This function watches for changes, and triggers a save of local settings saveLocalSettingsToConfig();