FreeDATA/gui/main.js

991 lines
28 KiB
JavaScript
Raw Normal View History

2023-02-11 21:49:07 +00:00
const { app, BrowserWindow, ipcMain, dialog, shell } = require("electron");
const { autoUpdater } = require("electron-updater");
const path = require("path");
const fs = require("fs");
const os = require("os");
const spawn = require("child_process").spawn;
const log = require("electron-log");
const mainLog = log.scope("main");
const daemonProcessLog = log.scope("freedata-daemon");
const mime = require("mime");
const net = require("net");
const FD = require("./freedata");
2023-01-27 15:07:32 +00:00
//Useful for debugging event emitter memory leaks
//require('events').EventEmitter.defaultMaxListeners = 10;
//process.traceProcessWarnings=true;
2023-02-11 21:49:07 +00:00
const sysInfo = log.scope("system information");
sysInfo.info("SYSTEM INFORMATION ----------------------------- ");
sysInfo.info("APP VERSION : " + app.getVersion());
sysInfo.info("PLATFORM : " + os.platform());
sysInfo.info("ARCHITECTURE: " + os.arch());
sysInfo.info("FREE MEMORY: " + os.freemem());
sysInfo.info("TOTAL MEMORY: " + os.totalmem());
sysInfo.info("LOAD AVG : " + os.loadavg());
sysInfo.info("RELEASE : " + os.release());
sysInfo.info("TYPE : " + os.type());
sysInfo.info("VERSION : " + os.version());
sysInfo.info("UPTIME : " + os.uptime());
2021-09-13 16:27:50 +00:00
app.setName("FreeDATA");
2021-09-04 15:11:20 +00:00
2023-02-11 21:49:07 +00:00
var appDataFolder =
process.env.APPDATA ||
(process.platform == "darwin"
? process.env.HOME + "/Library/Application Support"
: process.env.HOME + "/.config");
2021-09-13 16:27:50 +00:00
var configFolder = path.join(appDataFolder, "FreeDATA");
2023-02-11 21:49:07 +00:00
var configPath = path.join(configFolder, "config.json");
2021-09-04 14:33:17 +00:00
2021-11-19 16:30:17 +00:00
// create config folder if not exists
2021-09-04 18:23:58 +00:00
if (!fs.existsSync(configFolder)) {
2023-02-11 21:49:07 +00:00
fs.mkdirSync(configFolder);
2021-09-04 18:23:58 +00:00
}
2021-09-04 14:33:17 +00:00
// create config file if not exists with defaults
2023-02-12 14:44:38 +00:00
const configDefaultSettings =
'{\
"tnc_host": "127.0.0.1",\
"tnc_port": "3000",\
"daemon_host": "127.0.0.1",\
"daemon_port": "3001",\
"mycall": "AA0AA-0",\
"mygrid": "JN40aa",\
2022-09-23 09:17:59 +00:00
"radiocontrol" : "disabled",\
"hamlib_deviceid": "RIG_MODEL_DUMMY_NOVFO",\
2023-02-12 13:44:13 +00:00
"hamlib_deviceport": "ignore",\
"hamlib_stop_bits": "ignore",\
"hamlib_data_bits": "ignore",\
"hamlib_handshake": "ignore",\
"hamlib_serialspeed": "ignore",\
"hamlib_dtrstate": "ignore",\
"hamlib_pttprotocol": "ignore",\
"hamlib_ptt_port": "ignore",\
"hamlib_dcd": "ignore",\
2022-09-23 09:17:59 +00:00
"hamlbib_serialspeed_ptt": "9600",\
"hamlib_rigctld_port" : "4532",\
"hamlib_rigctld_ip" : "127.0.0.1",\
"hamlib_rigctld_path" : "",\
2022-10-03 12:17:03 +00:00
"hamlib_rigctld_server_port" : "4532",\
"hamlib_rigctld_custom_args": "",\
"spectrum": "waterfall",\
"tnclocation": "localhost",\
"enable_scatter" : "False",\
"enable_fft" : "False",\
2022-03-31 10:45:44 +00:00
"enable_fsk" : "False",\
"low_bandwidth_mode" : "False",\
"theme" : "default",\
"screen_height" : 430,\
"screen_width" : 1050,\
"update_channel" : "latest",\
2023-05-09 20:09:57 +00:00
"beacon_interval" : 300,\
2022-03-19 11:42:10 +00:00
"received_files_folder" : "None",\
"tuning_range_fmin" : "-50.0",\
"tuning_range_fmax" : "50.0",\
"respond_to_cq" : "True",\
2022-11-05 21:27:33 +00:00
"rx_buffer_size" : "16", \
2023-04-26 01:11:58 +00:00
"enable_explorer" : "False", \
"wftheme": 2, \
2023-02-05 17:54:23 +00:00
"high_graphics" : "True",\
"explorer_stats" : "False", \
2023-02-14 15:00:10 +00:00
"auto_tune" : "False", \
"enable_is_writing" : "True", \
"shared_folder_path" : ".", \
"enable_request_profile" : "True", \
2023-03-06 11:48:27 +00:00
"enable_request_shared_folder" : "False", \
2023-05-09 10:27:51 +00:00
"max_retry_attempts" : 5, \
"enable_auto_retry" : "False", \
"tx_delay" : 0, \
"auto_start": 0 \
}';
2021-09-04 18:23:58 +00:00
if (!fs.existsSync(configPath)) {
2023-02-11 21:49:07 +00:00
fs.writeFileSync(configPath, configDefaultSettings);
2021-09-04 18:23:58 +00:00
}
// load settings
var config = require(configPath);
//config validation
// check running config against default config.
// if parameter not exists, add it to running config to prevent errors
sysInfo.info("CONFIG VALIDATION ----------------------------- ");
var parsedConfig = JSON.parse(configDefaultSettings);
2023-02-11 21:49:07 +00:00
for (key in parsedConfig) {
if (config.hasOwnProperty(key)) {
sysInfo.info("FOUND SETTTING [" + key + "]: " + config[key]);
} else {
sysInfo.error("MISSING SETTTING [" + key + "] : " + parsedConfig[key]);
config[key] = parsedConfig[key];
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
}
}
sysInfo.info("------------------------------------------ ");
2022-03-10 18:45:37 +00:00
/*
2021-11-19 16:30:17 +00:00
var chatDB = path.join(configFolder, 'chatDB.json')
// create chat database file if not exists
const configContentChatDB = `
2021-11-19 16:30:17 +00:00
{ "chatDB" : [{
"id" : "00000000",
"timestamp" : 1234566,
"mycall" : "AA0AA",
"dxcall" : "AB0AB",
"dxgrid" : "JN1200",
"message" : "hallowelt"
}]
}
`;
if (!fs.existsSync(chatDB)) {
fs.writeFileSync(chatDB, configContentChatDB);
2021-11-19 16:30:17 +00:00
}
2022-03-10 18:45:37 +00:00
*/
2021-11-19 16:30:17 +00:00
2021-09-10 15:59:33 +00:00
/*
// Creates receivedFiles folder if not exists
// https://stackoverflow.com/a/26227660
var appDataFolder = process.env.HOME
2021-09-13 16:27:50 +00:00
var applicationFolder = path.join(appDataFolder, "FreeDATA");
2021-09-10 15:59:33 +00:00
var receivedFilesFolder = path.join(applicationFolder, "receivedFiles");
// https://stackoverflow.com/a/13544465
fs.mkdir(receivedFilesFolder, {
recursive: true
}, function(err) {
console.log(err);
});
*/
2021-07-17 07:02:56 +00:00
let win = null;
let data = null;
let logViewer = null;
2021-09-04 14:33:17 +00:00
var daemonProcess = null;
// create a splash screen
2023-02-11 21:49:07 +00:00
function createSplashScreen() {
splashScreen = new BrowserWindow({
height: 250,
width: 250,
transparent: true,
frame: false,
alwaysOnTop: true,
});
splashScreen.loadFile("src/splash.html");
splashScreen.center();
}
2021-07-24 07:06:22 +00:00
function createWindow() {
2023-02-11 21:49:07 +00:00
win = new BrowserWindow({
width: config.screen_width,
height: config.screen_height,
show: false,
autoHideMenuBar: true,
icon: "src/img/icon.png",
webPreferences: {
//preload: path.join(__dirname, 'preload-main.js'),
backgroundThrottle: false,
preload: require.resolve("./preload-main.js"),
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: false,
sandbox: false,
//https://stackoverflow.com/questions/53390798/opening-new-window-electron/53393655
//https://github.com/electron/remote
},
});
// hide menu bar
win.setMenuBarVisibility(false);
//open dev tools
/*win.webContents.openDevTools({
2021-07-24 07:06:22 +00:00
mode: 'undocked',
activate: true,
})
2021-09-05 15:30:46 +00:00
*/
2023-02-11 21:49:07 +00:00
win.loadFile("src/index.html");
chat = new BrowserWindow({
height: 600,
width: 1000,
show: false,
//parent: win,
webPreferences: {
preload: require.resolve("./preload-chat.js"),
nodeIntegration: true,
},
});
chat.loadFile("src/chat-module.html");
chat.setMenuBarVisibility(false);
logViewer = new BrowserWindow({
height: 900,
width: 600,
show: false,
//parent: win,
webPreferences: {
preload: require.resolve("./preload-log.js"),
nodeIntegration: true,
},
});
logViewer.loadFile("src/log-module.html");
logViewer.setMenuBarVisibility(false);
// Emitted when the window is closed.
logViewer.on("close", function (evt) {
if (logViewer !== null) {
evt.preventDefault();
logViewer.hide();
} else {
this.close();
}
});
2021-07-17 07:02:56 +00:00
2023-02-11 21:49:07 +00:00
// Emitted when the window is closed.
win.on("closed", function () {
console.log("closing all windows.....");
/*
2021-07-17 07:02:56 +00:00
win = null;
2021-11-19 16:30:17 +00:00
chat = null;
logViewer = null;
*/
2023-02-11 21:49:07 +00:00
close_all();
});
2021-07-17 07:02:56 +00:00
2023-02-11 21:49:07 +00:00
win.once("ready-to-show", () => {
log.transports.file.level = "debug";
autoUpdater.logger = log.scope("updater");
2021-07-17 07:02:56 +00:00
2023-02-11 21:49:07 +00:00
autoUpdater.channel = config.update_channel;
2021-07-17 07:02:56 +00:00
2023-02-11 21:49:07 +00:00
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.autoDownload = true;
autoUpdater.checkForUpdatesAndNotify();
//autoUpdater.quitAndInstall();
});
2023-02-11 21:49:07 +00:00
chat.on("closed", function () {});
2023-02-11 21:49:07 +00:00
// https://stackoverflow.com/questions/44258831/only-hide-the-window-when-closing-it-electron
chat.on("close", function (evt) {
evt.preventDefault();
chat.hide();
});
}
2021-09-04 18:23:58 +00:00
2023-02-11 21:49:07 +00:00
app.whenReady().then(() => {
// show splash screen
createSplashScreen();
// create main window
createWindow();
// wait some time, then close splash screen and show main windows
setTimeout(function () {
splashScreen.close();
win.show();
}, 3000);
//Generate daemon binary path
var daemonPath = "";
switch (os.platform().toLowerCase()) {
case "darwin":
case "linux":
daemonPath = path.join(process.resourcesPath, "tnc", "freedata-daemon");
break;
case "win32":
case "win64":
daemonPath = path.join(
process.resourcesPath,
"tnc",
"freedata-daemon.exe"
);
break;
default:
console.log("Unhandled OS Platform: ", os.platform());
break;
}
2023-02-11 21:49:07 +00:00
//Start daemon binary if it exists
if (fs.existsSync(daemonPath)) {
mainLog.info("Starting freedata-daemon binary");
daemonProcess = spawn(daemonPath, [], {
cwd: path.join(daemonPath, ".."),
});
// return process messages
daemonProcess.on("error", (err) => {
daemonProcessLog.error(`error when starting daemon: ${err}`);
});
daemonProcess.on("message", (data) => {
daemonProcessLog.info(`${data}`);
});
daemonProcess.stdout.on("data", (data) => {
daemonProcessLog.info(`${data}`);
});
daemonProcess.stderr.on("data", (data) => {
daemonProcessLog.info(`${data}`);
let arg = {
entry: `${data}`,
};
// send info to log only if log screen available
// it seems an error occurs when updating
if (logViewer !== null && logViewer !== "") {
try {
logViewer.webContents.send("action-update-log", arg);
} catch (e) {
// empty for keeping error stuff silent
// this is important to avoid error messages if we are going to close the app while
// an logging information will be pushed to the logger
}
}
});
daemonProcess.on("close", (code) => {
daemonProcessLog.warn(`daemonProcess exited with code ${code}`);
});
} else {
daemonProcess = null;
daemonPath = null;
mainLog.info("Daemon binary doesn't exist--normal for dev environments.");
}
win.send("action-set-app-version", app.getVersion());
});
2023-02-11 21:49:07 +00:00
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
2023-02-11 21:49:07 +00:00
app.on("window-all-closed", () => {
close_all();
});
2021-07-17 07:02:56 +00:00
// IPC HANDLER
//Update configuration globally
2023-03-03 03:06:25 +00:00
ipcMain.on("set-config-global", (event, data) => {
config = data;
win.webContents.send("update-config", config);
chat.webContents.send("update-config", config);
//console.log("set-config-global called");
});
2023-01-22 06:01:13 +00:00
//Show/update task bar/button progressbar
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-electron-progressbar", (event, data) => {
win.setProgressBar(data / 100);
2023-01-22 06:01:13 +00:00
});
2021-11-19 16:30:17 +00:00
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-chat-window", () => {
chat.show();
});
2021-11-19 16:30:17 +00:00
2022-11-25 11:04:15 +00:00
// UPDATE TNC CONNECTION
2023-02-11 21:49:07 +00:00
ipcMain.on("request-update-tnc-ip", (event, data) => {
win.webContents.send("action-update-tnc-ip", data);
2022-11-25 11:04:15 +00:00
});
// UPDATE DAEMON CONNECTION
2023-02-11 21:49:07 +00:00
ipcMain.on("request-update-daemon-ip", (event, data) => {
win.webContents.send("action-update-daemon-ip", data);
2022-11-25 11:04:15 +00:00
});
2023-02-11 21:49:07 +00:00
ipcMain.on("request-update-tnc-state", (event, arg) => {
win.webContents.send("action-update-tnc-state", arg);
//data.webContents.send('action-update-tnc-state', arg);
2021-07-17 07:02:56 +00:00
});
2021-08-07 18:57:36 +00:00
/*
2021-07-23 15:40:44 +00:00
ipcMain.on('request-update-data-state', (event, arg) => {
//win.webContents.send('action-update-data-state', arg);
//data.webContents.send('action-update-data-state', arg);
2021-07-23 15:40:44 +00:00
});
ipcMain.on('request-update-heard-stations', (event, arg) => {
2021-07-25 14:35:50 +00:00
win.webContents.send('action-update-heard-stations', arg);
2021-07-23 15:40:44 +00:00
});
2021-08-07 18:57:36 +00:00
*/
2023-02-11 21:49:07 +00:00
ipcMain.on("request-update-daemon-state", (event, arg) => {
win.webContents.send("action-update-daemon-state", arg);
2021-07-17 07:02:56 +00:00
});
2023-02-11 21:49:07 +00:00
ipcMain.on("request-update-hamlib-test", (event, arg) => {
win.webContents.send("action-update-hamlib-test", arg);
});
2023-02-11 21:49:07 +00:00
ipcMain.on("request-update-tnc-connection", (event, arg) => {
win.webContents.send("action-update-tnc-connection", arg);
2022-02-12 15:34:47 +00:00
});
2023-02-11 21:49:07 +00:00
ipcMain.on("request-update-daemon-connection", (event, arg) => {
win.webContents.send("action-update-daemon-connection", arg);
2021-07-17 07:02:56 +00:00
});
2023-02-11 21:49:07 +00:00
ipcMain.on("run-tnc-command", (event, arg) => {
win.webContents.send("run-tnc-command", arg);
});
2021-08-16 18:04:03 +00:00
2023-02-12 23:15:12 +00:00
ipcMain.on("tnc-fec-iswriting", (event, arg) => {
win.webContents.send("run-tnc-command-fec-iswriting");
});
2023-02-11 21:49:07 +00:00
ipcMain.on("request-update-rx-buffer", (event, arg) => {
win.webContents.send("action-update-rx-buffer", arg);
2021-09-08 16:22:41 +00:00
});
2022-03-10 18:45:37 +00:00
/*
2021-10-17 15:22:07 +00:00
ipcMain.on('request-update-rx-msg-buffer', (event, arg) => {
2021-11-19 16:30:17 +00:00
chat.webContents.send('action-update-rx-msg-buffer', arg);
});
2022-03-10 18:45:37 +00:00
*/
2023-02-11 21:49:07 +00:00
ipcMain.on("request-new-msg-received", (event, arg) => {
chat.webContents.send("action-new-msg-received", arg);
2022-03-10 18:45:37 +00:00
});
2023-02-11 21:49:07 +00:00
ipcMain.on("request-update-transmission-status", (event, arg) => {
chat.webContents.send("action-update-transmission-status", arg);
win.webContents.send("action-update-transmission-status", arg);
});
2023-02-11 21:49:07 +00:00
ipcMain.on("request-update-reception-status", (event, arg) => {
win.webContents.send("action-update-reception-status", arg);
});
2023-02-11 21:49:07 +00:00
ipcMain.on("request-open-tnc-log", () => {
logViewer.show();
});
//file selector
2023-02-11 21:49:07 +00:00
ipcMain.on("get-file-path", (event, data) => {
dialog
.showOpenDialog({
defaultPath: path.join(__dirname, "../"),
buttonLabel: "Select File",
2023-02-11 21:49:07 +00:00
properties: ["openFile"],
})
.then((filePaths) => {
if (filePaths.canceled == false) {
win.webContents.send(data.action, { path: filePaths });
}
});
});
2022-03-10 18:45:37 +00:00
//folder selector
2023-02-11 21:49:07 +00:00
ipcMain.on("get-folder-path", (event, data) => {
dialog
.showOpenDialog({
defaultPath: path.join(__dirname, "../"),
buttonLabel: "Select folder",
properties: ["openDirectory"],
})
.then((folderPaths) => {
if (folderPaths.canceled == false) {
win.webContents.send(data.action, { path: folderPaths });
//win.webContents.send(data.action, { path: filePaths });
}
2022-03-10 18:45:37 +00:00
});
});
//open folder
2023-02-11 21:49:07 +00:00
ipcMain.on("open-folder", (event, data) => {
shell.showItemInFolder(data.path);
2022-03-10 18:45:37 +00:00
});
//select file
2023-02-11 21:49:07 +00:00
ipcMain.on("select-file", (event, data) => {
dialog
.showOpenDialog({
defaultPath: path.join(__dirname, "../"),
buttonLabel: "Select file",
properties: ["openFile"],
})
2023-02-11 21:49:07 +00:00
.then((filepath) => {
console.log(filepath.filePaths[0]);
try {
//fs.readFile(filepath.filePaths[0], 'utf8', function (err, data) {
//Has to be binary
fs.readFile(filepath.filePaths[0], "binary", function (err, data) {
console.log(data.length);
console.log(data);
var filename = path.basename(filepath.filePaths[0]);
var mimeType = mime.getType(filename);
console.log(mimeType);
if (mimeType == "" || mimeType == null) {
mimeType = "plain/text";
}
chat.webContents.send("return-selected-files", {
data: data,
mime: mimeType,
filename: filename,
});
});
} catch (err) {
console.log(err);
}
});
});
2023-02-26 07:48:51 +00:00
//select image file
2023-02-25 22:23:59 +00:00
ipcMain.on("select-user-image", (event, data) => {
dialog
.showOpenDialog({
defaultPath: path.join(__dirname, "../"),
buttonLabel: "Select file",
properties: ["openFile"],
})
.then((filepath) => {
console.log(filepath.filePaths[0]);
try {
2023-02-26 07:48:51 +00:00
// read data as base64 which makes conversion to blob easier
fs.readFile(filepath.filePaths[0], "base64", function (err, data) {
2023-02-25 22:23:59 +00:00
var filename = path.basename(filepath.filePaths[0]);
var mimeType = mime.getType(filename);
2023-02-26 07:48:51 +00:00
2023-02-25 22:23:59 +00:00
if (mimeType == "" || mimeType == null) {
mimeType = "plain/text";
}
2023-02-26 07:48:51 +00:00
2023-02-25 22:23:59 +00:00
chat.webContents.send("return-select-user-image", {
data: data,
mime: mimeType,
filename: filename,
});
});
} catch (err) {
console.log(err);
}
});
});
// read files in folder - use case "shared folder"
ipcMain.on("read-files-in-folder", (event, data) => {
2023-02-28 12:55:54 +00:00
let fileList = [];
2023-03-03 03:23:14 +00:00
if (config["enable_request_shared_folder"].toLowerCase() == "false") {
//mainLog.info("Shared file folder is disable, not populating fileList");
chat.webContents.send("return-shared-folder-files", {
files: fileList,
});
return;
}
2023-02-28 12:55:54 +00:00
let folder = data.folder;
let files = fs.readdirSync(folder);
console.log(folder);
console.log(files);
files.forEach((file) => {
try {
let filePath = folder + "/" + file;
if (fs.lstatSync(filePath).isFile()) {
let fileSizeInBytes = fs.statSync(filePath).size;
let extension = path.extname(filePath);
2023-02-28 12:55:54 +00:00
fileList.push({
name: file,
extension: extension.substring(1),
size: fileSizeInBytes,
});
2023-02-28 12:55:54 +00:00
}
} catch (err) {
console.log(err);
}
});
2023-02-28 12:55:54 +00:00
chat.webContents.send("return-shared-folder-files", {
files: fileList,
});
});
//save file to folder
2023-02-11 21:49:07 +00:00
ipcMain.on("save-file-to-folder", (event, data) => {
console.log(data.file);
2022-03-10 18:45:37 +00:00
2023-02-11 21:49:07 +00:00
dialog.showSaveDialog({ defaultPath: data.filename }).then((filepath) => {
console.log(filepath.filePath);
console.log(data.file);
2022-03-27 19:04:04 +00:00
2023-02-11 21:49:07 +00:00
try {
let arraybuffer = Buffer.from(data.file, "base64").toString("utf-8");
console.log(arraybuffer);
//Has to be binary
fs.writeFile(
filepath.filePath,
arraybuffer,
"binary",
function (err, data) {}
);
} catch (err) {
console.log(err);
}
});
});
2022-06-07 08:08:15 +00:00
//tnc messages START --------------------------------------
// FEC iswriting received
ipcMain.on("request-show-fec-toast-iswriting", (event, data) => {
2023-05-09 21:21:48 +00:00
win.webContents.send("action-show-fec-toast-iswriting", data);
2023-02-14 03:50:05 +00:00
chat.webContents.send("action-show-feciswriting", data);
});
2022-06-07 08:08:15 +00:00
// CQ TRANSMITTING
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-cq-toast-transmitting", (event, data) => {
win.webContents.send("action-show-cq-toast-transmitting", data);
2022-06-07 08:08:15 +00:00
});
// CQ RECEIVED
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-cq-toast-received", (event, data) => {
win.webContents.send("action-show-cq-toast-received", data);
2022-06-07 08:08:15 +00:00
});
// QRV TRANSMITTING
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-qrv-toast-transmitting", (event, data) => {
win.webContents.send("action-show-qrv-toast-transmitting", data);
2022-06-07 08:08:15 +00:00
});
// QRV RECEIVED
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-qrv-toast-received", (event, data) => {
win.webContents.send("action-show-qrv-toast-received", data);
2022-06-07 08:08:15 +00:00
});
// BEACON TRANSMITTING
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-beacon-toast-transmitting", (event, data) => {
win.webContents.send("action-show-beacon-toast-transmitting", data);
2022-06-07 08:08:15 +00:00
});
// BEACON RECEIVED
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-beacon-toast-received", (event, data) => {
win.webContents.send("action-show-beacon-toast-received", data);
2022-06-07 08:08:15 +00:00
});
// PING TRANSMITTING
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-ping-toast-transmitting", (event, data) => {
win.webContents.send("action-show-ping-toast-transmitting", data);
2022-06-07 08:08:15 +00:00
});
// PING RECEIVED
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-ping-toast-received", (event, data) => {
win.webContents.send("action-show-ping-toast-received", data);
2022-06-07 08:08:15 +00:00
});
// PING RECEIVED ACK
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-ping-toast-received-ack", (event, data) => {
win.webContents.send("action-show-ping-toast-received-ack", data);
2022-06-07 08:08:15 +00:00
});
// ARQ DATA CHANNEL OPENING
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-datachannel-opening", (event, data) => {
win.webContents.send("action-show-arq-toast-datachannel-opening", data);
2022-06-07 08:08:15 +00:00
});
2022-11-17 21:17:50 +00:00
// ARQ DATA CHANNEL WAITING
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-datachannel-waiting", (event, data) => {
win.webContents.send("action-show-arq-toast-datachannel-waiting", data);
2022-11-17 21:17:50 +00:00
});
2022-06-07 08:08:15 +00:00
// ARQ DATA CHANNEL OPEN
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-datachannel-opened", (event, data) => {
win.webContents.send("action-show-arq-toast-datachannel-opened", data);
2022-06-07 08:08:15 +00:00
});
// ARQ DATA RECEIVED OPENER
2023-02-11 21:49:07 +00:00
ipcMain.on(
"request-show-arq-toast-datachannel-received-opener",
(event, data) => {
win.webContents.send(
"action-show-arq-toast-datachannel-received-opener",
data
);
}
);
2022-06-07 08:08:15 +00:00
// ARQ TRANSMISSION FAILED
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-transmission-failed", (event, data) => {
win.webContents.send("action-show-arq-toast-transmission-failed", data);
2022-06-07 08:08:15 +00:00
});
// ARQ TRANSMISSION FAILED
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-transmission-failed-ver", (event, data) => {
win.webContents.send("action-show-arq-toast-transmission-failed-ver", data);
});
2022-06-07 08:08:15 +00:00
// ARQ TRANSMISSION RECEIVING
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-transmission-receiving", (event, data) => {
win.webContents.send("action-show-arq-toast-transmission-receiving", data);
2022-06-07 08:08:15 +00:00
});
// ARQ TRANSMISSION RECEIVED
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-transmission-received", (event, data) => {
win.webContents.send("action-show-arq-toast-transmission-received", data);
2022-06-07 08:08:15 +00:00
});
// ARQ TRANSMISSION TRANSMITTING
2023-02-11 21:49:07 +00:00
ipcMain.on(
"request-show-arq-toast-transmission-transmitting",
(event, data) => {
win.webContents.send(
"action-show-arq-toast-transmission-transmitting",
data
);
}
);
2022-06-07 08:08:15 +00:00
// ARQ TRANSMISSION TRANSMITTED
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-transmission-transmitted", (event, data) => {
win.webContents.send("action-show-arq-toast-transmission-transmitted", data);
2022-06-07 08:08:15 +00:00
});
2022-06-15 08:51:19 +00:00
// ARQ SESSION CONNECTING
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-session-connecting", (event, data) => {
win.webContents.send("action-show-arq-toast-session-connecting", data);
2022-06-15 08:51:19 +00:00
});
2022-11-17 23:03:18 +00:00
// ARQ SESSION WAITING
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-session-waiting", (event, data) => {
win.webContents.send("action-show-arq-toast-session-waiting", data);
2022-11-17 23:03:18 +00:00
});
2022-06-15 08:51:19 +00:00
// ARQ SESSION CONNECTED
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-session-connected", (event, data) => {
win.webContents.send("action-show-arq-toast-session-connected", data);
2022-06-15 08:51:19 +00:00
});
// ARQ SESSION CLOSE
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-session-close", (event, data) => {
win.webContents.send("action-show-arq-toast-session-close", data);
2022-06-15 08:51:19 +00:00
});
// ARQ SESSION FAILED
2023-02-11 21:49:07 +00:00
ipcMain.on("request-show-arq-toast-session-failed", (event, data) => {
win.webContents.send("action-show-arq-toast-session-failed", data);
2022-06-15 08:51:19 +00:00
});
2022-06-07 08:08:15 +00:00
//tnc messages END --------------------------------------
//restart and install udpate
2023-02-11 21:49:07 +00:00
ipcMain.on("request-restart-and-install", (event, data) => {
close_sub_processes();
autoUpdater.quitAndInstall();
});
2022-02-22 14:53:55 +00:00
// LISTENER FOR UPDATER EVENTS
2023-02-11 21:49:07 +00:00
autoUpdater.on("update-available", (info) => {
mainLog.info("update available");
let arg = {
status: "update-available",
info: info,
};
win.webContents.send("action-updater", arg);
});
autoUpdater.on("update-not-available", (info) => {
mainLog.info("update not available");
let arg = {
status: "update-not-available",
info: info,
};
win.webContents.send("action-updater", arg);
});
autoUpdater.on("update-downloaded", (info) => {
mainLog.info("update downloaded");
let arg = {
status: "update-downloaded",
info: info,
};
win.webContents.send("action-updater", arg);
// we need to call this at this point.
// if an update is available and we are force closing the app
// the entire screen crashes...
//mainLog.info('quit application and install update');
//autoUpdater.quitAndInstall();
2022-02-22 14:40:33 +00:00
});
2023-02-11 21:49:07 +00:00
autoUpdater.on("checking-for-update", () => {
mainLog.info("checking for update");
let arg = {
status: "checking-for-update",
version: app.getVersion(),
};
win.webContents.send("action-updater", arg);
2022-02-22 14:40:33 +00:00
});
2023-02-11 21:49:07 +00:00
autoUpdater.on("download-progress", (progress) => {
let arg = {
status: "download-progress",
progress: progress,
};
win.webContents.send("action-updater", arg);
2022-02-22 14:40:33 +00:00
});
2023-02-11 21:49:07 +00:00
autoUpdater.on("error", (error) => {
mainLog.info("update error");
let arg = {
status: "error",
progress: error,
};
win.webContents.send("action-updater", arg);
2022-03-19 11:42:10 +00:00
mainLog.error("AUTO UPDATER : " + error);
});
2023-02-11 21:49:07 +00:00
function close_sub_processes() {
mainLog.warn("closing sub processes");
2023-02-11 21:49:07 +00:00
// closing the tnc binary if not closed when closing application and also our daemon which has been started by the gui
try {
if (daemonProcess != null) {
daemonProcess.kill();
}
2023-02-11 21:49:07 +00:00
} catch (e) {
mainLog.error(e);
}
2023-02-11 21:49:07 +00:00
mainLog.warn("closing tnc and daemon");
try {
if (os.platform() == "win32" || os.platform() == "win64") {
spawn("Taskkill", ["/IM", "freedata-tnc.exe", "/F"]);
spawn("Taskkill", ["/IM", "freedata-daemon.exe", "/F"]);
}
2023-02-11 21:49:07 +00:00
if (os.platform() == "linux") {
spawn("pkill", ["-9", "freedata-tnc"]);
spawn("pkill", ["-9", "freedata-daemon"]);
}
2023-02-11 21:49:07 +00:00
if (os.platform() == "darwin") {
spawn("pkill", ["-9", "freedata-tnc"]);
spawn("pkill", ["-9", "freedata-daemon"]);
}
} catch (e) {
mainLog.error(e);
}
}
function close_all() {
2023-02-11 21:49:07 +00:00
// function for closing the application with closing all used processes
2023-02-11 21:49:07 +00:00
close_sub_processes();
2023-02-11 21:49:07 +00:00
mainLog.warn("quitting app");
2023-02-11 21:49:07 +00:00
win.destroy();
chat.destroy();
logViewer.destroy();
2023-02-11 21:49:07 +00:00
app.quit();
}
2023-02-11 21:49:07 +00:00
// RUN RIGCTLD
ipcMain.on("request-start-rigctld", (event, data) => {
try {
let rigctld_proc = spawn(data.path, data.parameters, {
windowsVerbatimArguments: true,
});
2023-02-11 21:49:07 +00:00
rigctld_proc.on("exit", function (code) {
console.log("rigctld process exited with code " + code);
// if rigctld crashes, error code is -2
// then we are going to restart rigctld
// this "fixes" a problem with latest rigctld on raspberry pi
//if (code == -2){
// setTimeout(ipcRenderer.send('request-start-rigctld', data), 500);
//}
//let rigctld_proc = spawn(data.path, data.parameters);
});
} catch (e) {
console.log(e);
}
2023-02-11 21:49:07 +00:00
/*
2022-09-23 17:29:04 +00:00
const rigctld = exec(data.path, data.parameters);
rigctld.stdout.on("data", data => {
console.log(`stdout: ${data}`);
});
2022-09-23 17:22:47 +00:00
*/
});
// STOP RIGCTLD
2023-02-11 21:49:07 +00:00
ipcMain.on("request-stop-rigctld", (event, data) => {
mainLog.warn("closing rigctld");
try {
if (os.platform() == "win32" || os.platform() == "win64") {
spawn("Taskkill", ["/IM", "rigctld.exe", "/F"]);
}
2023-02-11 21:49:07 +00:00
if (os.platform() == "linux") {
spawn("pkill", ["-9", "rigctld"]);
}
2023-02-11 21:49:07 +00:00
if (os.platform() == "darwin") {
spawn("pkill", ["-9", "rigctld"]);
2022-09-23 12:06:13 +00:00
}
2023-02-11 21:49:07 +00:00
} catch (e) {
mainLog.error(e);
}
2022-09-23 12:06:13 +00:00
});
// CHECK RIGCTLD CONNECTION
2022-11-18 13:47:31 +00:00
// create new socket so we are not reopening every time a new one
var rigctld_connection = new net.Socket();
var rigctld_connection_state = false;
2023-01-27 15:07:32 +00:00
var rigctld_events_wired = false;
2023-02-11 21:49:07 +00:00
ipcMain.on("request-check-rigctld", (event, data) => {
try {
let Data = {
state: "unknown",
};
2022-11-08 08:36:06 +00:00
2023-02-11 21:49:07 +00:00
if (!rigctld_connection_state) {
rigctld_connection = new net.Socket();
rigctld_events_wired = false;
rigctld_connection.connect(data.port, data.ip);
}
2023-02-11 21:49:07 +00:00
// Check if we have created a new socket object and attach listeners if not already created
if (typeof rigctld_connection != "undefined" && !rigctld_events_wired) {
rigctld_connection.on("connect", function () {
rigctld_events_wired = true;
mainLog.info("Starting rigctld event listeners");
rigctld_connection_state = true;
2023-04-26 01:19:02 +00:00
Data["state"] = "Connected";
2023-03-27 21:07:54 +00:00
Data["active"] = true;
2023-02-11 21:49:07 +00:00
if (win !== null && win !== "" && typeof win != "undefined") {
// try catch for being sure we have a clean app close
try {
win.webContents.send("action-check-rigctld", Data);
} catch (e) {
console.log(e);
}
2022-11-18 13:47:31 +00:00
}
2023-02-11 21:49:07 +00:00
});
rigctld_connection.on("error", function () {
rigctld_connection_state = false;
2023-04-26 01:07:01 +00:00
Data["state"] = "Not Connected";
Data["active"] = false;
2023-02-11 21:49:07 +00:00
if (win !== null && win !== "" && typeof win != "undefined") {
// try catch for being sure we have a clean app close
try {
win.webContents.send("action-check-rigctld", Data);
} catch (e) {
console.log(e);
}
2022-11-18 13:47:31 +00:00
}
2023-02-11 21:49:07 +00:00
});
2022-11-18 13:47:31 +00:00
2023-02-11 21:49:07 +00:00
rigctld_connection.on("end", function () {
rigctld_connection_state = false;
});
}
2023-02-11 21:49:07 +00:00
} catch (e) {
console.log(e);
}
});