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,14 +461,12 @@ ipcMain.on("request-update-transmission-status", (event, arg) => {
ipcMain.on("request-update-reception-status", (event, arg) => { ipcMain.on("request-update-reception-status", (event, arg) => {
win.webContents.send("action-update-reception-status", arg); win.webContents.send("action-update-reception-status", arg);
chat.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 //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") //mainLog.info("Got request to check if chat has new messages")
chat.webContents.send("action-update-unread-messages"); chat.webContents.send("action-update-unread-messages");
}); });
//Called by chat to notify main if there are new messages //Called by chat to notify main if there are new messages
ipcMain.on("request-update-unread-messages-main", (event, arg) => { ipcMain.on("request-update-unread-messages-main", (event, arg) => {

View file

@ -1055,7 +1055,7 @@ if (typeof obj.percent == "undefined") {
// check if wrong status message // check if wrong status message
if (obj.status == "transmit" && obj.percent == 0) { if (obj.status == "transmit" && obj.percent == 0) {
var TimeDifference = (new Date().getTime()/1000) - obj.timestamp var TimeDifference = new Date().getTime() / 1000 - obj.timestamp;
if (TimeDifference > 3600) { if (TimeDifference > 3600) {
db.upsert(obj._id, function (doc) { db.upsert(obj._id, function (doc) {
if (!doc.status) { if (!doc.status) {
@ -1064,7 +1064,6 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
return doc; return doc;
}); });
obj.status = "failed"; obj.status = "failed";
} }
} }
if (typeof obj.new == "undefined") { if (typeof obj.new == "undefined") {
@ -1244,8 +1243,12 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
//Reset unread messages and new message indicator //Reset unread messages and new message indicator
let clear = selected_callsign; let clear = selected_callsign;
clearUnreadMessages(clear); clearUnreadMessages(clear);
document.getElementById(`chat-${selected_callsign}-list-displaydxcall`).textContent=selected_callsign; document.getElementById(
document.getElementById(`chat-${selected_callsign}-list`).classList.remove("list-group-item-warning"); `chat-${selected_callsign}-list-displaydxcall`
).textContent = selected_callsign;
document
.getElementById(`chat-${selected_callsign}-list`)
.classList.remove("list-group-item-warning");
setTimeout(scrollMessagesToBottom, 200); setTimeout(scrollMessagesToBottom, 200);
//get user information //get user information
@ -1267,9 +1270,12 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
document.getElementById("chat-" + dxcallsign + "-list-shortmsg").innerHTML = document.getElementById("chat-" + dxcallsign + "-list-shortmsg").innerHTML =
shortmsg; shortmsg;
if (obj.new == 1) { if (obj.new == 1) {
document.getElementById(`chat-${obj.dxcallsign}-list-displaydxcall`).textContent="*" +obj.dxcallsign; document.getElementById(
document.getElementById(`chat-${dxcallsign}-list`).classList.add("list-group-item-warning"); `chat-${obj.dxcallsign}-list-displaydxcall`
).textContent = "*" + obj.dxcallsign;
document
.getElementById(`chat-${dxcallsign}-list`)
.classList.add("list-group-item-warning");
} }
} }
// APPEND MESSAGES TO CALLSIGN // APPEND MESSAGES TO CALLSIGN
@ -1334,8 +1340,7 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
var message_html = obj.msg.replaceAll(/\n/g, "<br>"); var message_html = obj.msg.replaceAll(/\n/g, "<br>");
if (obj.type == "received") { if (obj.type == "received") {
if (obj.new == 1) if (obj.new == 1) {
{
showOsPopUp("Message received from " + obj.dxcallsign, obj.msg); showOsPopUp("Message received from " + obj.dxcallsign, obj.msg);
} }
@ -1449,8 +1454,6 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
//console.log("Low graphics enabled for chat module"); //console.log("Low graphics enabled for chat module");
} }
var new_message = ` var new_message = `
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
${controlarea_transmit} ${controlarea_transmit}
@ -1486,9 +1489,7 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
}" aria-valuemin="0" aria-valuemax="100"></div> }" 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-${ <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 obj._id
}-progress-information">${percent_value} % - ${ }-progress-information">${percent_value} % - ${obj.bytesperminute} Bpm</p>
obj.bytesperminute
} Bpm</p>
</div> </div>
</div> </div>
</div> </div>
@ -1508,9 +1509,6 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
// console.log(obj.status) // console.log(obj.status)
// console.log(obj.attempt) // console.log(obj.attempt)
if ( if (
!obj.status == "broadcast_transmit" || !obj.status == "broadcast_transmit" ||
!obj.status == "broadcast_received" !obj.status == "broadcast_received"
@ -1532,9 +1530,7 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
obj.attempt + "/" + max_retry_attempts; obj.attempt + "/" + max_retry_attempts;
} }
if (obj.status == "transmit") { if (obj.status == "transmit") {
document.getElementById("msg-" + obj._id + "-status").innerHTML = document.getElementById("msg-" + obj._id + "-status").innerHTML =
get_icon_for_state(obj.status); get_icon_for_state(obj.status);
@ -1548,7 +1544,6 @@ if (typeof obj.percent !== "undefined") {
document.getElementById( document.getElementById(
"msg-" + obj._id + "-progress-information" "msg-" + obj._id + "-progress-information"
).innerHTML = obj.percent + "% - " + obj.bytesperminute + " Bpm"; ).innerHTML = obj.percent + "% - " + obj.bytesperminute + " Bpm";
} else { } else {
document document
.getElementById("msg-" + obj._id + "-progress") .getElementById("msg-" + obj._id + "-progress")
@ -1559,12 +1554,8 @@ if (typeof obj.percent !== "undefined") {
document.getElementById( document.getElementById(
"msg-" + obj._id + "-progress-information" "msg-" + obj._id + "-progress-information"
).innerHTML = "0% - 0 Bpm"; ).innerHTML = "0% - 0 Bpm";
} }
document.getElementById("msg-" + obj._id + "-attempts").innerHTML = document.getElementById("msg-" + obj._id + "-attempts").innerHTML =
obj.attempt + "/" + max_retry_attempts; obj.attempt + "/" + max_retry_attempts;
} }
@ -1609,15 +1600,13 @@ if (typeof obj.percent !== "undefined") {
.getElementById("msg-" + obj._id + "-progress") .getElementById("msg-" + obj._id + "-progress")
.classList.add("bg-danger"); .classList.add("bg-danger");
console.log(document console.log(
.getElementById("msg-" + obj._id + "-progress") document.getElementById("msg-" + obj._id + "-progress").classList
.classList) );
document.getElementById( document.getElementById(
"msg-" + obj._id + "-progress-information" "msg-" + obj._id + "-progress-information"
).innerHTML = "TRANSMISSION FAILED - " + obj.bytesperminute + " Bpm"; ).innerHTML = "TRANSMISSION FAILED - " + obj.bytesperminute + " Bpm";
} }
//document.getElementById(id).className = message_class; //document.getElementById(id).className = message_class;
@ -2201,10 +2190,7 @@ async function updateAllChat(clear) {
await db await db
.createIndex({ .createIndex({
index: { index: {
fields: [ fields: [{ dxcallsign: "asc" }, { timestamp: "asc" }],
{ dxcallsign:"asc" },
{ timestamp:"asc" },
],
}, },
}) })
.then(async function (result) { .then(async function (result) {
@ -2215,13 +2201,11 @@ async function updateAllChat(clear) {
$and: [ $and: [
{ dxcallsign: { $exists: true } }, { dxcallsign: { $exists: true } },
{ timestamp: { $exists: true } }, { timestamp: { $exists: true } },
{ $or: chatFilter }] { $or: chatFilter },
],
//$or: chatFilter //$or: chatFilter
}, },
sort: [ sort: [{ dxcallsign: "asc" }, { timestamp: "asc" }],
{ dxcallsign:"asc" },
{ timestamp: "asc" },
]
}) })
.then(async function (result) { .then(async function (result) {
console.log(result); console.log(result);
@ -2284,7 +2268,6 @@ function getSetUserSharedFolder(selected_callsign) {
.then(function (data) { .then(function (data) {
console.log(data); console.log(data);
if (typeof data.user_shared_folder !== "undefined") { if (typeof data.user_shared_folder !== "undefined") {
console.log(data.user_shared_folder); console.log(data.user_shared_folder);
// shared folder table // shared folder table
@ -2812,19 +2795,18 @@ function checkForWaitingMessages(dxcall) {
}); });
} }
async function checkForNewMessages() async function checkForNewMessages() {
{
var newmsgs; var newmsgs;
await db.find({ await db
.find({
selector: { selector: {
new: { $eq: 1 }, new: { $eq: 1 },
}, limit:1, },
limit: 1,
}) })
.then(function (result) { .then(function (result) {
if (result.docs.length >0) if (result.docs.length > 0) newmsgs = true;
newmsgs=true; else newmsgs = false;
else
newmsgs=false;
}) })
.catch(function (err) { .catch(function (err) {
console.log(err); console.log(err);
@ -2837,9 +2819,10 @@ function clearUnreadMessages(dxcall) {
//Selector of dxcall and new $eq: 1 isn't working, don't know why //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 //For now parse all messages of callsign to clear new flag
db.find({ db.find({
selector: //{ //{
selector:
//$and:[ //$and:[
{dxcallsign:dxcall}//, {new: { $gte: 1}} { dxcallsign: dxcall }, //, {new: { $gte: 1}}
//] //]
// } // }
}) })
@ -2847,8 +2830,7 @@ function clearUnreadMessages(dxcall) {
//console.log(result); //console.log(result);
//console.log ("New messages count to clear for " + dxcall + ": " + result.docs.length) //console.log ("New messages count to clear for " + dxcall + ": " + result.docs.length)
result.docs.forEach(function (item) { result.docs.forEach(function (item) {
if (item.new ==1) if (item.new == 1) {
{
db.upsert(item._id, function (doc) { db.upsert(item._id, function (doc) {
doc.new = 0; doc.new = 0;
//console.log("Clearing new on _id " + item._id); //console.log("Clearing new on _id " + item._id);
@ -2863,8 +2845,7 @@ function clearUnreadMessages(dxcall) {
} }
//Have the operating system show a notification popup //Have the operating system show a notification popup
function showOsPopUp(title, message) function showOsPopUp(title, message) {
{
if (config.enable_sys_notification == 0) return; if (config.enable_sys_notification == 0) return;
const NOTIFICATION_TITLE = title; const NOTIFICATION_TITLE = title;
const NOTIFICATION_BODY = message; const NOTIFICATION_BODY = message;
@ -2872,13 +2853,20 @@ function showOsPopUp(title, message)
} }
//Function to clean old beacons and optimize database //Function to clean old beacons and optimize database
async function dbClean() async function dbClean() {
{
//Only keep the most x latest days of beacons //Only keep the most x latest days of beacons
let beaconKeep = 7; let beaconKeep = 7;
let itemCount = 0; let itemCount = 0;
let timestampPurge = Math.floor((Date.now()- beaconKeep * 24*60*60*1000) / 1000) ; let timestampPurge = Math.floor(
if (confirm("Delete beacons and pings older than " + beaconKeep + " days and compact database?")) { (Date.now() - beaconKeep * 24 * 60 * 60 * 1000) / 1000
);
if (
confirm(
"Delete beacons and pings older than " +
beaconKeep +
" days and compact database?"
)
) {
} else { } else {
return; return;
} }
@ -2890,20 +2878,20 @@ async function dbClean()
{ type: "ping" }, { type: "ping" },
]; ];
await db.find({ await db
.find({
selector: { selector: {
$and: [ $and: [{ timestamp: { $lt: timestampPurge } }, { $or: purgeFilter }],
{timestamp: { $lt: timestampPurge } }, },
{ $or: purgeFilter }]
}
}) })
.then(async function (result) { .then(async function (result) {
//console.log("Purging " + result.docs.length + " beacons received before " + timestampPurge); //console.log("Purging " + result.docs.length + " beacons received before " + timestampPurge);
itemCount = result.docs.length; itemCount = result.docs.length;
result.docs.forEach(async function (item) { result.docs.forEach(async function (item) {
await db.get(item._id) await db
.get(item._id)
.then(async function (doc) { .then(async function (doc) {
await db.remove(doc) await db.remove(doc);
}) })
.catch(function (err) { .catch(function (err) {
console.log(err); console.log(err);
@ -2916,5 +2904,9 @@ async function dbClean()
//Compact database //Compact database
await db.compact(); await db.compact();
window.alert("Database maintenance is complete. " + itemCount + " items removed from database. It's recommended you now restart the GUI."); window.alert(
"Database maintenance is complete. " +
itemCount +
" items removed from database. It's recommended you now restart the GUI."
);
} }

View file

@ -1220,7 +1220,9 @@ window.addEventListener("DOMContentLoaded", () => {
}); });
//Handle change of Notification settings //Handle change of Notification settings
document.getElementById("NotificationSwitch").addEventListener("click", () => { document
.getElementById("NotificationSwitch")
.addEventListener("click", () => {
if (document.getElementById("NotificationSwitch").checked == true) { if (document.getElementById("NotificationSwitch").checked == true) {
config.enable_sys_notification = 1; config.enable_sys_notification = 1;
} else { } else {
@ -1632,8 +1634,6 @@ document.getElementById("btnCleanDB").addEventListener("click", () => {
var radiocontrol = "rigctld"; var radiocontrol = "rigctld";
} }
daemon.testHamlib( daemon.testHamlib(
radiocontrol, radiocontrol,
deviceid, deviceid,
@ -2439,14 +2439,15 @@ function updateHeardStations(arg) {
timestampRaw = arg.stations[i]["timestamp"]; timestampRaw = arg.stations[i]["timestamp"];
var datetime = new Date(timestampRaw * 1000).toLocaleString( var datetime = new Date(timestampRaw * 1000).toLocaleString(
navigator.language,{ navigator.language,
hourCycle: 'h23', {
hourCycle: "h23",
year: "numeric", year: "numeric",
month: "2-digit", month: "2-digit",
day: "2-digit", day: "2-digit",
hour: "2-digit", hour: "2-digit",
minute: "2-digit", minute: "2-digit",
second: "2-digit" second: "2-digit",
} }
); );
//var hours = date.getHours(); //var hours = date.getHours();
@ -2927,19 +2928,15 @@ ipcRenderer.on("run-tnc-command-fec-iswriting", (event) => {
//Change background color of RF Chat button if new messages are available //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 //Do something
if (data == true) if (data == true) {
{ document.getElementById("openRFChat").classList.add("btn-warning");
document.getElementById("openRFChat").classList.add("btn-warning") document.getElementById("openRFChat").classList.remove("btn-secondary");
document.getElementById("openRFChat").classList.remove("btn-secondary") } else {
} document.getElementById("openRFChat").classList.remove("btn-warning");
else document.getElementById("openRFChat").classList.add("btn-secondary");
{
document.getElementById("openRFChat").classList.remove("btn-warning")
document.getElementById("openRFChat").classList.add("btn-secondary")
} }
}); });
ipcRenderer.on("run-tnc-command", (event, arg) => { ipcRenderer.on("run-tnc-command", (event, arg) => {
if (arg.command == "save_my_call") { if (arg.command == "save_my_call") {
sock.saveMyCall(arg.callsign); sock.saveMyCall(arg.callsign);
@ -3811,8 +3808,7 @@ function autostart_tnc() {
} }
//Have the operating system show a notification popup //Have the operating system show a notification popup
function showOsPopUp(title, message) function showOsPopUp(title, message) {
{
if (config.enable_sys_notification == 0) return; if (config.enable_sys_notification == 0) return;
const NOTIFICATION_TITLE = title; const NOTIFICATION_TITLE = title;
const NOTIFICATION_BODY = message; const NOTIFICATION_BODY = message;

View file

@ -261,11 +261,9 @@
class="dropdown-item bg-danger text-white" class="dropdown-item bg-danger text-white"
id="delete_selected_chat" id="delete_selected_chat"
href="#" href="#"
><i ><i class="bi bi-person-x" style="font-size: 1rem"></i>
class="bi bi-person-x" Delete chat</a
style="font-size: 1rem" >
></i>
Delete chat</a>
</li> </li>
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<li> <li>
@ -290,7 +288,8 @@ Delete chat</a>
data-bs-toggle="tooltip" data-bs-toggle="tooltip"
data-bs-trigger="hover" data-bs-trigger="hover"
title="Connected with" title="Connected with"
>------</span> >------</span
>
</div> </div>
</div> </div>

View file

@ -3797,9 +3797,17 @@
</label> </label>
</div> </div>
<div class="input-group input-group-sm mb-1"> <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"> <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> </label>
</div> </div>
<div class="center"> <div class="center">