From c0aab489c3dafe417ace89a4b8464cdb0c709324 Mon Sep 17 00:00:00 2001 From: Christian Bayer Date: Thu, 24 Aug 2023 11:45:33 -0400 Subject: [PATCH 1/6] WIP: initial push notification implementation --- package.nw/GridTracker.html | 53 +++++++++++++++++++++++++++++++++++++ package.nw/i18n/de.json | 6 +++++ package.nw/lib/defaults.js | 7 ++++- package.nw/lib/gt.js | 10 +++++++ package.nw/lib/gtws.js | 52 +++++++++++++++++++++++++++++++++++- 5 files changed, 126 insertions(+), 2 deletions(-) diff --git a/package.nw/GridTracker.html b/package.nw/GridTracker.html index af6a155..1fe5cf3 100644 --- a/package.nw/GridTracker.html +++ b/package.nw/GridTracker.html @@ -2978,6 +2978,59 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +
+ + + + + + + + + + +
+ + +
SimplePush API Key
+ +
+
+
+ + + + + + + + + + + + + +
+ + +
Pushover Credentials
+ + +
+ + +
+

diff --git a/package.nw/i18n/de.json b/package.nw/i18n/de.json index 9012337..2feceb7 100644 --- a/package.nw/i18n/de.json +++ b/package.nw/i18n/de.json @@ -166,6 +166,12 @@ "settings.Alerts.label": "Alarme", "settings.CallRoster.label": "Rufzeichenliste", "settings.OAMS.label": "OAMS", + "settings.OAMS.simplepush.enable.label": "Simplepush Nachrichtenweiterleitung ein/aus", + "settings.OAMS.simplepush.apikey.label": "Simplepush API Key", + "settings.OAMS.pushover.enable.label": "Pushover Nachrichtenweiterleitung ein/aus", + "settings.OAMS.pushover.credentials.label": "Pushover Zugangsdaten", + "settings.OAMS.pushover.username.label": "Benutzername", + "settings.OAMS.pushover.token.label": "Token", "settings.Logbook.label": "Logbook", "settings.Update.label": "Update", "settings.About.label": "Über", diff --git a/package.nw/lib/defaults.js b/package.nw/lib/defaults.js index 1e018b0..fe08fa6 100644 --- a/package.nw/lib/defaults.js +++ b/package.nw/lib/defaults.js @@ -193,7 +193,12 @@ var def_msgSettings = { msgFrequencySelect: 0, msgActionSelect: 1, msgAwaySelect: 0, - msgAwayText: "I am away from the shack at the moment" + msgAwayText: "I am away from the shack at the moment", + msgSimplepush: false, + msgSimplePushApiKey: "", + msgPushover: false, + msgPushoverUsername: "", + msgPushoverToken: "" }; var def_receptionSettings = { diff --git a/package.nw/lib/gt.js b/package.nw/lib/gt.js index 2533cc5..37483c9 100644 --- a/package.nw/lib/gt.js +++ b/package.nw/lib/gt.js @@ -10677,6 +10677,16 @@ function setOamsBandActivityNeighbors(checkbox) oamsBandActivityCheck(); } +function setOamsSimplepush(checkbox) +{ + GT.appSettings.msgSimplepush = checkbox.checked; +} + +function setOamsPushover(checkbox) +{ + GT.appSettings.msgPushover = checkbox.checked; +} + function setMsgEnable(checkbox) { GT.appSettings.gtMsgEnable = checkbox.checked; diff --git a/package.nw/lib/gtws.js b/package.nw/lib/gtws.js index ed4f4a4..46c6d12 100644 --- a/package.nw/lib/gtws.js +++ b/package.nw/lib/gtws.js @@ -567,6 +567,46 @@ function htmlEntities(str) .replace(/"/g, """); } +function sendSimplePushMessage(cid, jsmesg) +{ + const url = "https://api.simplepush.io/send"; + let data = { key: GT.msgSettings.msgSimplePushApiKey, title: "GridTracker Chat Message", msg: jsmesg.call + ": " + jsmesg.msg }; + getPostBuffer( + url, + null, // callback, + null, + "https", + 443, + data, + 500, // timeoutMs, + null, // timeoutCallback, + "simplepush" + ); +} + +function sendPushOverMessage(cid, jsmesg) +{ + const url = "https://api.pushover.net/1/messages.json"; + let data = { + user: GT.msgSettings.msgPushoverUsername, + token: GT.msgSettings.msgPushoverToken, + title: + "GridTracker Chat Message", + message: jsmesg.call + ": " + jsmesg.msg + }; + getPostBuffer( + url, + null, // callback, + null, + "https", + 443, + data, + 500, // timeoutMs, + null, // timeoutCallback, + "pushover" + ); +} + function gtChatMessage(jsmesg) { if (GT.appSettings.gtMsgEnable == true) @@ -580,7 +620,7 @@ function gtChatMessage(jsmesg) } catch (e) { - jsmesg.msg = "Corrupt message recieved"; + jsmesg.msg = "Corrupt message received"; } if (jsmesg.call != null && jsmesg.call != "" && jsmesg.call != "NOCALL") @@ -589,6 +629,16 @@ function gtChatMessage(jsmesg) GT.gtUnread[cid] = true; GT.gtCurrentMessageCount++; + if (GT.msgSettings.msgSimplepush && GT.msgSettings.msgSimplePushApiKey != null) + { + sendSimplePushMessage(cid, jsmesg); + } + if (GT.msgSettings.msgPushover && GT.msgSettings.pushoverUsername != null && + GT.msgSettings.pushoverToken != null) + { + sendPushOverMessage(cid, jsmesg); + } + if (newChatMessage(cid, jsmesg) == false) alertChatMessage(); if (GT.msgSettings.msgAwaySelect == 1 && !(cid in GT.gtSentAwayToCid)) From ea8559af144e73ce2fa3434d52f7632b0820a6d0 Mon Sep 17 00:00:00 2001 From: Christian Bayer Date: Fri, 25 Aug 2023 13:02:40 -0400 Subject: [PATCH 2/6] WIP --- package.nw/GridTracker.html | 10 ++++++---- package.nw/lib/gt.js | 4 +++- package.nw/lib/gtws.js | 6 +++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.nw/GridTracker.html b/package.nw/GridTracker.html index 1fe5cf3..62b6ac5 100644 --- a/package.nw/GridTracker.html +++ b/package.nw/GridTracker.html @@ -2983,8 +2983,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @@ -3005,8 +3006,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/package.nw/lib/gt.js b/package.nw/lib/gt.js index 37483c9..19b6b5e 100644 --- a/package.nw/lib/gt.js +++ b/package.nw/lib/gt.js @@ -13024,6 +13024,8 @@ function loadViewSettings() function loadMsgSettings() { msgEnable.checked = GT.appSettings.gtMsgEnable; + msgSimplepush.checked = GT.appSettings.msgSimplepush; + msgPushover.checked = GT.appSettings.msgPushover; GTspotEnable.checked = GT.appSettings.gtSpotEnable; oamsBandActivity.checked = GT.appSettings.oamsBandActivity; @@ -16202,4 +16204,4 @@ function refreshSpotsNoTx() } nodeTimers.setInterval(refreshSpotsNoTx, 300000); -nodeTimers.setTimeout(refreshSpotsNoTx, 300000); +nodeTimers.setTimeout(refreshSpotsNoTx, 300000); \ No newline at end of file diff --git a/package.nw/lib/gtws.js b/package.nw/lib/gtws.js index 46c6d12..b758381 100644 --- a/package.nw/lib/gtws.js +++ b/package.nw/lib/gtws.js @@ -633,8 +633,8 @@ function gtChatMessage(jsmesg) { sendSimplePushMessage(cid, jsmesg); } - if (GT.msgSettings.msgPushover && GT.msgSettings.pushoverUsername != null && - GT.msgSettings.pushoverToken != null) + if (GT.msgSettings.msgPushover && GT.msgSettings.msgPushoverUsername != null && + GT.msgSettings.msgPushoverToken != null) { sendPushOverMessage(cid, jsmesg); } @@ -868,4 +868,4 @@ function alertChatMessage() playAlertMediaFile(GT.msgSettings.msgAlertMedia); } GT.lastChatMsgAlert = timeNowSec(); -} +} \ No newline at end of file From 8b67e8cb3641d2115c1bd18d74db31fb87e8ee28 Mon Sep 17 00:00:00 2001 From: Christian Bayer Date: Mon, 28 Aug 2023 16:52:43 -0400 Subject: [PATCH 3/6] fixed settings storage --- package.nw/GridTracker.html | 10 ++++------ package.nw/lib/defaults.js | 4 ++-- package.nw/lib/gt.js | 2 +- package.nw/lib/gtws.js | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/package.nw/GridTracker.html b/package.nw/GridTracker.html index 62b6ac5..77b1bb1 100644 --- a/package.nw/GridTracker.html +++ b/package.nw/GridTracker.html @@ -2983,9 +2983,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @@ -3006,9 +3005,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/package.nw/lib/defaults.js b/package.nw/lib/defaults.js index fe08fa6..214d8cd 100644 --- a/package.nw/lib/defaults.js +++ b/package.nw/lib/defaults.js @@ -194,9 +194,9 @@ var def_msgSettings = { msgActionSelect: 1, msgAwaySelect: 0, msgAwayText: "I am away from the shack at the moment", - msgSimplepush: false, + msgSimplepush: 0, msgSimplePushApiKey: "", - msgPushover: false, + msgPushover: 0, msgPushoverUsername: "", msgPushoverToken: "" }; diff --git a/package.nw/lib/gt.js b/package.nw/lib/gt.js index 19b6b5e..bece478 100644 --- a/package.nw/lib/gt.js +++ b/package.nw/lib/gt.js @@ -16204,4 +16204,4 @@ function refreshSpotsNoTx() } nodeTimers.setInterval(refreshSpotsNoTx, 300000); -nodeTimers.setTimeout(refreshSpotsNoTx, 300000); \ No newline at end of file +nodeTimers.setTimeout(refreshSpotsNoTx, 300000); diff --git a/package.nw/lib/gtws.js b/package.nw/lib/gtws.js index b758381..bb0dfd2 100644 --- a/package.nw/lib/gtws.js +++ b/package.nw/lib/gtws.js @@ -868,4 +868,4 @@ function alertChatMessage() playAlertMediaFile(GT.msgSettings.msgAlertMedia); } GT.lastChatMsgAlert = timeNowSec(); -} \ No newline at end of file +} From 086d2c56ba3eae4e1d52702c4528517871b952d0 Mon Sep 17 00:00:00 2001 From: Christian Bayer Date: Tue, 29 Aug 2023 23:12:33 -0400 Subject: [PATCH 4/6] fixed storing attributes --- package.nw/lib/gt.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/package.nw/lib/gt.js b/package.nw/lib/gt.js index bece478..f46097e 100644 --- a/package.nw/lib/gt.js +++ b/package.nw/lib/gt.js @@ -10679,12 +10679,14 @@ function setOamsBandActivityNeighbors(checkbox) function setOamsSimplepush(checkbox) { - GT.appSettings.msgSimplepush = checkbox.checked; + GT.msgSettings.msgSimplepush = checkbox.checked; + localStorage.msgSettings = JSON.stringify(GT.msgSettings); } function setOamsPushover(checkbox) { - GT.appSettings.msgPushover = checkbox.checked; + GT.msgSettings.msgPushover = checkbox.checked; + localStorage.msgSettings = JSON.stringify(GT.msgSettings); } function setMsgEnable(checkbox) @@ -13024,8 +13026,6 @@ function loadViewSettings() function loadMsgSettings() { msgEnable.checked = GT.appSettings.gtMsgEnable; - msgSimplepush.checked = GT.appSettings.msgSimplepush; - msgPushover.checked = GT.appSettings.msgPushover; GTspotEnable.checked = GT.appSettings.gtSpotEnable; oamsBandActivity.checked = GT.appSettings.oamsBandActivity; @@ -13038,6 +13038,9 @@ function loadMsgSettings() { document.getElementById(key).value = GT.msgSettings[key]; } + + msgSimplepush.checked = GT.msgSettings.msgSimplepush; + msgPushover.checked = GT.msgSettings.msgPushover; ValidateText(msgAwayText); setMsgSettingsView(); } From 361e5653c2280fedb382d1abac514cf12942e42f Mon Sep 17 00:00:00 2001 From: Christian Bayer Date: Tue, 29 Aug 2023 23:20:28 -0400 Subject: [PATCH 5/6] added translations --- package.nw/i18n/cn-t.json | 6 ++++++ package.nw/i18n/cn.json | 6 ++++++ package.nw/i18n/en.json | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/package.nw/i18n/cn-t.json b/package.nw/i18n/cn-t.json index dcbbaa1..37b3618 100644 --- a/package.nw/i18n/cn-t.json +++ b/package.nw/i18n/cn-t.json @@ -166,6 +166,12 @@ "settings.Alerts.label": "警報", "settings.CallRoster.label": "呼叫清單", "settings.OAMS.label": "OAMS", + "settings.OAMS.simplepush.enable.label": "Simplepush Message Forwarding on/off", + "settings.OAMS.simplepush.apikey.label": "Simplepush API Key", + "settings.OAMS.pushover.enable.label": "Pushover Message Forwarding on/off", + "settings.OAMS.pushover.credentials.label": "Pushover Credentials", + "settings.OAMS.pushover.username.label": "Username", + "settings.OAMS.pushover.token.label": "Token", "settings.Logbook.label": "日志", "settings.Update.label": "更新", "settings.About.label": "關於", diff --git a/package.nw/i18n/cn.json b/package.nw/i18n/cn.json index e7973fe..e164951 100644 --- a/package.nw/i18n/cn.json +++ b/package.nw/i18n/cn.json @@ -166,6 +166,12 @@ "settings.Alerts.label": "警报", "settings.CallRoster.label": "呼叫列表", "settings.OAMS.label": "OAMS", + "settings.OAMS.simplepush.enable.label": "Simplepush Message Forwarding on/off", + "settings.OAMS.simplepush.apikey.label": "Simplepush API Key", + "settings.OAMS.pushover.enable.label": "Pushover Message Forwarding on/off", + "settings.OAMS.pushover.credentials.label": "Pushover Credentials", + "settings.OAMS.pushover.username.label": "Username", + "settings.OAMS.pushover.token.label": "Token", "settings.Logbook.label": "日志", "settings.Update.label": "更新", "settings.About.label": "关于", diff --git a/package.nw/i18n/en.json b/package.nw/i18n/en.json index a780e7e..3bba1f9 100644 --- a/package.nw/i18n/en.json +++ b/package.nw/i18n/en.json @@ -165,6 +165,12 @@ "settings.Alerts.label": "Alerts", "settings.CallRoster.label": "Call Roster", "settings.OAMS.label": "OAMS", + "settings.OAMS.simplepush.enable.label": "Simplepush Message Forwarding on/off", + "settings.OAMS.simplepush.apikey.label": "Simplepush API Key", + "settings.OAMS.pushover.enable.label": "Pushover Message Forwarding on/off", + "settings.OAMS.pushover.credentials.label": "Pushover Credentials", + "settings.OAMS.pushover.username.label": "Username", + "settings.OAMS.pushover.token.label": "Token", "settings.Logbook.label": "Logbook", "settings.Update.label": "Update", "settings.About.label": "About", From 0500aecfb16d3adac2574c1e33d6053930b645df Mon Sep 17 00:00:00 2001 From: Christian Bayer Date: Wed, 30 Aug 2023 23:06:10 -0400 Subject: [PATCH 6/6] call roster notifications using push notifications --- package.nw/lib/gt.js | 1 + package.nw/lib/gtws.js | 8 +-- package.nw/lib/roster/sendAlerts.js | 91 ++++++++++++++++++++++++++++- 3 files changed, 94 insertions(+), 6 deletions(-) diff --git a/package.nw/lib/gt.js b/package.nw/lib/gt.js index f46097e..3973acb 100644 --- a/package.nw/lib/gt.js +++ b/package.nw/lib/gt.js @@ -469,6 +469,7 @@ GT.unconfirmedCalls = new Map(); GT.tracker = {}; GT.lastTrasmissionTimeSec = timeNowSec(); +GT.getPostBuffer = getPostBuffer; const PSKREPORTER_INTERVAL_IN_SECONDS = 5 * 60; diff --git a/package.nw/lib/gtws.js b/package.nw/lib/gtws.js index bb0dfd2..4cb5224 100644 --- a/package.nw/lib/gtws.js +++ b/package.nw/lib/gtws.js @@ -567,7 +567,7 @@ function htmlEntities(str) .replace(/"/g, """); } -function sendSimplePushMessage(cid, jsmesg) +function sendSimplePushMessage(jsmesg) { const url = "https://api.simplepush.io/send"; let data = { key: GT.msgSettings.msgSimplePushApiKey, title: "GridTracker Chat Message", msg: jsmesg.call + ": " + jsmesg.msg }; @@ -584,7 +584,7 @@ function sendSimplePushMessage(cid, jsmesg) ); } -function sendPushOverMessage(cid, jsmesg) +function sendPushOverMessage(jsmesg) { const url = "https://api.pushover.net/1/messages.json"; let data = { @@ -631,12 +631,12 @@ function gtChatMessage(jsmesg) if (GT.msgSettings.msgSimplepush && GT.msgSettings.msgSimplePushApiKey != null) { - sendSimplePushMessage(cid, jsmesg); + sendSimplePushMessage(jsmesg); } if (GT.msgSettings.msgPushover && GT.msgSettings.msgPushoverUsername != null && GT.msgSettings.msgPushoverToken != null) { - sendPushOverMessage(cid, jsmesg); + sendPushOverMessage(jsmesg); } if (newChatMessage(cid, jsmesg) == false) alertChatMessage(); diff --git a/package.nw/lib/roster/sendAlerts.js b/package.nw/lib/roster/sendAlerts.js index 0d77830..b3e53ca 100644 --- a/package.nw/lib/roster/sendAlerts.js +++ b/package.nw/lib/roster/sendAlerts.js @@ -110,8 +110,95 @@ function sendAlerts(callRoster, rosterSettings) { conosle.log(e); } - CR.scriptReport = Object(); } - else CR.scriptReport = Object(); + if (window.opener.GT.msgSettings.msgPushover) + { + sendPushOverAlert(parseCRJson(CR.scriptReport)); + } + if (window.opener.GT.msgSettings.msgSimplepush) + { + sendSimplePushMessage(parseCRJson(CR.scriptReport)); + } + CR.scriptReport = Object(); } } + +function sendSimplePushMessage(message) +{ + const url = "https://api.simplepush.io/send"; + let data = { + key: window.opener.GT.msgSettings.msgSimplePushApiKey, + title: "GridTracker Alert " + window.opener.GT.appSettings.myCall, + msg: message + }; + window.opener.GT.getPostBuffer( + url, + null, // callback, + null, + "https", + 443, + data, + 500, // timeoutMs, + null, // timeoutCallback, + "simplepush" + ); +} +function sendPushOverAlert(message) +{ + const url = "https://api.pushover.net/1/messages.json"; + let data = { + user: window.opener.GT.msgSettings.msgPushoverUsername, + token: window.opener.GT.msgSettings.msgPushoverToken, + title: + "GridTracker Alert " + window.opener.GT.appSettings.myCall, + message: message + }; + window.opener.GT.getPostBuffer( + url, + null, // callback, + null, + "https", + 443, + data, + 500, // timeoutMs, + null, // timeoutCallback, + "pushover" + ); +} + +function parseCRJson(data) +{ + let message = ""; + for (let callsign in data) + { + if (data[callsign].shouldAlert === true && data[callsign].alerted === false) + { + if (data[callsign].grid) + { + if (data[callsign].state) + { + message = message + callsign + ", " + data[callsign].dxccName + ", " + data[callsign].RSTsent.toString() + ", " + data[callsign].grid + ", " + data[callsign].band + ", " + data[callsign].state + "\n"; + } + else + { + message = message + callsign + ", " + data[callsign].dxccName + ", " + data[callsign].RSTsent.toString() + ", " + data[callsign].grid + ", " + data[callsign].band + "\n"; + } + } + else + { + if (!data[callsign].grid) + { + if (data[callsign].state) + { + message = message + callsign + ", " + data[callsign].dxccName + ", " + data[callsign].RSTsent.toString() + ", " + data[callsign].band + ", " + data[callsign].state + "\n"; + } + else + { + message = message + callsign + ", " + data[callsign].dxccName + ", " + data[callsign].RSTsent.toString() + ", " + data[callsign].band + "\n"; + } + } + } + } + } + return message; +}
- + +
- + +
- - +
- - +