mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
GUI startup fixes if modem is not running
This commit is contained in:
parent
750d01bc92
commit
a5c9014a15
2 changed files with 23 additions and 0 deletions
|
@ -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 = {}) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue