Prettified Code!

This commit is contained in:
Mashintime 2023-07-02 13:43:54 +00:00 committed by GitHub Action
parent f0d7685a96
commit 95be2f339c
5 changed files with 206 additions and 213 deletions

View file

@ -461,18 +461,16 @@ ipcMain.on("request-update-transmission-status", (event, arg) => {
ipcMain.on("request-update-reception-status", (event, arg) => {
win.webContents.send("action-update-reception-status", arg);
chat.webContents.send("action-update-reception-status", arg);
});
//Called by main to query chat if there are new messages
ipcMain.on("request-update-unread-messages",() => {
ipcMain.on("request-update-unread-messages", () => {
//mainLog.info("Got request to check if chat has new messages")
chat.webContents.send("action-update-unread-messages");
});
//Called by chat to notify main if there are new messages
ipcMain.on("request-update-unread-messages-main", (event,arg) => {
win.webContents.send("action-update-unread-messages-main",arg);
ipcMain.on("request-update-unread-messages-main", (event, arg) => {
win.webContents.send("action-update-unread-messages-main", arg);
//mainLog.info("Received reply from chat and ?new messages = " +arg);
});

View file

@ -215,7 +215,7 @@ window.addEventListener("DOMContentLoaded", () => {
//Add event listener for filter apply button
document.getElementById("btnFilter").addEventListener("click", () => {
chatFilter.length=0;
chatFilter.length = 0;
if (document.getElementById("chkMessage").checked == true) {
chatFilter = [{ type: "newchat" }];
chatFilter.push({ type: "received" }, { type: "transmit" });
@ -231,7 +231,7 @@ window.addEventListener("DOMContentLoaded", () => {
if (document.getElementById("chkResponse").checked == true)
chatFilter.push({ type: "response" });
if (document.getElementById("chkNewMessage").checked == true)
chatFilter.push({new:1});
chatFilter.push({ new: 1 });
updateAllChat(true);
});
@ -667,21 +667,21 @@ ipcRenderer.on("return-select-user-image", (event, arg) => {
ipcRenderer.on("action-update-reception-status", (event, arg) => {
var data = arg["data"][0];
document.getElementById("txtConnectedWithChat").textContent = data.dxcallsign;
document.getElementById("txtConnectedWithChat").textContent = data.dxcallsign;
});
ipcRenderer.on("action-clear-reception-status", (event) => {
//Clear connected with textbox
let cwc = document.getElementById("txtConnectedWithChat");
if (cwc.textContent != "------") {
cwc.textContent = "------";
//console.log("Reseting connected with");
}
//Clear connected with textbox
let cwc = document.getElementById("txtConnectedWithChat");
if (cwc.textContent != "------") {
cwc.textContent = "------";
//console.log("Reseting connected with");
}
});
ipcRenderer.on("action-update-transmission-status", (event, arg) => {
var data = arg["data"][0];
document.getElementById("txtConnectedWithChat").textContent = data.dxcallsign;
document.getElementById("txtConnectedWithChat").textContent = data.dxcallsign;
console.log(data.status);
if (data.uuid !== "no-uuid") {
@ -884,7 +884,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
obj.filetype = splitted_data[7];
//obj.file = btoa(splitted_data[8]);
obj.file = FD.btoa_FD(splitted_data[8]);
obj.new=1;
obj.new = 1;
} else if (splitted_data[1] == "req" && splitted_data[2] == "0") {
obj.uuid = uuidv4().toString();
obj.timestamp = Math.floor(Date.now() / 1000);
@ -897,7 +897,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
obj.filename = "null";
obj.filetype = "null";
obj.file = "null";
obj.new=0;
obj.new = 0;
if (config.enable_request_profile == "True") {
sendUserData(item.dxcallsign);
}
@ -913,7 +913,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
obj.filename = "null";
obj.filetype = "null";
obj.file = "null";
obj.new=0;
obj.new = 0;
if (config.enable_request_shared_folder == "True") {
sendSharedFolderList(item.dxcallsign);
}
@ -934,7 +934,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
obj.filename = "null";
obj.filetype = "null";
obj.file = "null";
obj.new=0;
obj.new = 0;
if (config.enable_request_shared_folder == "True") {
sendSharedFolderFile(item.dxcallsign, name);
}
@ -950,7 +950,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
obj.filename = "null";
obj.filetype = "null";
obj.file = "null";
obj.new=0;
obj.new = 0;
console.log(splitted_data);
let userData = new Object();
userData.user_info_image = splitted_data[2];
@ -979,7 +979,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
obj.filename = "null";
obj.filetype = "null";
obj.file = "null";
obj.new=0;
obj.new = 0;
console.log(splitted_data);
let userData = new Object();
@ -1007,7 +1007,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => {
obj.filename = sharedFileInfo[0];
obj.filetype = "application/octet-stream";
obj.file = FD.btoa_FD(sharedFileInfo[1]);
obj.new=0;
obj.new = 0;
} else {
console.log("no rule matched for handling received data!");
}
@ -1046,31 +1046,30 @@ update_chat = function (obj) {
var attempt = obj.attempt;
}
// add percent and bytes per minute if not existing
//console.log(obj.percent)
if (typeof obj.percent == "undefined") {
obj.percent = 0;
obj.bytesperminute = 0;
}
// add percent and bytes per minute if not existing
//console.log(obj.percent)
if (typeof obj.percent == "undefined") {
obj.percent = 0;
obj.bytesperminute = 0;
}
// check if wrong status message
if (obj.status == "transmit" && obj.percent == 0) {
var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
if (TimeDifference > 3600){
db.upsert(obj._id, function (doc) {
if (!doc.status) {
doc.status = "failed";
}
return doc;
});
obj.status = "failed";
if (obj.status == "transmit" && obj.percent == 0) {
var TimeDifference = new Date().getTime() / 1000 - obj.timestamp;
if (TimeDifference > 3600) {
db.upsert(obj._id, function (doc) {
if (!doc.status) {
doc.status = "failed";
}
return doc;
});
obj.status = "failed";
}
}
if (typeof obj.new == "undefined"){
obj.new=0;
}
if (typeof obj.new == "undefined") {
obj.new = 0;
}
if (typeof config.max_retry_attempts == "undefined") {
var max_retry_attempts = 3;
} else {
@ -1244,8 +1243,12 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
//Reset unread messages and new message indicator
let clear = selected_callsign;
clearUnreadMessages(clear);
document.getElementById(`chat-${selected_callsign}-list-displaydxcall`).textContent=selected_callsign;
document.getElementById(`chat-${selected_callsign}-list`).classList.remove("list-group-item-warning");
document.getElementById(
`chat-${selected_callsign}-list-displaydxcall`
).textContent = selected_callsign;
document
.getElementById(`chat-${selected_callsign}-list`)
.classList.remove("list-group-item-warning");
setTimeout(scrollMessagesToBottom, 200);
//get user information
@ -1266,11 +1269,14 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
// short message
document.getElementById("chat-" + dxcallsign + "-list-shortmsg").innerHTML =
shortmsg;
if (obj.new==1) {
document.getElementById(`chat-${obj.dxcallsign}-list-displaydxcall`).textContent="*" +obj.dxcallsign;
document.getElementById(`chat-${dxcallsign}-list`).classList.add("list-group-item-warning");
}
if (obj.new == 1) {
document.getElementById(
`chat-${obj.dxcallsign}-list-displaydxcall`
).textContent = "*" + obj.dxcallsign;
document
.getElementById(`chat-${dxcallsign}-list`)
.classList.add("list-group-item-warning");
}
}
// APPEND MESSAGES TO CALLSIGN
@ -1334,11 +1340,10 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
var message_html = obj.msg.replaceAll(/\n/g, "<br>");
if (obj.type == "received") {
if (obj.new == 1)
{
showOsPopUp("Message received from " + obj.dxcallsign,obj.msg);
if (obj.new == 1) {
showOsPopUp("Message received from " + obj.dxcallsign, obj.msg);
}
var new_message = `
<div class="d-flex align-items-center" style="margin-left: auto;"> <!-- max-width: 75%; -->
@ -1449,8 +1454,6 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
//console.log("Low graphics enabled for chat module");
}
var new_message = `
<div class="d-flex align-items-center">
${controlarea_transmit}
@ -1485,10 +1488,8 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
obj.percent
}" aria-valuemin="0" aria-valuemax="100"></div>
<p class="justify-content-center d-flex position-absolute m-0 p-0 w-100 text-white ${progressbar_bg}" style="font-size: xx-small" id="msg-${
obj._id
}-progress-information">${percent_value} % - ${
obj.bytesperminute
} Bpm</p>
obj._id
}-progress-information">${percent_value} % - ${obj.bytesperminute} Bpm</p>
</div>
</div>
</div>
@ -1505,11 +1506,8 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
//console.log("element already exists......");
//console.log(obj);
// console.log(obj.status)
// console.log(obj.attempt)
// console.log(obj.status)
// console.log(obj.attempt)
if (
!obj.status == "broadcast_transmit" ||
@ -1532,40 +1530,33 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
obj.attempt + "/" + max_retry_attempts;
}
if (obj.status == "transmit") {
document.getElementById("msg-" + obj._id + "-status").innerHTML =
document.getElementById("msg-" + obj._id + "-status").innerHTML =
get_icon_for_state(obj.status);
if (typeof obj.percent !== "undefined") {
document
.getElementById("msg-" + obj._id + "-progress")
.setAttribute("aria-valuenow", obj.percent);
document
.getElementById("msg-" + obj._id + "-progress")
.setAttribute("style", "width:" + obj.percent + "%;");
document.getElementById(
"msg-" + obj._id + "-progress-information"
).innerHTML = obj.percent + "% - " + obj.bytesperminute + " Bpm";
if (typeof obj.percent !== "undefined") {
document
.getElementById("msg-" + obj._id + "-progress")
.setAttribute("aria-valuenow", obj.percent);
document
.getElementById("msg-" + obj._id + "-progress")
.setAttribute("style", "width:" + obj.percent + "%;");
document.getElementById(
"msg-" + obj._id + "-progress-information"
).innerHTML = obj.percent + "% - " + obj.bytesperminute + " Bpm";
} else {
document
.getElementById("msg-" + obj._id + "-progress")
.setAttribute("aria-valuenow", 0);
document
.getElementById("msg-" + obj._id + "-progress")
.setAttribute("style", "width:0%;");
document.getElementById(
"msg-" + obj._id + "-progress-information"
).innerHTML = "0% - 0 Bpm";
}
} else {
document
.getElementById("msg-" + obj._id + "-progress")
.setAttribute("aria-valuenow", 0);
document
.getElementById("msg-" + obj._id + "-progress")
.setAttribute("style", "width:0%;");
document.getElementById(
"msg-" + obj._id + "-progress-information"
).innerHTML = "0% - 0 Bpm";
}
document.getElementById("msg-" + obj._id + "-attempts").innerHTML =
document.getElementById("msg-" + obj._id + "-attempts").innerHTML =
obj.attempt + "/" + max_retry_attempts;
}
@ -1609,15 +1600,13 @@ if (typeof obj.percent !== "undefined") {
.getElementById("msg-" + obj._id + "-progress")
.classList.add("bg-danger");
console.log(document
.getElementById("msg-" + obj._id + "-progress")
.classList)
console.log(
document.getElementById("msg-" + obj._id + "-progress").classList
);
document.getElementById(
"msg-" + obj._id + "-progress-information"
).innerHTML = "TRANSMISSION FAILED - " + obj.bytesperminute + " Bpm";
}
//document.getElementById(id).className = message_class;
@ -2201,10 +2190,7 @@ async function updateAllChat(clear) {
await db
.createIndex({
index: {
fields: [
{ dxcallsign:"asc" },
{ timestamp:"asc" },
],
fields: [{ dxcallsign: "asc" }, { timestamp: "asc" }],
},
})
.then(async function (result) {
@ -2212,16 +2198,14 @@ async function updateAllChat(clear) {
await db
.find({
selector: {
$and: [
{dxcallsign: { $exists: true } },
{timestamp: { $exists: true } },
{ $or: chatFilter }]
$and: [
{ dxcallsign: { $exists: true } },
{ timestamp: { $exists: true } },
{ $or: chatFilter },
],
//$or: chatFilter
},
sort: [
{ dxcallsign:"asc" },
{ timestamp: "asc" },
]
sort: [{ dxcallsign: "asc" }, { timestamp: "asc" }],
})
.then(async function (result) {
console.log(result);
@ -2284,7 +2268,6 @@ function getSetUserSharedFolder(selected_callsign) {
.then(function (data) {
console.log(data);
if (typeof data.user_shared_folder !== "undefined") {
console.log(data.user_shared_folder);
// shared folder table
@ -2673,8 +2656,8 @@ ipcRenderer.on("update-config", (event, data) => {
});
ipcRenderer.on("action-update-unread-messages", (event) => {
checkForNewMessages().then(function(count) {
ipcRenderer.send("request-update-unread-messages-main",count);
checkForNewMessages().then(function (count) {
ipcRenderer.send("request-update-unread-messages-main", count);
});
});
@ -2812,24 +2795,23 @@ function checkForWaitingMessages(dxcall) {
});
}
async function checkForNewMessages()
{
async function checkForNewMessages() {
var newmsgs;
await db.find({
selector: {
new: {$eq: 1},
}, limit:1,
})
await db
.find({
selector: {
new: { $eq: 1 },
},
limit: 1,
})
.then(function (result) {
if (result.docs.length >0)
newmsgs=true;
else
newmsgs=false;
if (result.docs.length > 0) newmsgs = true;
else newmsgs = false;
})
.catch(function (err) {
console.log(err);
});
return newmsgs;
return newmsgs;
}
function clearUnreadMessages(dxcall) {
@ -2837,25 +2819,25 @@ function clearUnreadMessages(dxcall) {
//Selector of dxcall and new $eq: 1 isn't working, don't know why
//For now parse all messages of callsign to clear new flag
db.find({
selector: //{
//{
selector:
//$and:[
{dxcallsign:dxcall}//, {new: { $gte: 1}}
//]
// }
})
{ dxcallsign: dxcall }, //, {new: { $gte: 1}}
//]
// }
})
.then(function (result) {
//console.log(result);
//console.log ("New messages count to clear for " + dxcall + ": " + result.docs.length)
result.docs.forEach(function (item) {
if (item.new ==1)
{
db.upsert(item._id, function (doc) {
doc.new=0;
//console.log("Clearing new on _id " + item._id);
return doc;
});
}
});
result.docs.forEach(function (item) {
if (item.new == 1) {
db.upsert(item._id, function (doc) {
doc.new = 0;
//console.log("Clearing new on _id " + item._id);
return doc;
});
}
});
})
.catch(function (err) {
console.log(err);
@ -2863,8 +2845,7 @@ function clearUnreadMessages(dxcall) {
}
//Have the operating system show a notification popup
function showOsPopUp(title, message)
{
function showOsPopUp(title, message) {
if (config.enable_sys_notification == 0) return;
const NOTIFICATION_TITLE = title;
const NOTIFICATION_BODY = message;
@ -2872,13 +2853,20 @@ function showOsPopUp(title, message)
}
//Function to clean old beacons and optimize database
async function dbClean()
{
async function dbClean() {
//Only keep the most x latest days of beacons
let beaconKeep = 7;
let itemCount = 0;
let timestampPurge = Math.floor((Date.now()- beaconKeep * 24*60*60*1000) / 1000) ;
if (confirm("Delete beacons and pings older than " + beaconKeep + " days and compact database?")) {
let timestampPurge = Math.floor(
(Date.now() - beaconKeep * 24 * 60 * 60 * 1000) / 1000
);
if (
confirm(
"Delete beacons and pings older than " +
beaconKeep +
" days and compact database?"
)
) {
} else {
return;
}
@ -2889,32 +2877,36 @@ async function dbClean()
{ type: "ping-ack" },
{ type: "ping" },
];
await db.find({
selector: {
$and: [
{timestamp: { $lt: timestampPurge } },
{ $or: purgeFilter }]
}
})
await db
.find({
selector: {
$and: [{ timestamp: { $lt: timestampPurge } }, { $or: purgeFilter }],
},
})
.then(async function (result) {
//console.log("Purging " + result.docs.length + " beacons received before " + timestampPurge);
itemCount=result.docs.length;
itemCount = result.docs.length;
result.docs.forEach(async function (item) {
await db.get(item._id)
await db
.get(item._id)
.then(async function (doc) {
await db.remove(doc)
await db.remove(doc);
})
.catch(function (err) {
console.log(err);
});
});
});
})
.catch(function (err) {
console.log(err);
});
//Compact database
await db.compact();
window.alert("Database maintenance is complete. " + itemCount + " items removed from database. It's recommended you now restart the GUI.");
//Compact database
await db.compact();
window.alert(
"Database maintenance is complete. " +
itemCount +
" items removed from database. It's recommended you now restart the GUI."
);
}

View file

@ -71,10 +71,10 @@ var noise_level_raw = 0;
//Global version variable
var appVer = null;
//Track the number of times TNC has been started
//So that warning is shown when using auto start and 2nd start
//if hamlib is not running
var tncStartCount = 0;
//Track the number of times TNC has been started
//So that warning is shown when using auto start and 2nd start
//if hamlib is not running
var tncStartCount = 0;
// START INTERVALL COMMAND EXECUTION FOR STATES
//setInterval(sock.getRxBuffer, 1000);
@ -1219,8 +1219,10 @@ window.addEventListener("DOMContentLoaded", () => {
FD.saveConfig(config, configPath);
});
//Handle change of Notification settings
document.getElementById("NotificationSwitch").addEventListener("click", () => {
//Handle change of Notification settings
document
.getElementById("NotificationSwitch")
.addEventListener("click", () => {
if (document.getElementById("NotificationSwitch").checked == true) {
config.enable_sys_notification = 1;
} else {
@ -1606,10 +1608,10 @@ window.addEventListener("DOMContentLoaded", () => {
daemon.stopTNC();
});
// btnCleanDB button clicked
document.getElementById("btnCleanDB").addEventListener("click", () => {
ipcRenderer.send("request-clean-db");
});
// btnCleanDB button clicked
document.getElementById("btnCleanDB").addEventListener("click", () => {
ipcRenderer.send("request-clean-db");
});
// TEST HAMLIB
document.getElementById("testHamlib").addEventListener("click", () => {
@ -1632,8 +1634,6 @@ document.getElementById("btnCleanDB").addEventListener("click", () => {
var radiocontrol = "rigctld";
}
daemon.testHamlib(
radiocontrol,
deviceid,
@ -1958,14 +1958,14 @@ function signal_quality_perc_quad(rssi, perfect_rssi = 10, worst_rssi = -150) {
}
var lastHeard = "";
var checkForNewMessageWait=85;
var checkForNewMessageWait = 85;
ipcRenderer.on("action-update-tnc-state", (event, arg) => {
//check for new messages
if (checkForNewMessageWait >= 100){
if (checkForNewMessageWait >= 100) {
//This is very expensive
ipcRenderer.send("request-update-unread-messages");
checkForNewMessageWait=-1;
checkForNewMessageWait = -1;
}
checkForNewMessageWait++;
// update FFT
@ -2439,15 +2439,16 @@ function updateHeardStations(arg) {
timestampRaw = arg.stations[i]["timestamp"];
var datetime = new Date(timestampRaw * 1000).toLocaleString(
navigator.language,{
hourCycle: 'h23',
navigator.language,
{
hourCycle: "h23",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit"
}
second: "2-digit",
}
);
//var hours = date.getHours();
//var minutes = "0" + date.getMinutes();
@ -2770,7 +2771,7 @@ ipcRenderer.on("action-update-tnc-connection", (event, arg) => {
set_CPU_mode();
//GUI will auto connect to TNC if already running, if that is the case increment start count if 0
if (tncStartCount==0) tncStartCount++;
if (tncStartCount == 0) tncStartCount++;
} else {
/*
document.getElementById('hamlib_deviceid').disabled = false;
@ -2925,21 +2926,17 @@ ipcRenderer.on("run-tnc-command-fec-iswriting", (event) => {
});
//Change background color of RF Chat button if new messages are available
ipcRenderer.on("action-update-unread-messages-main", (event,data) => {
ipcRenderer.on("action-update-unread-messages-main", (event, data) => {
//Do something
if (data == true)
{
document.getElementById("openRFChat").classList.add("btn-warning")
document.getElementById("openRFChat").classList.remove("btn-secondary")
}
else
{
document.getElementById("openRFChat").classList.remove("btn-warning")
document.getElementById("openRFChat").classList.add("btn-secondary")
if (data == true) {
document.getElementById("openRFChat").classList.add("btn-warning");
document.getElementById("openRFChat").classList.remove("btn-secondary");
} else {
document.getElementById("openRFChat").classList.remove("btn-warning");
document.getElementById("openRFChat").classList.add("btn-secondary");
}
});
ipcRenderer.on("run-tnc-command", (event, arg) => {
if (arg.command == "save_my_call") {
sock.saveMyCall(arg.callsign);
@ -3121,7 +3118,7 @@ ipcRenderer.on("action-show-cq-toast-received", (event, data) => {
let dxcallsign = data["data"][0]["dxcallsign"];
let dxgrid = data["data"][0]["dxgrid"];
let content = `cq from <strong>${dxcallsign}</strong> (${dxgrid})`;
showOsPopUp("CQ from " + dxcallsign,"Say hello!");
showOsPopUp("CQ from " + dxcallsign, "Say hello!");
displayToast(
(type = "success"),
(icon = "bi-broadcast"),
@ -3807,14 +3804,13 @@ function autostart_tnc() {
if (config.auto_start == 1) {
//Now start TNC
document.getElementById("startTNC").click();
}
}
}
//Have the operating system show a notification popup
function showOsPopUp(title, message)
{
function showOsPopUp(title, message) {
if (config.enable_sys_notification == 0) return;
const NOTIFICATION_TITLE = title;
const NOTIFICATION_BODY = message;
new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY });
}
}

View file

@ -173,7 +173,7 @@
class="form-check-input"
id="chkNewMessage"
/>
<label class="form-check-label" for="chkNewMessage">
Unread Messages
</label>
@ -261,11 +261,9 @@
class="dropdown-item bg-danger text-white"
id="delete_selected_chat"
href="#"
><i
class="bi bi-person-x"
style="font-size: 1rem"
></i>
Delete chat</a>
><i class="bi bi-person-x" style="font-size: 1rem"></i>
Delete chat</a
>
</li>
<div class="dropdown-divider"></div>
<li>
@ -285,12 +283,13 @@ Delete chat</a>
</ul>
<span
class="input-group-text ms-2"
id="txtConnectedWithChat"
data-bs-toggle="tooltip"
data-bs-trigger="hover"
title="Connected with"
>------</span>
class="input-group-text ms-2"
id="txtConnectedWithChat"
data-bs-toggle="tooltip"
data-bs-trigger="hover"
title="Connected with"
>------</span
>
</div>
</div>

View file

@ -3797,9 +3797,17 @@
</label>
</div>
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50">Database maintenance</label>
<label class="input-group-text w-50"
>Database maintenance</label
>
<label class="input-group-text w-50">
<button class="btn btn-outline-secondary btn-sm w-50" id="btnCleanDB" type="button">Clean</button>
<button
class="btn btn-outline-secondary btn-sm w-50"
id="btnCleanDB"
type="button"
>
Clean
</button>
</label>
</div>
<div class="center">