[CodeFactor] Apply fixes

This commit is contained in:
codefactor-io 2024-03-04 10:42:55 +00:00
parent eeb72faf83
commit a258f4b16f
No known key found for this signature in database
GPG Key ID: B66B2D63282C190F
10 changed files with 182 additions and 181 deletions

View File

@ -74,7 +74,7 @@ async function createWindow() {
// Test actively push message to the Electron-Renderer
//win.webContents.on("did-finish-load", () => {
// win?.webContents.send("main-process-message", new Date().toLocaleString());
// win?.webContents.send("main-process-message", new Date().toLocaleString());
//});
// Make all links open with the browser, not with the application
@ -96,60 +96,62 @@ app.whenReady().then(() => {
console.log(platform());
//Generate daemon binary path
var serverPath = "";
console.log(process.env)
console.log(process.env);
// Attempt to find Installation Folder
console.log(app.getAppPath())
console.log(join(app.getAppPath(), '..', '..'))
console.log(join(app.getAppPath(), '..', '..', '..'))
console.log(app.getAppPath());
console.log(join(app.getAppPath(), "..", ".."));
console.log(join(app.getAppPath(), "..", "..", ".."));
//var basePath = join(app.getAppPath(), '..', '..', '..') || join(process.env.PWD, '..') || join(process.env.INIT_CWD, '..') || join(process.env.DIST, '..', '..', '..');
var basePath = join(app.getAppPath(), '..', '..', '..')
var basePath = join(app.getAppPath(), "..", "..", "..");
switch (platform().toLowerCase()) {
//case "darwin":
//serverPath = join(basePath, "freedata-server", "freedata-server.exe");
//serverProcess = spawn(serverPath, [], { detached: true });
//serverProcess.unref(); // Allow the server process to continue running independently of the parent process
// break;
//serverPath = join(basePath, "freedata-server", "freedata-server.exe");
//serverProcess = spawn(serverPath, [], { detached: true });
//serverProcess.unref(); // Allow the server process to continue running independently of the parent process
// break;
//case "linux":
//serverPath = join(basePath, "freedata-server", "freedata-server.exe");
//serverProcess = spawn(serverPath, [], { detached: true });
//serverProcess.unref(); // Allow the server process to continue running independently of the parent process
// break;
//serverPath = join(basePath, "freedata-server", "freedata-server.exe");
//serverProcess = spawn(serverPath, [], { detached: true });
//serverProcess.unref(); // Allow the server process to continue running independently of the parent process
// break;
case "win32":
serverPath = join(basePath, "freedata-server", "freedata-server.exe");
console.log(`Starting server with path: ${serverPath}`);
serverProcess = spawn('cmd.exe', ['/c', 'start', 'cmd.exe', '/c', serverPath], { shell: true });
console.log(`Started server | PID: ${serverProcess.pid}`);
break;
serverPath = join(basePath, "freedata-server", "freedata-server.exe");
console.log(`Starting server with path: ${serverPath}`);
serverProcess = spawn(
"cmd.exe",
["/c", "start", "cmd.exe", "/c", serverPath],
{ shell: true },
);
console.log(`Started server | PID: ${serverProcess.pid}`);
break;
default:
console.log("Unhandled OS Platform: ", platform());
serverProcess = null;
serverPath = null;
break;
console.log("Unhandled OS Platform: ", platform());
serverProcess = null;
serverPath = null;
break;
}
serverProcess.on('error', (err) => {
console.error('Failed to start server process:', err);
serverProcess = null;
serverProcess.on("error", (err) => {
console.error("Failed to start server process:", err);
serverProcess = null;
serverPath = null;
});
serverProcess.stdout.on('data', (data) => {
//console.log(`stdout: ${data}`);
});
serverProcess.stdout.on("data", (data) => {
//console.log(`stdout: ${data}`);
});
serverProcess.stderr.on("data", (data) => {
console.error(`stderr: ${data}`);
});
});
serverProcess.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
app.on("before-quit", () => {
close_sub_processes();
});
});
app.on('before-quit', () => {
close_sub_processes();
});
app.on("window-all-closed", () => {
win = null;
if (process.platform !== "darwin") app.quit();
@ -190,33 +192,32 @@ ipcMain.handle("open-win", (_, arg) => {
});
function close_sub_processes() {
console.log("Closing sub processes...");
console.log("Closing sub processes...");
if (serverProcess != null) {
try {
console.log(`Killing server process with PID: ${serverProcess.pid}`);
if (serverProcess != null) {
try {
console.log(`Killing server process with PID: ${serverProcess.pid}`);
switch (platform().toLowerCase()) {
//case "darwin":
switch (platform().toLowerCase()) {
//case "darwin":
// process.kill(serverProcess.pid);
// break;
//case "linux":
// process.kill(serverProcess.pid);
//case "linux":
// process.kill(serverProcess.pid);
// break;
case "win32":
// For Windows, use taskkill to ensure all child processes are also terminated
spawn("taskkill", ["/pid", serverProcess.pid.toString(), "/f", "/t"]);
break;
case "win32":
// For Windows, use taskkill to ensure all child processes are also terminated
spawn("taskkill", ["/pid", serverProcess.pid.toString(), "/f", "/t"]);
break;
default:
console.log("Unhandled OS Platform: ", platform());
serverProcess = null;
serverPath = null;
break;
}
} catch (error) {
console.error(`Error killing server process: ${error}`);
}
default:
console.log("Unhandled OS Platform: ", platform());
serverProcess = null;
serverPath = null;
break;
}
} catch (error) {
console.error(`Error killing server process: ${error}`);
}
}
}
}

View File

@ -23,17 +23,11 @@ import Dynamic_components from "./dynamic_components.vue";
import { getFreedataMessages } from "../js/api";
import { getRemote } from "../store/settingsStore.js";
import { loadAllData } from "../js/eventHandler";
</script>
<template>
<!-------------------------------- INFO TOASTS ---------------->
<div
aria-live="polite"
aria-atomic="true"
class="position-relative z-3"
>
<div aria-live="polite" aria-atomic="true" class="position-relative z-3">
<div
class="toast-container position-absolute top-0 end-0 p-3"
id="mainToastContainer"

View File

@ -2,7 +2,6 @@
import { Modal } from "bootstrap";
import { onMounted } from "vue";
import { setActivePinia } from "pinia";
import pinia from "../store/index";
setActivePinia(pinia);
@ -18,7 +17,6 @@ const audioStore = useAudioStore();
import { useSerialStore } from "../store/serialStore";
const serialStore = useSerialStore();
import {
getVersion,
setConfig,
@ -27,8 +25,6 @@ import {
getModemState,
} from "../js/api";
const version = import.meta.env.PACKAGE_VERSION;
// start modemCheck modal once on startup
@ -39,8 +35,6 @@ onMounted(() => {
new Modal("#modemCheck", {}).show();
});
function getModemStateLocal() {
// Returns active/inactive if modem is running for modem status label
if (state.is_modem_running == true) return "Active";
@ -210,28 +204,45 @@ function testHamlib() {
</label>
</div>
<!-- Audio Input Device -->
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50">Audio Input device</label>
<select class="form-select form-select-sm" aria-label=".form-select-sm" @change="onChange" v-model="settings.remote.AUDIO.input_device">
<option v-for="device in audioStore.audioInputs" :value="device.id">
{{ device.name }} [{{ device.api }}]
</option>
</select>
</div>
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50"
>Audio Input device</label
>
<select
class="form-select form-select-sm"
aria-label=".form-select-sm"
@change="onChange"
v-model="settings.remote.AUDIO.input_device"
>
<option
v-for="device in audioStore.audioInputs"
:value="device.id"
>
{{ device.name }} [{{ device.api }}]
</option>
</select>
</div>
<!-- Audio Output Device -->
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50">Audio Output device</label>
<select class="form-select form-select-sm" aria-label=".form-select-sm" @change="onChange" v-model="settings.remote.AUDIO.output_device">
<option v-for="device in audioStore.audioOutputs" :value="device.id">
{{ device.name }} [{{ device.api }}]
</option>
</select>
</div>
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50"
>Audio Output device</label
>
<select
class="form-select form-select-sm"
aria-label=".form-select-sm"
@change="onChange"
v-model="settings.remote.AUDIO.output_device"
>
<option
v-for="device in audioStore.audioOutputs"
:value="device.id"
>
{{ device.name }} [{{ device.api }}]
</option>
</select>
</div>
</div>
</div>
</div>
@ -299,15 +310,19 @@ function testHamlib() {
>Radio port</span
>
<select @change="onChange" v-model="settings.remote.RADIO.serial_port" class="form-select form-select-sm">
<option v-for="device in serialStore.serialDevices" :value="device.port" :key="device.port">
{{ device.description }}
</option>
</select>
<select
@change="onChange"
v-model="settings.remote.RADIO.serial_port"
class="form-select form-select-sm"
>
<option
v-for="device in serialStore.serialDevices"
:value="device.port"
:key="device.port"
>
{{ device.description }}
</option>
</select>
</div>
<div class="input-group input-group-sm mb-1">
@ -376,7 +391,6 @@ function testHamlib() {
data-bs-toggle="collapse"
>
Version
</button>
</h2>
<div
@ -399,7 +413,6 @@ function testHamlib() {
>
Modem version | {{ state.modem_version }}
</button>
</div>
</div>
</div>

View File

@ -19,7 +19,6 @@ import settings_exp from "./settings_exp.vue";
<div class="card-header">
<!-- SETTINGS Nav tabs -->
<ul class="nav nav-tabs card-header-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button
class="nav-link active"
@ -127,8 +126,6 @@ import settings_exp from "./settings_exp.vue";
>
<!-- SETTINGS Nav Tab panes -->
<!-- Station tab contents-->
<div class="tab-content">
<div

View File

@ -2,7 +2,6 @@
import { settingsStore as settings, onChange } from "../store/settingsStore.js";
import { useSerialStore } from "../store/serialStore";
const serialStore = useSerialStore();
</script>
<template>
@ -335,23 +334,19 @@ const serialStore = useSerialStore();
<div class="input-group input-group-sm mb-1">
<span class="input-group-text" style="width: 180px">Radio port</span>
<select @change="onChange" v-model="settings.remote.RADIO.serial_port" class="form-select form-select-sm">
<option v-for="device in serialStore.serialDevices" :value="device.port" :key="device.port">
{{ device.description }}
</option>
</select>
<select
@change="onChange"
v-model="settings.remote.RADIO.serial_port"
class="form-select form-select-sm"
>
<option
v-for="device in serialStore.serialDevices"
:value="device.port"
:key="device.port"
>
{{ device.description }}
</option>
</select>
</div>
<div class="input-group input-group-sm mb-1">
@ -427,17 +422,19 @@ const serialStore = useSerialStore();
<div class="input-group input-group-sm mb-1">
<span class="input-group-text" style="width: 180px">PTT device port</span>
<select @change="onChange" v-model="settings.remote.RADIO.ptt_port" class="form-select form-select-sm">
<option v-for="device in serialStore.serialDevices" :value="device.port" :key="device.port">
{{ device.description }}
</option>
</select>
<select
@change="onChange"
v-model="settings.remote.RADIO.ptt_port"
class="form-select form-select-sm"
>
<option
v-for="device in serialStore.serialDevices"
:value="device.port"
:key="device.port"
>
{{ device.description }}
</option>
</select>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text" style="width: 180px">PTT type</span>

View File

@ -9,9 +9,6 @@ import { startModem, stopModem } from "../js/api.js";
import { useAudioStore } from "../store/audioStore";
const audioStore = useAudioStore();
</script>
<template>
@ -70,31 +67,36 @@ const audioStore = useAudioStore();
/>
</div>
<!-- Audio Input Device -->
<!-- Audio Input Device -->
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50">Audio Input device</label>
<select class="form-select form-select-sm" aria-label=".form-select-sm" @change="onChange" v-model="settings.remote.AUDIO.input_device">
<select
class="form-select form-select-sm"
aria-label=".form-select-sm"
@change="onChange"
v-model="settings.remote.AUDIO.input_device"
>
<option v-for="device in audioStore.audioInputs" :value="device.id">
{{ device.name }} [{{ device.api }}]
</option>
</select>
</div>
<!-- Audio Output Device -->
<!-- Audio Output Device -->
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50">Audio Output device</label>
<select class="form-select form-select-sm" aria-label=".form-select-sm" @change="onChange" v-model="settings.remote.AUDIO.output_device">
<select
class="form-select form-select-sm"
aria-label=".form-select-sm"
@change="onChange"
v-model="settings.remote.AUDIO.output_device"
>
<option v-for="device in audioStore.audioOutputs" :value="device.id">
{{ device.name }} [{{ device.api }}]
</option>
</select>
</div>
<!-- Audio rx level-->
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">RX Audio Level</span>

View File

@ -8,11 +8,7 @@ import {
} from "./chatHandler";
*/
import { displayToast } from "./popupHandler";
import {
getFreedataMessages,
getModemState,
getAudioDevices,
} from "./api";
import { getFreedataMessages, getModemState, getAudioDevices } from "./api";
import { processFreedataMessages } from "./messagesHandler.ts";
import { processRadioStatus } from "./radioHandler.ts";
@ -33,17 +29,15 @@ import {
getRemote,
} from "../store/settingsStore.js";
export function loadAllData(){
getModemState();
getRemote();
getOverallHealth();
audioStore.loadAudioDevices();
serialStore.loadSerialDevices();
getFreedataMessages();
processFreedataMessages();
processRadioStatus();
export function loadAllData() {
getModemState();
getRemote();
getOverallHealth();
audioStore.loadAudioDevices();
serialStore.loadSerialDevices();
getFreedataMessages();
processFreedataMessages();
processRadioStatus();
}
export function connectionFailed(endpoint, event) {
@ -141,7 +135,6 @@ export function eventDispatcher(data) {
displayToast("success", "bi-ethernet", message, 5000);
stateStore.modem_connection = "connected";
loadAllData();
return;

View File

@ -33,7 +33,6 @@ import { getRemote } from "./store/settingsStore";
import { initConnections } from "./js/event_sock.js";
import { getModemState } from "./js/api";
getRemote().then(() => {
initConnections();
getModemState();

View File

@ -2,14 +2,15 @@ import { defineStore } from "pinia";
import { getAudioDevices } from "../js/api";
import { ref } from "vue";
// Define skel fallback data
const skel = [{
"api": "ERR",
"id": "0000",
"name": "No devices received from modem",
"native_index": 0
}];
const skel = [
{
api: "ERR",
id: "0000",
name: "No devices received from modem",
native_index: 0,
},
];
export const useAudioStore = defineStore("audioStore", () => {
const audioInputs = ref([]);
@ -20,7 +21,8 @@ export const useAudioStore = defineStore("audioStore", () => {
const devices = await getAudioDevices();
// Check if devices are valid and have entries, otherwise use skel
audioInputs.value = devices && devices.in.length > 0 ? devices.in : skel;
audioOutputs.value = devices && devices.out.length > 0 ? devices.out : skel;
audioOutputs.value =
devices && devices.out.length > 0 ? devices.out : skel;
} catch (error) {
console.error("Failed to load audio devices:", error);
// Use skel as fallback in case of error
@ -34,4 +36,4 @@ export const useAudioStore = defineStore("audioStore", () => {
audioOutputs,
loadAudioDevices,
};
});
});

View File

@ -3,10 +3,12 @@ import { getSerialDevices } from "../js/api"; // Make sure this points to the co
import { ref } from "vue";
// Define "skel" fallback data for serial devices
const skelSerial = [{
"description": "No devices received from modem",
"port": "ignore" // Using "ignore" as a placeholder value
}];
const skelSerial = [
{
description: "No devices received from modem",
port: "ignore", // Using "ignore" as a placeholder value
},
];
export const useSerialStore = defineStore("serialStore", () => {
const serialDevices = ref([]);
@ -15,7 +17,8 @@ export const useSerialStore = defineStore("serialStore", () => {
try {
const devices = await getSerialDevices();
// Check if devices are valid and have entries, otherwise use skelSerial
serialDevices.value = devices && devices.length > 0 ? devices : skelSerial;
serialDevices.value =
devices && devices.length > 0 ? devices : skelSerial;
} catch (error) {
console.error("Failed to load serial devices:", error);
// Use skelSerial as fallback in case of error
@ -23,7 +26,7 @@ export const useSerialStore = defineStore("serialStore", () => {
}
// Ensure the "-- ignore --" option is always available
if (!serialDevices.value.some(device => device.port === "ignore")) {
if (!serialDevices.value.some((device) => device.port === "ignore")) {
serialDevices.value.push({ description: "-- ignore --", port: "ignore" });
}
};