Change color of RF chat button if new messages are available

This commit is contained in:
Mashintime 2023-06-11 02:07:40 -04:00
parent 41770e1a83
commit 0697ecd0e9
4 changed files with 53 additions and 11 deletions

View file

@ -464,6 +464,18 @@ ipcMain.on("request-update-reception-status", (event, arg) => {
});
//Called by main to query chat if there are new messages
ipcMain.on("request-update-unread-messages", (event) => {
//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);
//mainLog.info("Received reply from chat and ?new messages = " +arg);
});
ipcMain.on("request-open-tnc-log", () => {
logViewer.show();
});

View file

@ -1044,7 +1044,7 @@ update_chat = function (obj) {
}
// add percent and bytes per minute if not existing
console.log(obj.percent)
//console.log(obj.percent)
if (typeof obj.percent == "undefined") {
obj.percent = 0;
obj.bytesperminute = 0;
@ -1073,7 +1073,7 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
} else {
var max_retry_attempts = parseInt(config.max_retry_attempts);
}
console.log(obj.msg);
//console.log(obj.msg);
// define shortmessage
if (obj.msg == "null" || obj.msg == "NULL") {
var shortmsg = obj.type;
@ -1422,7 +1422,7 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
}
if (obj.type == "transmit") {
console.log(obj);
//console.log(obj);
//console.log('msg-' + obj._id + '-status')
if (obj.status == "failed") {
@ -1495,11 +1495,11 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp
/* UPDATE EXISTING ELEMENTS */
} else if (document.getElementById("msg-" + obj._id)) {
console.log("element already exists......");
console.log(obj);
//console.log("element already exists......");
//console.log(obj);
console.log(obj.status)
console.log(obj.attempt)
// console.log(obj.status)
// console.log(obj.attempt)
@ -2660,6 +2660,12 @@ ipcRenderer.on("update-config", (event, data) => {
config = data;
});
ipcRenderer.on("action-update-unread-messages", (event) => {
checkForNewMessages().then(function(count) {
ipcRenderer.send("request-update-unread-messages-main",count);
});
});
// https://stackoverflow.com/a/18650828
function formatBytes(bytes, decimals = 2) {
if (!+bytes) return "0 Bytes";
@ -2790,10 +2796,10 @@ function checkForWaitingMessages(dxcall) {
});
}
function checkForWaitingMessages()
async function checkForNewMessages()
{
var newmsgs;
db.find({
await db.find({
selector: {
new: {$eq: 1},
}, limit:1,
@ -2803,7 +2809,6 @@ function checkForWaitingMessages()
newmsgs=true;
else
newmsgs=false;
//console.log ("New messages count to clear for " + dxcall + ": " + result.docs.length)
})
.catch(function (err) {
console.log(err);

View file

@ -1951,7 +1951,16 @@ function signal_quality_perc_quad(rssi, perfect_rssi = 10, worst_rssi = -150) {
}
var lastHeard = "";
var checkForNewMessageWait=85;
ipcRenderer.on("action-update-tnc-state", (event, arg) => {
//check for new messages
if (checkForNewMessageWait >= 100){
//This is very expensive
ipcRenderer.send("request-update-unread-messages");
checkForNewMessageWait=-1;
}
checkForNewMessageWait++;
// update FFT
if (typeof arg.fft !== "undefined") {
// FIXME: WE need to fix this when disabled waterfall chart
@ -2908,6 +2917,22 @@ ipcRenderer.on("run-tnc-command-fec-iswriting", (event) => {
sock.sendFecIsWriting(config.mycall);
});
//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")
}
});
ipcRenderer.on("run-tnc-command", (event, arg) => {
if (arg.command == "save_my_call") {
sock.saveMyCall(arg.callsign);

View file

@ -189,7 +189,7 @@
data-bs-toggle="tooltip"
data-bs-trigger="hover"
data-bs-html="false"
title="Open the HF chat module. This is currently just a test and not finished, yet!"
title="Open the chat window.  The background will change to yellow if a new message is available."
>
<i class="bi bi-chat-left-text-fill me-2"></i>
<strong>RF Chat</strong>