From 0697ecd0e9a19b7938934d5f614c60ec291f431f Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sun, 11 Jun 2023 02:07:40 -0400 Subject: [PATCH] Change color of RF chat button if new messages are available --- gui/main.js | 12 ++++++++++++ gui/preload-chat.js | 25 +++++++++++++++---------- gui/preload-main.js | 25 +++++++++++++++++++++++++ gui/src/index.html | 2 +- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/gui/main.js b/gui/main.js index 566453de..13d9fb61 100644 --- a/gui/main.js +++ b/gui/main.js @@ -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(); }); diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 6e9babc5..121f4faa 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -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); diff --git a/gui/preload-main.js b/gui/preload-main.js index 24a72ed7..4bc06253 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -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); diff --git a/gui/src/index.html b/gui/src/index.html index ddd8137b..e910cc4b 100644 --- a/gui/src/index.html +++ b/gui/src/index.html @@ -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." > RF Chat