Skip to content

Commit

Permalink
GUI startup fixes if modem is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
Mashintime committed Nov 26, 2023
1 parent 750d01b commit a5c9014
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gui/src/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ function buildURL(params, endpoint) {
}

async function apiGet(endpoint) {
try {

Check warning on line 9 in gui/src/js/api.js

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/api.js#L9

Delete `·` (prettier/prettier)
const response = await fetch(buildURL(settings.local, endpoint));

Check warning on line 10 in gui/src/js/api.js

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/api.js#L10

Insert `··` (prettier/prettier)
if (!response.ok) {

Check warning on line 11 in gui/src/js/api.js

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/api.js#L11

Insert `··` (prettier/prettier)
throw new Error(`REST response not ok: ${response.statusText}`);

Check warning on line 12 in gui/src/js/api.js

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/api.js#L12

Replace `····` with `······` (prettier/prettier)
}

Check warning on line 13 in gui/src/js/api.js

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/api.js#L13

Insert `··` (prettier/prettier)
const data = await response.json();

Check warning on line 14 in gui/src/js/api.js

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/api.js#L14

Insert `··` (prettier/prettier)
return data;

Check warning on line 15 in gui/src/js/api.js

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/api.js#L15

Replace `··` with `····` (prettier/prettier)
} catch(error) {

Check warning on line 16 in gui/src/js/api.js

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/api.js#L16

Replace `··catch(error)·` with `catch·(error)` (prettier/prettier)
console.error("Error getting from REST:", error);
}

Check warning on line 18 in gui/src/js/api.js

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/api.js#L18

Delete `⏎···⏎·` (prettier/prettier)


}

export async function apiPost(endpoint, payload = {}) {
Expand Down
17 changes: 17 additions & 0 deletions gui/src/js/deviceFormHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}]`

Check warning on line 13 in gui/src/js/deviceFormHelper.ts

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/deviceFormHelper.ts#L13

Replace `⏎)` with `);` (prettier/prettier)
)
export function loadAudioDevices() {
getAudioDevices().then((devices) => {
audioDevices = devices;
Expand All @@ -16,10 +25,18 @@ export function loadSerialDevices() {
}

export function audioInputOptions() {
if ((audioDevices === undefined))

Check warning on line 28 in gui/src/js/deviceFormHelper.ts

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/deviceFormHelper.ts#L28

Replace `(audioDevices·===·undefined))⏎·` with `audioDevices·===·undefined)` (prettier/prettier)
{
return skel;
}
return audioDevices.in;
}

export function audioOutputOptions() {
if ((audioDevices === undefined))

Check warning on line 36 in gui/src/js/deviceFormHelper.ts

View check run for this annotation

codefactor.io / CodeFactor

gui/src/js/deviceFormHelper.ts#L36

Replace `(audioDevices·===·undefined))⏎·` with `audioDevices·===·undefined)` (prettier/prettier)
{
return skel;
}
return audioDevices.out;
}

Expand Down

0 comments on commit a5c9014

Please sign in to comment.