Skip to content

Commit 38dbf0c

Browse files
committed
Notification is now only triggered once. Use a specific appID instead of SnoreToast's default.
1 parent 3649059 commit 38dbf0c

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175

176176
END OF TERMS AND CONDITIONS
177177

178-
Copyright 2020-2021 blu3mania.
178+
Copyright 2020 blu3mania.
179179

180180
Licensed under the Apache License, Version 2.0 (the "License");
181181
you may not use this file except in compliance with the License.

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ prefer you can use npm as well, just replace "yarn" with "npm" in any command.
3636
* Desktop notifications are shown to the user on desktop. For example, on Windows 10 it uses Windows
3737
Toast notification.
3838

39-
**Note 1**, this only works when running in standalone mode instead of as a system service.
40-
41-
**Note 2**, since the notifier uses Snoretoast for Windows Toast notification, a new app "Snoretoast"
42-
will be registered on Start menu if using this feature on Windows, and all notifications will appear to
43-
be from that app.
39+
**Note**, this only works when running in standalone mode instead of as a system service.
4440
* email defines options for email notifications.
4541
* format is the email format. It can be either "html" or "text". "html" is the default value.
4642
* subject is the email subject. You can use these macros in the defined value:

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"uninstall": "node src/uninstall-service.js"
1111
},
1212
"keywords": [
13-
"disk space",
14-
"disk monitor"
13+
"disk-space",
14+
"disk-monitor",
15+
"disk-space-monitor"
1516
],
1617
"author": "blu3mania <[email protected]>",
1718
"license": "Apache-2.0",

src/app.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
if (!calculateThresholdInBytes(disk, diskInfo)) {
5959
return Promise.reject(`Invalid configuration "${disk.threshold}" for disk "${disk.path}".`);
6060
}
61+
disk.notificationTriggered = false;
6162
verbose(`Disk "${disk.path}" threshold "${disk.threshold}", which is ${disk.thresholdInBytes} bytes.`);
6263
}
6364
checkDiskFreeSpace(disk, diskInfo);
@@ -143,14 +144,19 @@
143144

144145
function checkDiskFreeSpace(disk, diskInfo) {
145146
if (diskInfo.free < disk.thresholdInBytes) {
146-
if (settings.notificationTypes.find(type => type.toLowerCase() === NotificationType.Email)) {
147-
warning(replaceMacro('Free space on disk {DISK} has dropped under {THRESHOLD}! Sending email notification...', disk, diskInfo));
148-
sendEmailNotification(disk, diskInfo);
149-
}
150-
if (settings.notificationTypes.find(type => type.toLowerCase() === NotificationType.Desktop)) {
151-
warning(replaceMacro('Free space on disk {DISK} has dropped under {THRESHOLD}! Showing desktop notification...', disk, diskInfo));
152-
sendDesktopNotification(disk, diskInfo);
147+
if (!disk.notificationTriggered) {
148+
disk.notificationTriggered = true;
149+
if (settings.notificationTypes.find(type => type.toLowerCase() === NotificationType.Email)) {
150+
warning(replaceMacro('Free space on disk {DISK} has dropped under {THRESHOLD}! Sending email notification...', disk, diskInfo));
151+
sendEmailNotification(disk, diskInfo);
152+
}
153+
if (settings.notificationTypes.find(type => type.toLowerCase() === NotificationType.Desktop)) {
154+
warning(replaceMacro('Free space on disk {DISK} has dropped under {THRESHOLD}! Showing desktop notification...', disk, diskInfo));
155+
sendDesktopNotification(disk, diskInfo);
156+
}
153157
}
158+
} else {
159+
disk.notificationTriggered = false;
154160
}
155161
}
156162

@@ -193,6 +199,7 @@
193199
notifier.notify({
194200
title: 'Low disk space warning',
195201
message: replaceMacro('Free space on disk {DISK} has dropped under {THRESHOLD}!', disk, diskInfo),
202+
appID: 'Disk Space Monitor',
196203
icon: getImagePath('low-disk-space.png'),
197204
});
198205
}

0 commit comments

Comments
 (0)