Implement configurable notifications

This commit is contained in:
Mashintime 2023-06-10 23:14:25 -04:00
parent 51efd0f9bc
commit 3307214c36
4 changed files with 84 additions and 3 deletions

View file

@ -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)) {

View file

@ -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 = `
<div class="m-auto mt-1 p-0 w-50 rounded bg-secondary bg-gradient" id="msg-${obj._id}">
<p class="text-small text-white mb-0 text-break" style="font-size: 0.7rem;"><i class="m-3 bi bi-arrow-left-right"></i>snr: ${obj.snr} - ${timestamp} </p>
@ -1325,6 +1328,11 @@ 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)
{
showOsPopUp("Message received from " + obj.dxcallsign,obj.msg);
}
var new_message = `
<div class="d-flex align-items-center" style="margin-left: auto;"> <!-- max-width: 75%; -->
@ -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 });
}

View file

@ -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 <strong>${dxcallsign}</strong> (${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 });
}

View file

@ -2907,6 +2907,23 @@
<option value="alpha">alpha</option>
</select>
</div>
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50"
>Enable notifications</label
>
<label class="input-group-text w-50">
<div class="form-check form-switch form-check-inline">
<input
class="form-check-input"
type="checkbox"
id="NotificationSwitch"
/>
<label class="form-check-label" for="NotificationSwitch"
>Show system pop-ups</label
>
</div>
</label>
</div>
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50"
>Auto-start TNC/rigctld</label