GUI startup fixes if modem is not running

This commit is contained in:
Mashintime 2023-11-26 01:07:04 -05:00
parent 750d01bc92
commit a5c9014a15
2 changed files with 23 additions and 0 deletions

View file

@ -6,12 +6,18 @@ function buildURL(params, endpoint) {
}
async function apiGet(endpoint) {
try {
const response = await fetch(buildURL(settings.local, endpoint));
if (!response.ok) {
throw new Error(`REST response not ok: ${response.statusText}`);
}
const data = await response.json();
return data;
} catch(error) {
console.error("Error getting from REST:", error);
}
}
export async function apiPost(endpoint, payload = {}) {

View file

@ -3,6 +3,15 @@ import { getAudioDevices, getSerialDevices } from "./api";
let audioDevices = await getAudioDevices();
let serialDevices = await getSerialDevices();
//Dummy device data sent if unable to get devices from modem to prevent GUI crash
const skel = JSON.parse(`
[{
"api": "MME",
"id": "0000",
"name": "No devices received from modem",
"native_index": 0
}]`
)
export function loadAudioDevices() {
getAudioDevices().then((devices) => {
audioDevices = devices;
@ -16,10 +25,18 @@ export function loadSerialDevices() {
}
export function audioInputOptions() {
if ((audioDevices === undefined))
{
return skel;
}
return audioDevices.in;
}
export function audioOutputOptions() {
if ((audioDevices === undefined))
{
return skel;
}
return audioDevices.out;
}