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) => {
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", () => {
//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) => {

View file

@ -1055,7 +1055,7 @@ if (typeof obj.percent == "undefined") {
// check if wrong status message
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) {
db.upsert(obj._id, function (doc) {
if (!doc.status) {
@ -1064,7 +1064,6 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
return doc;
});
obj.status = "failed";
}
}
if (typeof obj.new == "undefined") {
@ -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
@ -1267,9 +1270,12 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
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");
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,8 +1340,7 @@ 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)
{
if (obj.new == 1) {
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");
}
var new_message = `
<div class="d-flex align-items-center">
${controlarea_transmit}
@ -1486,9 +1489,7 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
}" 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>
}-progress-information">${percent_value} % - ${obj.bytesperminute} Bpm</p>
</div>
</div>
</div>
@ -1508,9 +1509,6 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
// console.log(obj.status)
// console.log(obj.attempt)
if (
!obj.status == "broadcast_transmit" ||
!obj.status == "broadcast_received"
@ -1532,9 +1530,7 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
obj.attempt + "/" + max_retry_attempts;
}
if (obj.status == "transmit") {
document.getElementById("msg-" + obj._id + "-status").innerHTML =
get_icon_for_state(obj.status);
@ -1548,7 +1544,6 @@ if (typeof obj.percent !== "undefined") {
document.getElementById(
"msg-" + obj._id + "-progress-information"
).innerHTML = obj.percent + "% - " + obj.bytesperminute + " Bpm";
} else {
document
.getElementById("msg-" + obj._id + "-progress")
@ -1559,12 +1554,8 @@ if (typeof obj.percent !== "undefined") {
document.getElementById(
"msg-" + obj._id + "-progress-information"
).innerHTML = "0% - 0 Bpm";
}
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) {
@ -2215,13 +2201,11 @@ async function updateAllChat(clear) {
$and: [
{ dxcallsign: { $exists: true } },
{ timestamp: { $exists: true } },
{ $or: chatFilter }]
{ $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
@ -2812,19 +2795,18 @@ function checkForWaitingMessages(dxcall) {
});
}
async function checkForNewMessages()
{
async function checkForNewMessages() {
var newmsgs;
await db.find({
await db
.find({
selector: {
new: { $eq: 1 },
}, limit: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);
@ -2837,9 +2819,10 @@ 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}}
//]
// }
})
@ -2847,8 +2830,7 @@ function clearUnreadMessages(dxcall) {
//console.log(result);
//console.log ("New messages count to clear for " + dxcall + ": " + result.docs.length)
result.docs.forEach(function (item) {
if (item.new ==1)
{
if (item.new == 1) {
db.upsert(item._id, function (doc) {
doc.new = 0;
//console.log("Clearing new on _id " + item._id);
@ -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;
}
@ -2890,20 +2878,20 @@ async function dbClean()
{ type: "ping" },
];
await db.find({
await db
.find({
selector: {
$and: [
{timestamp: { $lt: timestampPurge } },
{ $or: purgeFilter }]
}
$and: [{ timestamp: { $lt: timestampPurge } }, { $or: purgeFilter }],
},
})
.then(async function (result) {
//console.log("Purging " + result.docs.length + " beacons received before " + timestampPurge);
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);
@ -2916,5 +2904,9 @@ async function dbClean()
//Compact database
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
document.getElementById("NotificationSwitch").addEventListener("click", () => {
document
.getElementById("NotificationSwitch")
.addEventListener("click", () => {
if (document.getElementById("NotificationSwitch").checked == true) {
config.enable_sys_notification = 1;
} else {
@ -1632,8 +1634,6 @@ document.getElementById("btnCleanDB").addEventListener("click", () => {
var radiocontrol = "rigctld";
}
daemon.testHamlib(
radiocontrol,
deviceid,
@ -2439,14 +2439,15 @@ 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();
@ -2927,19 +2928,15 @@ 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) => {
//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);
@ -3811,8 +3808,7 @@ function autostart_tnc() {
}
//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;

View file

@ -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>
@ -290,7 +288,8 @@ Delete chat</a>
data-bs-toggle="tooltip"
data-bs-trigger="hover"
title="Connected with"
>------</span>
>------</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">