diff --git a/index.html b/index.html index 9935bd4..ff3cc60 100755 --- a/index.html +++ b/index.html @@ -24,6 +24,7 @@ + diff --git a/js/app.js b/js/app.js index c945164..1152457 100755 --- a/js/app.js +++ b/js/app.js @@ -210,42 +210,47 @@ JamStash.service('notifications', function ($rootScope, globals) { } } this.requestPermissionIfRequired = function () { - if (!this.hasNotificationPermission() && (window.webkitNotifications)) { - window.webkitNotifications.requestPermission(); + if (window.Notify.isSupported() && window.Notify.needsPermission()) { + window.Notify.requestPermission(); } } this.hasNotificationPermission = function () { - return !!(window.webkitNotifications) && (window.webkitNotifications.checkPermission() == 0); + return (window.Notify.needsPermission() === false); + } + this.hasNotificationSupport = function () { + return window.Notify.isSupported(); } var notifications = new Array(); + this.showNotification = function (pic, title, text, type, bind) { if (this.hasNotificationPermission()) { //closeAllNotifications() - var popup; - if (type == 'text') { - popup = window.webkitNotifications.createNotification(pic, title, text); - } else if (type == 'html') { - popup = window.webkitNotifications.createHTMLNotification(text); - } + var settings = {} if (bind = '#NextTrack') { - popup.addEventListener('click', function (bind) { - //$(bind).click(); + settings.notifyClick = function() { $rootScope.nextTrack(); - this.cancel(); - }) + this.close(); + }; } - notifications.push(popup); + if (type == 'text') { + settings.body = text; + settings.icon = pic; + } else if (type == 'html') { + settings.body = text; + } + var notification = new Notify(title, settings); + notifications.push(notification); setTimeout(function (notWin) { - notWin.cancel(); - }, globals.settings.NotificationTimeout, popup); - popup.show(); + notWin.close(); + }, globals.settings.NotificationTimeout, notification); + notification.show(); } else { console.log("showNotification: No Permission"); } } this.closeAllNotifications = function () { for (notification in notifications) { - notifications[notification].cancel(); + notifications[notification].close(); } } }); diff --git a/js/controllers/settings.js b/js/controllers/settings.js index 2f7f184..7afbb28 100644 --- a/js/controllers/settings.js +++ b/js/controllers/settings.js @@ -29,13 +29,13 @@ function SettingsCtrl($scope, $routeParams, $location, utils, globals, json, not if ($scope.settings.Password != '' && globals.settings.Password.substring(0, 4) != 'enc:') { $scope.settings.Password = 'enc:' + utils.HexEncode($scope.settings.Password); } if (globals.settings.NotificationSong) { notifications.requestPermissionIfRequired(); - if (!notifications.hasNotificationPermission()) { + if (!notifications.hasNotificationSupport()) { alert('HTML5 Notifications are not available for your current browser, Sorry :('); } } if (globals.settings.NotificationNowPlaying) { notifications.requestPermissionIfRequired(); - if (!notifications.hasNotificationPermission()) { + if (!notifications.hasNotificationSupport()) { alert('HTML5 Notifications are not available for your current browser, Sorry :('); } } diff --git a/js/plugins/notifyjs b/js/plugins/notifyjs new file mode 160000 index 0000000..5ee07d7 --- /dev/null +++ b/js/plugins/notifyjs @@ -0,0 +1 @@ +Subproject commit 5ee07d7122386d3ab2606e9094a6716ba4deaa13