feat: Added Desktop Notifications While Minimized. This Will Send Notifications to the Desktop if a Host Status Changes While It’s Minimized to the System Tray. Closes #12.
This commit is contained in:
+39
-2
@@ -976,7 +976,6 @@ const monitorTab = (() => {
|
||||
let running = false;
|
||||
let entries = {};
|
||||
var editingLabel = false;
|
||||
|
||||
var els = {
|
||||
input: () => document.getElementById('monitor-input'),
|
||||
interval: () => document.getElementById('monitor-interval'),
|
||||
@@ -987,6 +986,26 @@ const monitorTab = (() => {
|
||||
body: () => document.getElementById('monitor-body'),
|
||||
};
|
||||
|
||||
var reminderInterval = null;
|
||||
|
||||
async function notify(title, body) {
|
||||
try {
|
||||
var current = window.__TAURI__.window.getCurrentWindow();
|
||||
var visible = await current.isVisible();
|
||||
if (visible) return;
|
||||
|
||||
var notif = window.__TAURI__.notification;
|
||||
var granted = await notif.isPermissionGranted();
|
||||
if (!granted) {
|
||||
var perm = await notif.requestPermission();
|
||||
if (perm !== 'granted') return;
|
||||
}
|
||||
notif.sendNotification({ title: title, body: body });
|
||||
} catch (e) {
|
||||
console.log('Notification error:', e);
|
||||
}
|
||||
}
|
||||
|
||||
function setRunning(active) {
|
||||
running = active;
|
||||
els.btnStart().disabled = active;
|
||||
@@ -1083,6 +1102,14 @@ const monitorTab = (() => {
|
||||
|
||||
try {
|
||||
await invoke('monitor_start', { intervalMs: interval });
|
||||
|
||||
// Start 15-minute reminder
|
||||
if (reminderInterval) clearInterval(reminderInterval);
|
||||
reminderInterval = setInterval(function () {
|
||||
var count = Object.keys(entries).length;
|
||||
notify('Argus Monitor Active',
|
||||
'The monitor is still running with ' + count + ' hosts. Close the monitor to stop pinging.');
|
||||
}, 15 * 60 * 1000);
|
||||
} catch (err) {
|
||||
console.error('Monitor start error:', err);
|
||||
setRunning(false);
|
||||
@@ -1095,6 +1122,10 @@ const monitorTab = (() => {
|
||||
} catch (err) {
|
||||
console.error('Monitor stop error:', err);
|
||||
}
|
||||
if (reminderInterval) {
|
||||
clearInterval(reminderInterval);
|
||||
reminderInterval = null;
|
||||
}
|
||||
setRunning(false);
|
||||
}
|
||||
|
||||
@@ -1138,7 +1169,13 @@ const monitorTab = (() => {
|
||||
|
||||
await listen('monitor:state-change', function (e) {
|
||||
var data = e.payload;
|
||||
console.log('State change:', data.ip, data.old, '->', data.new);
|
||||
console.log('State change:', data.ip, data.old, '->', data['new']);
|
||||
var label = entries[data.ip] ? (entries[data.ip].label || data.ip) : data.ip;
|
||||
if (data['new'] === 'Down') {
|
||||
notify('Host Down', label + ' (' + data.ip + ') is no longer responding');
|
||||
} else if (data['new'] === 'Up' && data.old === 'Down') {
|
||||
notify('Host Recovered', label + ' (' + data.ip + ') is back online');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user