improved gui reconnecting

This commit is contained in:
DJ2LS 2024-02-10 13:57:18 +01:00
parent 17bce4b0db
commit ec34a690e9
3 changed files with 30 additions and 23 deletions

View file

@ -69,8 +69,11 @@ export async function getVersion() {
let data = await apiGet("/version").then((res) => { let data = await apiGet("/version").then((res) => {
return res; return res;
}); });
if (typeof data !== "undefined" && typeof data.version !== "undefined") {
return data.version; return data.version;
//return data["version"]; }
return 0;
} }
export async function getConfig() { export async function getConfig() {

View file

@ -24,7 +24,7 @@ setActivePinia(pinia);
import { useStateStore } from "../store/stateStore.js"; import { useStateStore } from "../store/stateStore.js";
const stateStore = useStateStore(pinia); 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) { export function connectionFailed(endpoint, event) {
stateStore.modem_connection = "disconnected"; stateStore.modem_connection = "disconnected";
@ -128,9 +128,16 @@ export function eventDispatcher(data) {
message = "Connected to server"; message = "Connected to server";
displayToast("success", "bi-ethernet", message, 5000); displayToast("success", "bi-ethernet", message, 5000);
stateStore.modem_connection = "connected"; stateStore.modem_connection = "connected";
getRemote().then(() => {
//initConnections();
getModemState();
});
//getConfig();
getModemState(); getModemState();
getOverallHealth(); getOverallHealth();
getConfig();
getAudioDevices(); getAudioDevices();
getSerialDevices(); getSerialDevices();
getFreedataMessages(); getFreedataMessages();

View file

@ -29,23 +29,8 @@ nconf.file({ file: configPath });
//They should be an exact mirror (variable wise) of settingsStore.local //They should be an exact mirror (variable wise) of settingsStore.local
//Nothing else should be needed aslong as components are using v-bind //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"]); const defaultConfig = {
export const settingsStore = reactive({
local: { local: {
host: "127.0.0.1", host: "127.0.0.1",
port: "5000", port: "5000",
@ -104,7 +89,7 @@ export const settingsStore = reactive({
STATION: { STATION: {
enable_explorer: false, enable_explorer: false,
enable_stats: false, enable_stats: false,
mycall: "", mycall: "DEFAULT",
myssid: 0, myssid: 0,
mygrid: "", mygrid: "",
ssid_list: [], ssid_list: [],
@ -114,7 +99,12 @@ export const settingsStore = reactive({
tci_port: 0, 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 //Save settings for GUI to config file
settingsStore.local = nconf.get("local"); settingsStore.local = nconf.get("local");
@ -128,10 +118,17 @@ export function onChange() {
export function getRemote() { export function getRemote() {
return getConfig().then((conf) => { return getConfig().then((conf) => {
if (typeof conf !== 'undefined') {
settingsStore.remote = conf; settingsStore.remote = conf;
onChange();
} else {
console.warn('Received undefined configuration, using default!');
settingsStore.remote = defaultConfig.remote;
}
}); });
} }
watch(settingsStore.local, (oldValue, newValue) => { watch(settingsStore.local, (oldValue, newValue) => {
//This function watches for changes, and triggers a save of local settings //This function watches for changes, and triggers a save of local settings
saveLocalSettingsToConfig(); saveLocalSettingsToConfig();