Add button to enable desktop notifications

This commit is contained in:
Sam Chow 2018-05-03 11:46:02 -04:00
parent e80c56e441
commit 2d3583fb44
3 changed files with 96 additions and 0 deletions

View file

@ -184,5 +184,52 @@
$scope.showBilling = function() {
$scope.showBillingCounter++;
};
$scope.notificationsPermissionsEnabled = Notification
&& Notification.permission === 'granted'
&& localStorage.getItem('quay.enabledDesktopNotifications') === 'on';
$scope.desktopNotificationsPermissionIsDisabled = () => Notification.permission === 'denied';
$scope.toggleDesktopNotifications = () => {
if (!Notification) { // unsupported in IE & some older browsers, we'll just tell the user it's not available
bootbox.dialog({
"message": 'Desktop Notifications unsupported in this browser',
"title": 'Unsupported Option',
"buttons": {
"close": {
"label": "Close",
"className": "btn-primary"
}
}
});
return;
}
if (localStorage.getItem('quay.enabledDesktopNotifications') === 'on') {
localStorage.setItem('quay.enabledDesktopNotifications', 'off');
localStorage.removeItem('quay.notifications.mostRecentTimestamp');
$scope.notificationsPermissionsEnabled = false;
} else {
if (Notification.permission === 'default') {
Notification.requestPermission()
.then((newPermission) => {
if (newPermission === 'granted') {
localStorage.setItem('quay.enabledDesktopNotifications', 'on');
$scope.notificationsPermissionsEnabled = true;
} else {
$scope.notificationsPermissionsEnabled = false;
}
});
} else if (Notification.permission === 'granted') {
localStorage.setItem('quay.enabledDesktopNotifications', 'on');
localStorage.setItem('quay.notifications.mostRecentTimestamp', new Date().getTime().toString());
$scope.notificationsPermissionsEnabled = true;
}
}
};
}
})();