Move common functions to class, ensure config is set globally

This commit is contained in:
Mashintime 2023-03-02 22:05:45 -05:00
parent 975aa5ad66
commit 4a487c17b1
5 changed files with 151 additions and 97 deletions

37
gui/freedata.js Normal file
View file

@ -0,0 +1,37 @@
const fs = require("fs");
const { ipcRenderer } = require("electron");
/**
* Save config and update config setting globally
* @param {string} config - config data
* @param {string} configPath
*/
exports.saveConfig = function (config, configPath){
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
ipcRenderer.send("set-config-global", config);
}
/**
* Binary to ASCII replacement
* @param {string} data in normal/usual utf-8 format
* @returns base64 encoded string
*/
exports.btoa_FD = function (data) {
return Buffer.from(data, "utf-8").toString("base64");
}
/**
* ASCII to Binary replacement
* @param {string} data in base64 encoding
* @returns utf-8 normal/usual string
*/
exports.atob_FD = function (data) {
return Buffer.from(data, "base64").toString("utf-8");
}
/**
* UTF8 to ASCII btoa
* @param {string} data in base64 encoding
* @returns base64 bota compatible data for use in browser
*/
exports.atob = function (data) {
return window.btoa(Buffer.from(data, "base64").toString("utf8"));
}

View file

@ -10,6 +10,8 @@ const mainLog = log.scope("main");
const daemonProcessLog = log.scope("freedata-daemon"); const daemonProcessLog = log.scope("freedata-daemon");
const mime = require("mime"); const mime = require("mime");
const net = require("net"); const net = require("net");
const FD = require("./freedata");
//Useful for debugging event emitter memory leaks //Useful for debugging event emitter memory leaks
//require('events').EventEmitter.defaultMaxListeners = 10; //require('events').EventEmitter.defaultMaxListeners = 10;
//process.traceProcessWarnings=true; //process.traceProcessWarnings=true;
@ -361,6 +363,14 @@ app.on("window-all-closed", () => {
}); });
// IPC HANDLER // IPC HANDLER
//Update configuration globally
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");
});
//Show/update task bar/button progressbar //Show/update task bar/button progressbar
ipcMain.on("request-show-electron-progressbar", (event, data) => { ipcMain.on("request-show-electron-progressbar", (event, data) => {
win.setProgressBar(data / 100); win.setProgressBar(data / 100);

View file

@ -3,6 +3,7 @@ const { ipcRenderer } = require("electron");
const { v4: uuidv4 } = require("uuid"); const { v4: uuidv4 } = require("uuid");
const imageCompression = require("browser-image-compression"); const imageCompression = require("browser-image-compression");
const blobUtil = require("blob-util"); const blobUtil = require("blob-util");
const FD = require("./freedata");
// https://stackoverflow.com/a/26227660 // https://stackoverflow.com/a/26227660
var appDataFolder = var appDataFolder =
@ -506,7 +507,7 @@ window.addEventListener("DOMContentLoaded", () => {
[filename]: { [filename]: {
content_type: filetype, content_type: filetype,
//data: btoa(file) //data: btoa(file)
data: btoa_FD(file), data: FD.btoa_FD(file),
}, },
}, },
}) })
@ -772,7 +773,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
} else if (item.arq == "transmission" && item.status == "received") { } else if (item.arq == "transmission" && item.status == "received") {
//var encoded_data = atob(item.data); //var encoded_data = atob(item.data);
//var encoded_data = Buffer.from(item.data,'base64').toString('utf-8'); //var encoded_data = Buffer.from(item.data,'base64').toString('utf-8');
var encoded_data = atob_FD(item.data); var encoded_data = FD.atob_FD(item.data);
var splitted_data = encoded_data.split(split_char); var splitted_data = encoded_data.split(split_char);
console.log(splitted_data); console.log(splitted_data);
@ -793,7 +794,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
obj.filename = splitted_data[6]; obj.filename = splitted_data[6];
obj.filetype = splitted_data[7]; obj.filetype = splitted_data[7];
//obj.file = btoa(splitted_data[8]); //obj.file = btoa(splitted_data[8]);
obj.file = btoa_FD(splitted_data[8]); obj.file = FD.btoa_FD(splitted_data[8]);
} else if (splitted_data[1] == "req" && splitted_data[2] == "0") { } else if (splitted_data[1] == "req" && splitted_data[2] == "0") {
obj.uuid = uuidv4().toString(); obj.uuid = uuidv4().toString();
obj.timestamp = Math.floor(Date.now() / 1000); obj.timestamp = Math.floor(Date.now() / 1000);
@ -939,7 +940,7 @@ update_chat = function (obj) {
// we really should avoid converting back from base64 for performance reasons... // we really should avoid converting back from base64 for performance reasons...
//var filesize = Math.ceil(atob(obj._attachments[filename]["data"]).length) + "Bytes"; //var filesize = Math.ceil(atob(obj._attachments[filename]["data"]).length) + "Bytes";
var filesize = var filesize =
Math.ceil(atob_FD(obj._attachments[filename]["data"]).length) + Math.ceil(FD.atob_FD(obj._attachments[filename]["data"]).length) +
" Bytes"; " Bytes";
} }
@ -947,7 +948,7 @@ update_chat = function (obj) {
if (filetype == "image/png" || filetype == "png") { if (filetype == "image/png" || filetype == "png") {
var fileheader = ` var fileheader = `
<div class="card-header border-0 bg-transparent text-end p-0 mb-0 hover-overlay"> <div class="card-header border-0 bg-transparent text-end p-0 mb-0 hover-overlay">
<img class="w-100 rounded-2" src="data:image/png;base64,${atoa_FD( <img class="w-100 rounded-2" src="data:image/png;base64,${FD.atob(
obj._attachments[filename]["data"] obj._attachments[filename]["data"]
)}"> )}">
<p class="text-right mb-0 p-1 text-black" style="text-align: right; font-size : 1rem"> <p class="text-right mb-0 p-1 text-black" style="text-align: right; font-size : 1rem">
@ -1382,7 +1383,7 @@ update_chat = function (obj) {
db.getAttachment(obj._id, filename).then(function (data) { db.getAttachment(obj._id, filename).then(function (data) {
console.log(data); console.log(data);
//Rewrote this part to use buffers to ensure encoding is corect -- n1qm //Rewrote this part to use buffers to ensure encoding is corect -- n1qm
var binaryString = atob_FD(data); var binaryString = FD.atob_FD(data);
console.log(binaryString); console.log(binaryString);
var data_with_attachment = var data_with_attachment =
@ -1704,30 +1705,7 @@ var crc32 = function (str) {
return (crc ^ -1) >>> 0; return (crc ^ -1) >>> 0;
}; };
/**
* Binary to ASCII replacement
* @param {string} data in normal/usual utf-8 format
* @returns base64 encoded string
*/
function btoa_FD(data) {
return Buffer.from(data, "utf-8").toString("base64");
}
/**
* ASCII to Binary replacement
* @param {string} data in base64 encoding
* @returns utf-8 normal/usual string
*/
function atob_FD(data) {
return Buffer.from(data, "base64").toString("utf-8");
}
/**
* UTF8 to ASCII btoa
* @param {string} data in base64 encoding
* @returns base64 bota compatible data
*/
function atoa_FD(data) {
return window.btoa(Buffer.from(data, "base64").toString("utf8"));
}
function returnObjFromCallsign(database, callsign) { function returnObjFromCallsign(database, callsign) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
users users
@ -2105,3 +2083,6 @@ function pauseButton(btn, timems) {
btn.disabled = false; btn.disabled = false;
}, timems); }, timems);
} }
ipcRenderer.on("update-config",(event,data) => {
config=data;
});

View file

@ -4,6 +4,7 @@ const exec = require("child_process").spawn;
const sock = require("./sock.js"); const sock = require("./sock.js");
const daemon = require("./daemon.js"); const daemon = require("./daemon.js");
const fs = require("fs"); const fs = require("fs");
const FD = require("./freedata");
const { const {
locatorToLatLng, locatorToLatLng,
distance, distance,
@ -26,7 +27,7 @@ var appDataFolder =
: process.env.HOME + "/.config"); : process.env.HOME + "/.config");
var configFolder = path.join(appDataFolder, "FreeDATA"); var configFolder = path.join(appDataFolder, "FreeDATA");
var configPath = path.join(configFolder, "config.json"); var configPath = path.join(configFolder, "config.json");
const config = require(configPath); var config = require(configPath);
const contrib = [ const contrib = [
"DK5SM", "DK5SM",
"DL4IAZ", "DL4IAZ",
@ -171,7 +172,9 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("received_files_folder").value = document.getElementById("received_files_folder").value =
data.path.filePaths[0]; data.path.filePaths[0];
config.received_files_folder = data.path.filePaths[0]; config.received_files_folder = data.path.filePaths[0];
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); FD.saveConfig(config,configPath);
//fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
} }
); );
}); });
@ -190,7 +193,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("shared_folder_path").value = document.getElementById("shared_folder_path").value =
data.path.filePaths[0]; data.path.filePaths[0];
config.shared_folder_path = data.path.filePaths[0]; config.shared_folder_path = data.path.filePaths[0];
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
} }
); );
}); });
@ -524,7 +528,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("radio-control-rigctld").style.display = "none"; document.getElementById("radio-control-rigctld").style.display = "none";
config.radiocontrol = "disabled"; config.radiocontrol = "disabled";
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// // radio settings 'network' event listener // // radio settings 'network' event listener
@ -547,7 +552,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("radio-control-rigctld").style.display = "none"; document.getElementById("radio-control-rigctld").style.display = "none";
config.radiocontrol = "rigctld"; config.radiocontrol = "rigctld";
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// // radio settings 'rigctld' event listener // // radio settings 'rigctld' event listener
@ -569,7 +575,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("radio-control-rigctld").style.display = "block"; document.getElementById("radio-control-rigctld").style.display = "block";
config.radiocontrol = "rigctld"; config.radiocontrol = "rigctld";
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
document document
@ -600,7 +607,8 @@ window.addEventListener("DOMContentLoaded", () => {
rigctldPath = data.path.filePaths[0]; rigctldPath = data.path.filePaths[0];
document.getElementById("hamlib_rigctld_path").value = rigctldPath; document.getElementById("hamlib_rigctld_path").value = rigctldPath;
config.hamlib_rigctld_path = rigctldPath; config.hamlib_rigctld_path = rigctldPath;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
hamlib_params(); hamlib_params();
}); });
}); });
@ -612,7 +620,8 @@ window.addEventListener("DOMContentLoaded", () => {
config.hamlib_rigctld_server_port = document.getElementById( config.hamlib_rigctld_server_port = document.getElementById(
"hamlib_rigctld_server_port" "hamlib_rigctld_server_port"
).value; ).value;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
hamlib_params(); hamlib_params();
}); });
@ -621,7 +630,8 @@ window.addEventListener("DOMContentLoaded", () => {
try { try {
document.getElementById(elem).addEventListener("change", function () { document.getElementById(elem).addEventListener("change", function () {
config[elem] = document.getElementById(elem).value; config[elem] = document.getElementById(elem).value;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
console.log(config); console.log(config);
hamlib_params(); hamlib_params();
}); });
@ -754,7 +764,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("waterfall").style.height = "100%"; document.getElementById("waterfall").style.height = "100%";
config.spectrum = "waterfall"; config.spectrum = "waterfall";
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// scatter // scatter
document document
@ -773,7 +784,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("chart").style.display = "none"; document.getElementById("chart").style.display = "none";
config.spectrum = "scatter"; config.spectrum = "scatter";
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// chart // chart
document document
@ -792,7 +804,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("chart").style.visibility = "visible"; document.getElementById("chart").style.visibility = "visible";
config.spectrum = "chart"; config.spectrum = "chart";
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// on click remote tnc toggle view // on click remote tnc toggle view
@ -804,7 +817,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("remote-tnc-field").style.visibility = "hidden"; document.getElementById("remote-tnc-field").style.visibility = "hidden";
config.tnclocation = "localhost"; config.tnclocation = "localhost";
toggleClass("remote-tnc-field", "d-none", true); toggleClass("remote-tnc-field", "d-none", true);
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
document document
.getElementById("local-remote-switch2") .getElementById("local-remote-switch2")
@ -814,7 +828,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("remote-tnc-field").style.visibility = "visible"; document.getElementById("remote-tnc-field").style.visibility = "visible";
config.tnclocation = "remote"; config.tnclocation = "remote";
toggleClass("remote-tnc-field", "d-none", false); toggleClass("remote-tnc-field", "d-none", false);
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// on change ping callsign // on change ping callsign
@ -833,8 +848,8 @@ window.addEventListener("DOMContentLoaded", () => {
console.log(document.getElementById("tnc_adress").value); console.log(document.getElementById("tnc_adress").value);
config.tnc_host = document.getElementById("tnc_adress").value; config.tnc_host = document.getElementById("tnc_adress").value;
config.daemon_host = document.getElementById("tnc_adress").value; config.daemon_host = document.getElementById("tnc_adress").value;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
let Data = { let Data = {
port: document.getElementById("tnc_port").value, port: document.getElementById("tnc_port").value,
adress: document.getElementById("tnc_adress").value, adress: document.getElementById("tnc_adress").value,
@ -853,7 +868,8 @@ window.addEventListener("DOMContentLoaded", () => {
config.tnc_port = document.getElementById("tnc_port").value; config.tnc_port = document.getElementById("tnc_port").value;
config.daemon_port = config.daemon_port =
parseInt(document.getElementById("tnc_port").value) + 1; parseInt(document.getElementById("tnc_port").value) + 1;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
let Data = { let Data = {
port: document.getElementById("tnc_port").value, port: document.getElementById("tnc_port").value,
@ -875,7 +891,8 @@ window.addEventListener("DOMContentLoaded", () => {
); );
document.getElementById("audioLevelTXvalue").innerHTML = tx_audio_level; document.getElementById("audioLevelTXvalue").innerHTML = tx_audio_level;
config.tx_audio_level = tx_audio_level; config.tx_audio_level = tx_audio_level;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
let Data = { let Data = {
command: "set_tx_audio_level", command: "set_tx_audio_level",
@ -900,7 +917,8 @@ window.addEventListener("DOMContentLoaded", () => {
//var documentTitle = document.title.split('Call:') //var documentTitle = document.title.split('Call:')
//document.title = documentTitle[0] + 'Call: ' + callsign_ssid; //document.title = documentTitle[0] + 'Call: ' + callsign_ssid;
updateTitle(callsign_ssid); updateTitle(callsign_ssid);
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
daemon.saveMyCall(callsign_ssid); daemon.saveMyCall(callsign_ssid);
}); });
@ -908,7 +926,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("myGrid").addEventListener("input", () => { document.getElementById("myGrid").addEventListener("input", () => {
grid = document.getElementById("myGrid").value; grid = document.getElementById("myGrid").value;
config.mygrid = grid; config.mygrid = grid;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
daemon.saveMyGrid(grid); daemon.saveMyGrid(grid);
}); });
@ -967,7 +986,8 @@ window.addEventListener("DOMContentLoaded", () => {
sock.stopBeacon(); sock.stopBeacon();
} }
config.beacon_interval = interval; config.beacon_interval = interval;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
bcn.disabled = false; bcn.disabled = false;
}); });
@ -979,7 +999,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.enable_scatter = "False"; config.enable_scatter = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// sendfft Switch clicked // sendfft Switch clicked
@ -989,7 +1010,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.enable_fft = "False"; config.enable_fft = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// enable 500z Switch clicked // enable 500z Switch clicked
@ -999,7 +1021,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.low_bandwidth_mode = "False"; config.low_bandwidth_mode = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// enable response to cq clicked // enable response to cq clicked
@ -1009,7 +1032,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.respond_to_cq = "False"; config.respond_to_cq = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// enable explorer Switch clicked // enable explorer Switch clicked
@ -1019,7 +1043,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.enable_explorer = "False"; config.enable_explorer = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// enable explorer stats Switch clicked // enable explorer stats Switch clicked
document document
@ -1030,7 +1055,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.explorer_stats = "False"; config.explorer_stats = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// enable autotune Switch clicked // enable autotune Switch clicked
document.getElementById("autoTuneSwitch").addEventListener("click", () => { document.getElementById("autoTuneSwitch").addEventListener("click", () => {
@ -1039,7 +1065,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.auto_tune = "False"; config.auto_tune = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
document.getElementById("GraphicsSwitch").addEventListener("click", () => { document.getElementById("GraphicsSwitch").addEventListener("click", () => {
if (document.getElementById("GraphicsSwitch").checked == true) { if (document.getElementById("GraphicsSwitch").checked == true) {
@ -1047,7 +1074,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.high_graphics = "False"; config.high_graphics = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
set_CPU_mode(); set_CPU_mode();
}); });
@ -1058,7 +1086,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.enable_fsk = "False"; config.enable_fsk = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// enable is writing switch clicked // enable is writing switch clicked
@ -1068,7 +1097,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.enable_is_writing = "False"; config.enable_is_writing = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// enable enable_request_shared_folder switch clicked // enable enable_request_shared_folder switch clicked
@ -1082,7 +1112,8 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.enable_request_shared_folder = "False"; config.enable_request_shared_folder = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// enable enable_request_profile switch clicked // enable enable_request_profile switch clicked
@ -1094,20 +1125,23 @@ window.addEventListener("DOMContentLoaded", () => {
} else { } else {
config.enable_request_profile = "False"; config.enable_request_profile = "False";
} }
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// Tuning range clicked // Tuning range clicked
document.getElementById("tuning_range_fmin").addEventListener("click", () => { document.getElementById("tuning_range_fmin").addEventListener("click", () => {
var tuning_range_fmin = document.getElementById("tuning_range_fmin").value; var tuning_range_fmin = document.getElementById("tuning_range_fmin").value;
config.tuning_range_fmin = tuning_range_fmin; config.tuning_range_fmin = tuning_range_fmin;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
document.getElementById("tuning_range_fmax").addEventListener("click", () => { document.getElementById("tuning_range_fmax").addEventListener("click", () => {
var tuning_range_fmax = document.getElementById("tuning_range_fmax").value; var tuning_range_fmax = document.getElementById("tuning_range_fmax").value;
config.tuning_range_fmax = tuning_range_fmax; config.tuning_range_fmax = tuning_range_fmax;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// Theme selector clicked // Theme selector clicked
@ -1124,7 +1158,8 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("bootstrap_theme").href = escape(theme_path); document.getElementById("bootstrap_theme").href = escape(theme_path);
config.theme = theme; config.theme = theme;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// Waterfall theme selector changed // Waterfall theme selector changed
@ -1132,7 +1167,8 @@ window.addEventListener("DOMContentLoaded", () => {
var wftheme = document.getElementById("wftheme_selector").value; var wftheme = document.getElementById("wftheme_selector").value;
spectrum.setColorMap(wftheme); spectrum.setColorMap(wftheme);
config.wftheme = wftheme; config.wftheme = wftheme;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// Update channel selector changed // Update channel selector changed
@ -1142,7 +1178,8 @@ window.addEventListener("DOMContentLoaded", () => {
config.update_channel = document.getElementById( config.update_channel = document.getElementById(
"update_channel_selector" "update_channel_selector"
).value; ).value;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
console.log("Autoupdate channel changed to ", config.update_channel); console.log("Autoupdate channel changed to ", config.update_channel);
}); });
@ -1150,14 +1187,16 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("rx_buffer_size").addEventListener("click", () => { document.getElementById("rx_buffer_size").addEventListener("click", () => {
var rx_buffer_size = document.getElementById("rx_buffer_size").value; var rx_buffer_size = document.getElementById("rx_buffer_size").value;
config.rx_buffer_size = rx_buffer_size; config.rx_buffer_size = rx_buffer_size;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
//screen size //screen size
window.addEventListener("resize", () => { window.addEventListener("resize", () => {
config.screen_height = window.innerHeight; config.screen_height = window.innerHeight;
config.screen_width = window.innerWidth; config.screen_width = window.innerWidth;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
}); });
// Explorer button clicked // Explorer button clicked
@ -1333,7 +1372,8 @@ window.addEventListener("DOMContentLoaded", () => {
config.explorer_stats = explorer_stats; config.explorer_stats = explorer_stats;
config.auto_tune = auto_tune; config.auto_tune = auto_tune;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); //fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
FD.saveConfig(config,configPath);
daemon.startTNC( daemon.startTNC(
callsign_ssid, callsign_ssid,
@ -2534,7 +2574,7 @@ ipcRenderer.on("action-update-rx-buffer", (event, arg) => {
console.log(arg.data); console.log(arg.data);
var encoded_data = atob(arg.data[i]["data"]); var encoded_data = FD.atob_FD(arg.data[i]["data"]);
var splitted_data = encoded_data.split(split_char); var splitted_data = encoded_data.split(split_char);
console.log(splitted_data); console.log(splitted_data);
@ -3298,4 +3338,7 @@ function loadSettings(elements) {
console.log("nothing matched...."); console.log("nothing matched....");
} }
}); });
ipcRenderer.on("update-config",(event,data) => {
config=data;
});
} }

View file

@ -1,7 +1,7 @@
var net = require("net"); var net = require("net");
const path = require("path"); const path = require("path");
const { ipcRenderer } = require("electron"); const { ipcRenderer } = require("electron");
const FD = require("./freedata");
const log = require("electron-log"); const log = require("electron-log");
const socketLog = log.scope("tnc"); const socketLog = log.scope("tnc");
//const utf8 = require("utf8"); //const utf8 = require("utf8");
@ -443,7 +443,7 @@ client.on("data", function (socketdata) {
socketLog.info(data); socketLog.info(data);
// we need to encode here to do a deep check for checking if file or message // we need to encode here to do a deep check for checking if file or message
//var encoded_data = atob(data['data']) //var encoded_data = atob(data['data'])
var encoded_data = atob_FD(data["data"]); var encoded_data = FD.atob_FD(data["data"]);
var splitted_data = encoded_data.split(split_char); var splitted_data = encoded_data.split(split_char);
if (splitted_data[0] == "f") { if (splitted_data[0] == "f") {
@ -507,7 +507,7 @@ client.on("data", function (socketdata) {
try { try {
// we need to encode here to do a deep check for checking if file or message // we need to encode here to do a deep check for checking if file or message
//var encoded_data = atob(data['data-array'][i]['data']) //var encoded_data = atob(data['data-array'][i]['data'])
var encoded_data = atob_FD(data["data-array"][i]["data"]); var encoded_data = FD.atob_FD(data["data-array"][i]["data"]);
var splitted_data = encoded_data.split(split_char); var splitted_data = encoded_data.split(split_char);
if (splitted_data[0] == "f") { if (splitted_data[0] == "f") {
@ -613,7 +613,7 @@ exports.sendFile = function (
//Btoa / atob will not work with charsets > 8 bits (i.e. the emojis); should probably move away from using it //Btoa / atob will not work with charsets > 8 bits (i.e. the emojis); should probably move away from using it
//TODO: Will need to update anyother occurences and throughly test //TODO: Will need to update anyother occurences and throughly test
//data = btoa(data) //data = btoa(data)
data = btoa_FD(data); data = FD.btoa_FD(data);
command = command =
'{"type" : "arq", "command" : "send_raw", "parameter" : [{"dxcallsign" : "' + '{"type" : "arq", "command" : "send_raw", "parameter" : [{"dxcallsign" : "' +
@ -638,7 +638,7 @@ exports.sendMessage = function (
uuid, uuid,
command command
) { ) {
data = btoa_FD( data = FD.btoa_FD(
"m" + "m" +
split_char + split_char +
command + command +
@ -669,7 +669,7 @@ exports.sendMessage = function (
// Send Request message // Send Request message
//It would be then „m + split + request + split + request-type“ //It would be then „m + split + request + split + request-type“
function sendRequest(dxcallsign, mode, frames, data, command) { function sendRequest(dxcallsign, mode, frames, data, command) {
data = btoa_FD("m" + split_char + command + split_char + data); data = FD.btoa_FD("m" + split_char + command + split_char + data);
command = command =
'{"type" : "arq", "command" : "send_raw", "parameter" : [{"dxcallsign" : "' + '{"type" : "arq", "command" : "send_raw", "parameter" : [{"dxcallsign" : "' +
dxcallsign + dxcallsign +
@ -688,7 +688,7 @@ function sendRequest(dxcallsign, mode, frames, data, command) {
// Send Response message // Send Response message
//It would be then „m + split + request + split + request-type“ //It would be then „m + split + request + split + request-type“
function sendResponse(dxcallsign, mode, frames, data, command) { function sendResponse(dxcallsign, mode, frames, data, command) {
data = btoa_FD("m" + split_char + command + split_char + data); data = FD.btoa_FD("m" + split_char + command + split_char + data);
command = command =
'{"type" : "arq", "command" : "send_raw", "parameter" : [{"dxcallsign" : "' + '{"type" : "arq", "command" : "send_raw", "parameter" : [{"dxcallsign" : "' +
dxcallsign + dxcallsign +
@ -841,23 +841,6 @@ ipcRenderer.on("action-update-tnc-ip", (event, arg) => {
connectTNC(); connectTNC();
}); });
/**
* String to base64
* @param {string} data in normal/usual utf-8 format
* @returns base64 encoded string
*/
function btoa_FD(data) {
return Buffer.from(data, "utf-8").toString("base64");
}
/**
* base64 to string
* @param {string} data in base64 encoding
* @returns utf-8 normal/usual string
*/
function atob_FD(data) {
return Buffer.from(data, "base64").toString("utf-8");
}
// https://stackoverflow.com/a/50579690 // https://stackoverflow.com/a/50579690
// crc32 calculation // crc32 calculation
//console.log(crc32('abc')); //console.log(crc32('abc'));