@@ -1294,6 +1327,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 = `
@@ -1384,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") {
@@ -1457,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)
@@ -1844,6 +1882,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,
@@ -2093,6 +2132,7 @@ function createChatIndex() {
"attempt",
"bytesperminute",
"_attachments",
+ "new",
],
},
})
@@ -2232,9 +2272,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",
@@ -2620,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";
@@ -2749,3 +2795,56 @@ function checkForWaitingMessages(dxcall) {
console.log(err);
});
}
+
+async function checkForNewMessages()
+{
+ var newmsgs;
+ await db.find({
+ selector: {
+ new: {$eq: 1},
+ }, limit:1,
+ })
+ .then(function (result) {
+ if (result.docs.length >0)
+ newmsgs=true;
+ else
+ newmsgs=false;
+ })
+ .catch(function (err) {
+ console.log(err);
+ });
+ return newmsgs;
+}
+
+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);
+ });
+}
+
+//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 61d0f45f..5fe94d3a 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) {
@@ -1371,7 +1388,7 @@ window.addEventListener("DOMContentLoaded", () => {
// Discord Link clicked
document.getElementById("discordUrl").addEventListener("click", () => {
- shell.openExternal("https://discord.gg/jnADeDtxUF");
+ shell.openExternal("https://discord.freedata.app/");
});
// startTNC button clicked
@@ -1938,7 +1955,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
@@ -2258,6 +2284,7 @@ ipcRenderer.on("action-update-tnc-state", (event, arg) => {
"bi bi-chat-fill text-success me-1";
} else {
document.getElementById("spnConnectedWith").className = "bi bi-chat-fill";
+ ipcRenderer.send("request-clear-chat-connected");
}
// HAMLIB STATUS
@@ -2894,6 +2921,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 == "enable_mesh") {
@@ -3090,7 +3133,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"),
@@ -3777,4 +3820,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/chat-module.html b/gui/src/chat-module.html
index dddc0c7d..3447b6e6 100644
--- a/gui/src/chat-module.html
+++ b/gui/src/chat-module.html
@@ -264,7 +264,18 @@
Help
+
+
+
+
+ ------
diff --git a/gui/src/index.html b/gui/src/index.html
index fb187444..685683f0 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
@@ -2911,6 +2911,23 @@
+