-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
262 additions
and
439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Configuration Data | ||
var vibratePattern = [100, 50, 100, 50, 100] | ||
var notificationTag = 'pomodori-notification' | ||
var notificationIcon = '/static/icons/icon-192x192.png' | ||
var renotifyOption = 'true' | ||
|
||
var _supported = function () { return ('Notification' in window && window.Notification !== undefined) } | ||
var _isBlocked = function () { return ('Notification' in window && window.Notification.permission === 'denied') } | ||
var _isEnabled = function () { return ('Notification' in window && window.Notification.permission === 'granted') } | ||
|
||
exports.supported = function () { return _supported() } | ||
exports.isBlocked = function () { return _isBlocked() } | ||
exports.isEnabled = function () { return _isEnabled() } | ||
|
||
exports.requestPermission = function () { | ||
if (_supported() && window.Notification.permission === 'default') { | ||
window.Notification.requestPermission() | ||
} | ||
} | ||
|
||
exports.sendNotification = function (msgTitle, msgBody) { | ||
if (_supported() && window.Notification.permission === 'granted') { | ||
// send notification via service workers (for browsers w/ service worker installed) | ||
if (navigator.serviceWorker.controller !== null) { | ||
navigator.serviceWorker.ready.then(function (registration) { | ||
registration.showNotification(msgTitle, { | ||
body: msgBody, | ||
icon: notificationIcon, | ||
vibrate: vibratePattern, | ||
tag: notificationTag, | ||
renotify: renotifyOption | ||
}) | ||
}) | ||
} else { | ||
new window.Notification(msgTitle, { // eslint-disable-line no-new | ||
'body': msgBody, | ||
'icon': notificationIcon, | ||
'vibrate': vibratePattern, | ||
'tag': notificationTag, | ||
'renotify': renotifyOption | ||
}) | ||
} | ||
return true | ||
} | ||
return false | ||
} |
Oops, something went wrong.