Fix notification permission request for Safari

This commit is contained in:
Charles Gould 2018-02-28 23:31:27 -05:00
parent d66bc9c900
commit c526f1bf3b

View File

@ -335,9 +335,21 @@ function main() {
function start() { function start() {
// Request permission to show notifications // Request permission to show notifications
Notification.requestPermission().then(function(result) { try {
console.log('Notification permission: ' + result); Notification.requestPermission().then(function(result) {
}); console.log('Notification permission: ' + result);
});
} catch (error) {
// Safari doesn't return a promise for requestPermissions and it throws a TypeError.
// It takes a callback as the first argument instead.
if (error instanceof TypeError) {
Notification.requestPermission(() => {
console.log('Notification permission: ' + Notification.permission);
});
} else {
throw error;
}
}
// Load initial data // Load initial data
doHttpGet('/games', function(games) { doHttpGet('/games', function(games) {