From cd600110a595798536ad7f6b346777e99cee06d1 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 10 Jun 2023 12:54:03 -0400 Subject: [PATCH 01/19] Ignore some flex radio devices --- tnc/audio.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tnc/audio.py b/tnc/audio.py index 575bde54..237dd6f4 100644 --- a/tnc/audio.py +++ b/tnc/audio.py @@ -76,6 +76,9 @@ def fetch_audio_devices(input_devices, output_devices): # Use a try/except block because Windows doesn't have an audio device range try: name = device["name"] + # Ignore some Flex Radio devices to make device selection simpler + if name.startswith("DAX RESERVED") or name.startswith("DAX IQ"): + continue; max_output_channels = device["max_output_channels"] max_input_channels = device["max_input_channels"] From 51efd0f9bc6dafa4cd097237278dbc895dc3e79c Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 10 Jun 2023 12:57:23 -0400 Subject: [PATCH 02/19] Append indicator before callsign on new msg --- gui/preload-chat.js | 61 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 46f0ec6e..4f72dd7e 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -785,6 +785,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; + obj.new = 1; console.log(obj); add_obj_to_database(obj); update_chat_obj_by_uuid(obj.uuid); @@ -813,6 +814,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; + obj.new = 1; add_obj_to_database(obj); update_chat_obj_by_uuid(obj.uuid); @@ -832,7 +834,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - + obj.new = 1; add_obj_to_database(obj); update_chat_obj_by_uuid(obj.uuid); @@ -851,7 +853,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - + obj.new = 1; add_obj_to_database(obj); update_chat_obj_by_uuid(obj.uuid); @@ -879,6 +881,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; } else if (splitted_data[1] == "req" && splitted_data[2] == "0") { obj.uuid = uuidv4().toString(); obj.timestamp = Math.floor(Date.now() / 1000); @@ -891,7 +894,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - + obj.new=1; if (config.enable_request_profile == "True") { sendUserData(item.dxcallsign); } @@ -907,7 +910,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - + obj.new=1; if (config.enable_request_shared_folder == "True") { sendSharedFolderList(item.dxcallsign); } @@ -928,7 +931,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - + obj.new=1; if (config.enable_request_shared_folder == "True") { sendSharedFolderFile(item.dxcallsign, name); } @@ -944,7 +947,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - + obj.new=1; console.log(splitted_data); let userData = new Object(); userData.user_info_image = splitted_data[2]; @@ -973,7 +976,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - + obj.new=1; console.log(splitted_data); let userData = new Object(); @@ -1001,6 +1004,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=1; } else { console.log("no rule matched for handling received data!"); } @@ -1060,7 +1064,10 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp } } - + if (typeof obj.new == "undefined"){ + obj.new=0; + } + if (typeof config.max_retry_attempts == "undefined") { var max_retry_attempts = 3; } else { @@ -1201,7 +1208,7 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp - ${dxcallsign} + ${dxcallsign} ${dxgrid} ${timestampHours} ${shortmsg} @@ -1230,6 +1237,12 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp .getElementById("chat-" + dxcallsign + "-list") .addEventListener("click", function () { //document.getElementById('chatModuleDxCall').value = dxcallsign; + + //Reset unread messages and new message indicator + let clear = selected_callsign; + clearUnreadMessages(clear); + document.getElementById(`chat-${selected_callsign}-list-displaydxcall`).textContent=selected_callsign; + selected_callsign = dxcallsign; setTimeout(scrollMessagesToBottom, 200); @@ -1251,6 +1264,7 @@ 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; } // APPEND MESSAGES TO CALLSIGN @@ -1861,6 +1875,7 @@ add_obj_to_database = function (obj) { status: obj.status, snr: obj.snr, attempt: obj.attempt, + new: obj.new, _attachments: { [obj.filename]: { content_type: obj.filetype, @@ -2110,6 +2125,7 @@ function createChatIndex() { "attempt", "bytesperminute", "_attachments", + "new", ], }, }) @@ -2249,9 +2265,9 @@ function getSetUserSharedFolder(selected_callsign) { .then(function (data) { console.log(data); - console.log(data.user_shared_folder); if (typeof data.user_shared_folder !== "undefined") { + console.log(data.user_shared_folder); // shared folder table var icons = [ "aac", @@ -2766,3 +2782,28 @@ function checkForWaitingMessages(dxcall) { console.log(err); }); } + + +function clearUnreadMessages(dxcall) { + //console.log(dxcall); + db.find({ + selector: { + dxcallsign: dxcall, + new: {$eq: 1}, + } + }) + .then(function (result) { + //console.log(result); + //console.log ("New messages count to clear for " + dxcall + ": " + result.docs.length) + result.docs.forEach(function (item) { + 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); + }); +} \ No newline at end of file From 3307214c3602f1d057b3fedbb11a7bf9d14f3060 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 10 Jun 2023 23:14:25 -0400 Subject: [PATCH 03/19] Implement configurable notifications --- gui/main.js | 3 ++- gui/preload-chat.js | 39 ++++++++++++++++++++++++++++++++++++++- gui/preload-main.js | 28 +++++++++++++++++++++++++++- gui/src/index.html | 17 +++++++++++++++++ 4 files changed, 84 insertions(+), 3 deletions(-) diff --git a/gui/main.js b/gui/main.js index b3a0119e..566453de 100644 --- a/gui/main.js +++ b/gui/main.js @@ -100,7 +100,8 @@ const configDefaultSettings = "max_retry_attempts" : 5, \ "enable_auto_retry" : "False", \ "tx_delay" : 0, \ - "auto_start": 0 \ + "auto_start": 0, \ + "notification": 1 \ }'; if (!fs.existsSync(configPath)) { diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 4f72dd7e..56ef144e 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -1274,7 +1274,10 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp if (config.enable_auto_retry.toUpperCase() == "TRUE") { checkForWaitingMessages(obj.dxcallsign); } - + if (obj.new == 1) + { + showOsPopUp("Ping from " + obj.dxcallsign,"You've been ping'd!"); + } var new_message = `

snr: ${obj.snr} - ${timestamp}

@@ -1325,6 +1328,11 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp var message_html = obj.msg.replaceAll(/\n/g, "
"); if (obj.type == "received") { + if (obj.new == 1) + { + showOsPopUp("Message received from " + obj.dxcallsign,obj.msg); + } + var new_message = `
@@ -2783,6 +2791,26 @@ function checkForWaitingMessages(dxcall) { }); } +function checkForWaitingMessages() +{ + var newmsgs; + db.find({ + selector: { + new: {$eq: 1}, + }, limit:1, + }) + .then(function (result) { + if (result.docs.length >0) + newmsgs=true; + else + newmsgs=false; + //console.log ("New messages count to clear for " + dxcall + ": " + result.docs.length) + }) + .catch(function (err) { + console.log(err); + }); + return newmsgs; +} function clearUnreadMessages(dxcall) { //console.log(dxcall); @@ -2806,4 +2834,13 @@ function clearUnreadMessages(dxcall) { .catch(function (err) { console.log(err); }); +} + +//Have the operating system show a notification popup +function showOsPopUp(title, message) +{ + if (config.notification == 0) return; + const NOTIFICATION_TITLE = title; + const NOTIFICATION_BODY = message; + new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }); } \ No newline at end of file diff --git a/gui/preload-main.js b/gui/preload-main.js index b11eac5b..24a72ed7 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -390,6 +390,12 @@ window.addEventListener("DOMContentLoaded", () => { document.getElementById("AutoStartSwitch").checked = false; } + if (config.notification == 1) { + document.getElementById("NotificationSwitch").checked = true; + } else { + document.getElementById("NotificationSwitch").checked = false; + } + // theme selector changeGuiDesign(config.theme); @@ -1213,6 +1219,17 @@ window.addEventListener("DOMContentLoaded", () => { FD.saveConfig(config, configPath); }); + //Handle change of Notification settings + document.getElementById("NotificationSwitch").addEventListener("click", () => { + if (document.getElementById("NotificationSwitch").checked == true) { + config.notification = 1; + } else { + config.notification = 0; + } + //fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + FD.saveConfig(config, configPath); + }); + // enable fsk Switch clicked document.getElementById("fskModeSwitch").addEventListener("click", () => { if (document.getElementById("fskModeSwitch").checked == true) { @@ -3072,7 +3089,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 ${dxcallsign} (${dxgrid})`; - + showOsPopUp("CQ from " + dxcallsign,"Say hello!"); displayToast( (type = "success"), (icon = "bi-broadcast"), @@ -3759,4 +3776,13 @@ function autostart_tnc() { //Now start TNC document.getElementById("startTNC").click(); } +} + +//Have the operating system show a notification popup +function showOsPopUp(title, message) +{ + if (config.notification == 0) return; + const NOTIFICATION_TITLE = title; + const NOTIFICATION_BODY = message; + new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }); } \ No newline at end of file diff --git a/gui/src/index.html b/gui/src/index.html index eff74b0d..ddd8137b 100644 --- a/gui/src/index.html +++ b/gui/src/index.html @@ -2907,6 +2907,23 @@
+
+ + +
Date: Sat, 10 Jun 2023 23:50:30 -0400 Subject: [PATCH 04/19] Reset new messages on click instead of after losing focus --- gui/preload-chat.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 56ef144e..6e9babc5 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -1237,13 +1237,12 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp .getElementById("chat-" + dxcallsign + "-list") .addEventListener("click", function () { //document.getElementById('chatModuleDxCall').value = dxcallsign; - + selected_callsign = dxcallsign; //Reset unread messages and new message indicator let clear = selected_callsign; clearUnreadMessages(clear); document.getElementById(`chat-${selected_callsign}-list-displaydxcall`).textContent=selected_callsign; - selected_callsign = dxcallsign; setTimeout(scrollMessagesToBottom, 200); //get user information From 0697ecd0e9a19b7938934d5f614c60ec291f431f Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sun, 11 Jun 2023 02:07:40 -0400 Subject: [PATCH 05/19] 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 From edd53929be2e359eaffb06ac488f2beafdfb78ad Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sun, 11 Jun 2023 02:29:31 -0400 Subject: [PATCH 06/19] Code quality fixes --- gui/main.js | 2 +- tnc/audio.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/main.js b/gui/main.js index 13d9fb61..a888601e 100644 --- a/gui/main.js +++ b/gui/main.js @@ -465,7 +465,7 @@ 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) => { +ipcMain.on("request-update-unread-messages",() => { //mainLog.info("Got request to check if chat has new messages") chat.webContents.send("action-update-unread-messages"); diff --git a/tnc/audio.py b/tnc/audio.py index 237dd6f4..e4397b86 100644 --- a/tnc/audio.py +++ b/tnc/audio.py @@ -78,7 +78,7 @@ def fetch_audio_devices(input_devices, output_devices): name = device["name"] # Ignore some Flex Radio devices to make device selection simpler if name.startswith("DAX RESERVED") or name.startswith("DAX IQ"): - continue; + continue max_output_channels = device["max_output_channels"] max_input_channels = device["max_input_channels"] From 8f308d9adc03000b91664c5f8627f0dd2966ff46 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sun, 11 Jun 2023 10:40:01 -0400 Subject: [PATCH 07/19] Update config name for notifications --- gui/main.js | 2 +- gui/preload-chat.js | 2 +- gui/preload-main.js | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gui/main.js b/gui/main.js index a888601e..0a699244 100644 --- a/gui/main.js +++ b/gui/main.js @@ -101,7 +101,7 @@ const configDefaultSettings = "enable_auto_retry" : "False", \ "tx_delay" : 0, \ "auto_start": 0, \ - "notification": 1 \ + "enable_sys_notification": 1 \ }'; if (!fs.existsSync(configPath)) { diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 121f4faa..7506fbbf 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -2843,7 +2843,7 @@ function clearUnreadMessages(dxcall) { //Have the operating system show a notification popup function showOsPopUp(title, message) { - if (config.notification == 0) return; + if (config.enable_sys_notification == 0) return; const NOTIFICATION_TITLE = title; const NOTIFICATION_BODY = message; new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }); diff --git a/gui/preload-main.js b/gui/preload-main.js index 4bc06253..df277654 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -390,7 +390,7 @@ window.addEventListener("DOMContentLoaded", () => { document.getElementById("AutoStartSwitch").checked = false; } - if (config.notification == 1) { + if (config.enable_sys_notification == 1) { document.getElementById("NotificationSwitch").checked = true; } else { document.getElementById("NotificationSwitch").checked = false; @@ -1222,9 +1222,9 @@ window.addEventListener("DOMContentLoaded", () => { //Handle change of Notification settings document.getElementById("NotificationSwitch").addEventListener("click", () => { if (document.getElementById("NotificationSwitch").checked == true) { - config.notification = 1; + config.enable_sys_notification = 1; } else { - config.notification = 0; + config.enable_sys_notification = 0; } //fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); FD.saveConfig(config, configPath); @@ -3806,7 +3806,7 @@ function autostart_tnc() { //Have the operating system show a notification popup function showOsPopUp(title, message) { - if (config.notification == 0) return; + if (config.enable_sys_notification == 0) return; const NOTIFICATION_TITLE = title; const NOTIFICATION_BODY = message; new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }); From a65d2d52def511a16fa3813d98c95b17c0b89ee1 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Wed, 14 Jun 2023 18:03:10 -0400 Subject: [PATCH 08/19] Clean old beacons and compact DB. --- gui/preload-chat.js | 46 +++++++++++++++++++++++++++++++++++++--- gui/src/chat-module.html | 11 +++++++--- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 7506fbbf..deaf3568 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -165,7 +165,9 @@ window.addEventListener("DOMContentLoaded", () => { "user_info_website", "user_info_comments", ]; - + document.getElementById("btndbClean").addEventListener("click", () => { + dbClean(); + }); users .find({ selector: { @@ -819,7 +821,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { add_obj_to_database(obj); update_chat_obj_by_uuid(obj.uuid); - // handle beacon + // handle ping-ack } else if (item.ping == "acknowledge") { obj.timestamp = parseInt(item.timestamp); obj.dxcallsign = item.dxcallsign; @@ -2847,4 +2849,42 @@ function showOsPopUp(title, message) const NOTIFICATION_TITLE = title; const NOTIFICATION_BODY = message; new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }); -} \ No newline at end of file +} + +//Function to clean old beacons and optimize database +async function dbClean() +{ + //Only keep the most x latest days of beacons + let beaconKeep = 7; + let timestampPurge = Math.floor((Date.now()- beaconKeep * 24*60*60*1000) / 1000) ; + if (confirm("Delete beacons older than " + beaconKeep + " days and compact database?")) { + } else { + return; + } + + await db.find({ + selector: { + timestamp: {$lt: timestampPurge}, + type: "beacon", + } + }) + .then(async function (result) { + console.log("Purging " + result.docs.length + " beacons received before " + timestampPurge); + result.docs.forEach(async function (item) { + await db.get(item._id) + .then(async function (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."); +} diff --git a/gui/src/chat-module.html b/gui/src/chat-module.html index 3447b6e6..e2d8ba57 100644 --- a/gui/src/chat-module.html +++ b/gui/src/chat-module.html @@ -264,9 +264,14 @@ Help - - - +
  • + +
  • Date: Fri, 16 Jun 2023 22:52:33 -0400 Subject: [PATCH 09/19] Adjust 'new' items and change background of list with new items --- gui/preload-chat.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index deaf3568..b1c941b0 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -787,7 +787,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - obj.new = 1; + obj.new = 0; console.log(obj); add_obj_to_database(obj); update_chat_obj_by_uuid(obj.uuid); @@ -816,7 +816,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - obj.new = 1; + obj.new = 0; add_obj_to_database(obj); update_chat_obj_by_uuid(obj.uuid); @@ -836,7 +836,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - obj.new = 1; + obj.new = 0; add_obj_to_database(obj); update_chat_obj_by_uuid(obj.uuid); @@ -855,7 +855,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - obj.new = 1; + obj.new = 0; add_obj_to_database(obj); update_chat_obj_by_uuid(obj.uuid); @@ -896,7 +896,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - obj.new=1; + obj.new=0; if (config.enable_request_profile == "True") { sendUserData(item.dxcallsign); } @@ -912,7 +912,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - obj.new=1; + obj.new=0; if (config.enable_request_shared_folder == "True") { sendSharedFolderList(item.dxcallsign); } @@ -933,7 +933,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - obj.new=1; + obj.new=0; if (config.enable_request_shared_folder == "True") { sendSharedFolderFile(item.dxcallsign, name); } @@ -949,7 +949,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - obj.new=1; + obj.new=0; console.log(splitted_data); let userData = new Object(); userData.user_info_image = splitted_data[2]; @@ -978,7 +978,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - obj.new=1; + obj.new=0; console.log(splitted_data); let userData = new Object(); @@ -1006,7 +1006,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=1; + obj.new=0; } else { console.log("no rule matched for handling received data!"); } @@ -1244,7 +1244,7 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp 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"); setTimeout(scrollMessagesToBottom, 200); //get user information @@ -1265,7 +1265,11 @@ 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; + 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 @@ -1275,10 +1279,10 @@ var TimeDifference = (new Date().getTime()/1000) - obj.timestamp if (config.enable_auto_retry.toUpperCase() == "TRUE") { checkForWaitingMessages(obj.dxcallsign); } - if (obj.new == 1) - { - showOsPopUp("Ping from " + obj.dxcallsign,"You've been ping'd!"); - } + //if (obj.new == 1) + //{ + // showOsPopUp("Ping from " + obj.dxcallsign,"You've been ping'd!"); + //} var new_message = `

    snr: ${obj.snr} - ${timestamp}

    From 928da54325c7d9d1a683f843e5e0984678971a71 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sun, 18 Jun 2023 14:53:07 -0400 Subject: [PATCH 10/19] Allow filtering on new messages --- gui/src/chat-module.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gui/src/chat-module.html b/gui/src/chat-module.html index e2d8ba57..b30c5bfa 100644 --- a/gui/src/chat-module.html +++ b/gui/src/chat-module.html @@ -161,7 +161,21 @@ id="chkMessage" /> +
    +
    +
    +
    + + +
    From cc65e05a0e855042e594ee6ac76d1f2016611124 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sun, 18 Jun 2023 14:57:18 -0400 Subject: [PATCH 11/19] Sort chat call list alphabetically --- gui/preload-chat.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index b1c941b0..df2628f6 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -140,6 +140,7 @@ var chatFilter = [ { type: "ping-ack" }, { type: "broadcast_received" }, { type: "broadcast_transmit" }, + { type: "new"} //{ type: "request" }, //{ type: "response" }, @@ -218,9 +219,11 @@ window.addEventListener("DOMContentLoaded", () => { //Add event listener for filter apply button document.getElementById("btnFilter").addEventListener("click", () => { - chatFilter = [{ type: "newchat" }]; - if (document.getElementById("chkMessage").checked == true) + chatFilter.length=0; + if (document.getElementById("chkMessage").checked == true) { + chatFilter = [{ type: "newchat" }]; chatFilter.push({ type: "received" }, { type: "transmit" }); + } if (document.getElementById("chkPing").checked == true) chatFilter.push({ type: "ping" }); if (document.getElementById("chkPingAck").checked == true) @@ -231,6 +234,8 @@ window.addEventListener("DOMContentLoaded", () => { chatFilter.push({ type: "request" }); if (document.getElementById("chkResponse").checked == true) chatFilter.push({ type: "response" }); + if (document.getElementById("chkNewMessage").checked == true) + chatFilter.push({new:1}); updateAllChat(true); }); @@ -2200,7 +2205,10 @@ async function updateAllChat(clear) { await db .createIndex({ index: { - fields: [{ timestamp: "asc" }], + fields: [ + { dxcallsign:"asc" }, + { timestamp:"asc" }, + ], }, }) .then(async function (result) { @@ -2208,14 +2216,16 @@ async function updateAllChat(clear) { await db .find({ selector: { - $and: [{ timestamp: { $exists: true } }, { $or: chatFilter }], + $and: [ + {dxcallsign: { $exists: true } }, + {timestamp: { $exists: true } }, + { $or: chatFilter }] //$or: chatFilter }, sort: [ - { - timestamp: "asc", - }, - ], + { dxcallsign:"asc" }, + { timestamp: "asc" }, + ] }) .then(async function (result) { console.log(result); From 74ba4299156f3e8ab6c0a5a6b7f2d3e397250293 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sun, 18 Jun 2023 20:33:12 -0400 Subject: [PATCH 12/19] Fix chat filter --- gui/preload-chat.js | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index df2628f6..0721ac2d 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -140,7 +140,6 @@ var chatFilter = [ { type: "ping-ack" }, { type: "broadcast_received" }, { type: "broadcast_transmit" }, - { type: "new"} //{ type: "request" }, //{ type: "response" }, From 1cb92af31132b188bb03eed075e2587453dd8dbd Mon Sep 17 00:00:00 2001 From: Mashintime Date: Mon, 19 Jun 2023 18:31:51 -0400 Subject: [PATCH 13/19] clearUnreadmsgs stopped doing what it's supposed to --- gui/preload-chat.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 0721ac2d..36972e5c 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -2833,21 +2833,27 @@ async function checkForNewMessages() function clearUnreadMessages(dxcall) { //console.log(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: { - dxcallsign: dxcall, - new: {$eq: 1}, - } - }) + selector: //{ + //$and:[ + {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) { - db.upsert(item._id, function (doc) { - doc.new=0; - //console.log("Clearing new on _id " + item._id); - return doc; - }); + 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) { From ed7eb4762bbda7fa65ed0214c261d744f3e7716c Mon Sep 17 00:00:00 2001 From: Mashintime Date: Tue, 27 Jun 2023 16:43:52 -0400 Subject: [PATCH 14/19] Mark new broadcasts as new --- gui/preload-chat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 36972e5c..d12d1368 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -791,7 +791,7 @@ ipcRenderer.on("action-new-msg-received", (event, arg) => { obj.filename = "null"; obj.filetype = "null"; obj.file = "null"; - obj.new = 0; + obj.new = 1; console.log(obj); add_obj_to_database(obj); update_chat_obj_by_uuid(obj.uuid); From fe549c5c65002e9ee64f99543cc5eff613651845 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 1 Jul 2023 11:22:41 -0400 Subject: [PATCH 15/19] Bootstrap 5.3.0 and icons --- gui/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/package.json b/gui/package.json index b21f3ace..93cc1b98 100644 --- a/gui/package.json +++ b/gui/package.json @@ -32,8 +32,8 @@ "@electron/osx-sign": "^1.0.4", "@popperjs/core": "^2.11.6", "blob-util": "^2.0.2", - "bootstrap": "^5.3.0-alpha.3", - "bootstrap-icons": "^1.10.3", + "bootstrap": "^5.3.0", + "bootstrap-icons": "^1.10.5", "bootswatch": "^5.2.3", "browser-image-compression": "^2.0.0", "chart.js": "^4.2.1", From 6020ea9ce9477304ca538edfe14eaf1d166e5ad0 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 1 Jul 2023 12:42:58 -0400 Subject: [PATCH 16/19] Add pings to database clean up --- gui/preload-chat.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index d12d1368..ad70f9b1 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -2875,20 +2875,30 @@ 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 older than " + beaconKeep + " days and compact database?")) { + if (confirm("Delete beacons and pings older than " + beaconKeep + " days and compact database?")) { } else { return; } + + //Items to purge from database + var purgeFilter = [ + { type: "beacon" }, + { type: "ping-ack" }, + { type: "ping" }, + ]; await db.find({ selector: { - timestamp: {$lt: timestampPurge}, - type: "beacon", + $and: [ + {timestamp: { $lt: timestampPurge } }, + { $or: purgeFilter }] } }) .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; result.docs.forEach(async function (item) { await db.get(item._id) .then(async function (doc) { @@ -2905,5 +2915,5 @@ async function dbClean() //Compact database await db.compact(); - window.alert("Database maintenance is complete."); + window.alert("Database maintenance is complete. " + itemCount + " items removed from database."); } From c0d65c3f9d80433d2020c62f2510aa121e9d858e Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 1 Jul 2023 17:03:22 -0400 Subject: [PATCH 17/19] Move DB maint to settings/exp section --- gui/main.js | 5 +++++ gui/preload-chat.js | 6 +++++- gui/preload-main.js | 7 +++++++ gui/src/chat-module.html | 16 ++++++---------- gui/src/index.html | 6 ++++++ 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/gui/main.js b/gui/main.js index 0a699244..1901a5ac 100644 --- a/gui/main.js +++ b/gui/main.js @@ -476,6 +476,11 @@ ipcMain.on("request-update-unread-messages-main", (event,arg) => { //mainLog.info("Received reply from chat and ?new messages = " +arg); }); +//Called by main to notify chat we should clean the DB +ipcMain.on("request-clean-db", (event,arg) => { + chat.webContents.send("action-clean-db"); +}); + ipcMain.on("request-open-tnc-log", () => { logViewer.show(); }); diff --git a/gui/preload-chat.js b/gui/preload-chat.js index ad70f9b1..7e1693b3 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -2681,6 +2681,10 @@ ipcRenderer.on("action-update-unread-messages", (event) => { }); }); +ipcRenderer.on("action-clean-db", (event) => { + dbClean(); +}); + // https://stackoverflow.com/a/18650828 function formatBytes(bytes, decimals = 2) { if (!+bytes) return "0 Bytes"; @@ -2915,5 +2919,5 @@ async function dbClean() //Compact database await db.compact(); - window.alert("Database maintenance is complete. " + itemCount + " items removed from database."); + window.alert("Database maintenance is complete. " + itemCount + " items removed from database. It's recommended you now restart the GUI."); } diff --git a/gui/preload-main.js b/gui/preload-main.js index df277654..38d73a2f 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -1606,6 +1606,11 @@ window.addEventListener("DOMContentLoaded", () => { daemon.stopTNC(); }); +// btnCleanDB button clicked +document.getElementById("btnCleanDB").addEventListener("click", () => { + ipcRenderer.send("request-clean-db"); +}); + // TEST HAMLIB document.getElementById("testHamlib").addEventListener("click", () => { var data_bits = document.getElementById("hamlib_data_bits").value; @@ -1627,6 +1632,8 @@ window.addEventListener("DOMContentLoaded", () => { var radiocontrol = "rigctld"; } + + daemon.testHamlib( radiocontrol, deviceid, diff --git a/gui/src/chat-module.html b/gui/src/chat-module.html index b30c5bfa..ba116fcb 100644 --- a/gui/src/chat-module.html +++ b/gui/src/chat-module.html @@ -261,9 +261,13 @@ class="dropdown-item bg-danger text-white" id="delete_selected_chat" href="#" - >Delete chat + > +Delete chat +
  • -
  • - -
  • +
    + + +
    These options may From 202a54dcea0f3dd67227b11779f75c751c70dd16 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 1 Jul 2023 17:07:02 -0400 Subject: [PATCH 18/19] Button no longer exists --- gui/preload-chat.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 7e1693b3..6a9f5db4 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -165,9 +165,6 @@ window.addEventListener("DOMContentLoaded", () => { "user_info_website", "user_info_comments", ]; - document.getElementById("btndbClean").addEventListener("click", () => { - dbClean(); - }); users .find({ selector: { From 1306bada1d16f7d155065b4252bbe866430aba8a Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 1 Jul 2023 17:12:58 -0400 Subject: [PATCH 19/19] Fix CodeFactor issue --- gui/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/main.js b/gui/main.js index 1901a5ac..78ee9b6e 100644 --- a/gui/main.js +++ b/gui/main.js @@ -477,7 +477,7 @@ ipcMain.on("request-update-unread-messages-main", (event,arg) => { }); //Called by main to notify chat we should clean the DB -ipcMain.on("request-clean-db", (event,arg) => { +ipcMain.on("request-clean-db", () => { chat.webContents.send("action-clean-db"); });