From 073067385143bfbb31091cc8fdf1659fb27191c8 Mon Sep 17 00:00:00 2001 From: ajs124 Date: Sat, 24 May 2014 02:57:30 +0200 Subject: [PATCH 1/2] remove webkit prefix from Notifications, now working with firefox! + probably fix bug with undefined artist or album --- htdocs/js/mpd.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js index 9e7d6c7..a0a0cd0 100644 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@ -493,15 +493,19 @@ $('#btnrepeat').on('click', function (e) { }); $('#btnnotify').on('click', function (e) { - if($.cookie("notification") === "true") + if($.cookie("notification") === "true") { $.cookie("notification", false); - else { - window.webkitNotifications.requestPermission(); - if (window.webkitNotifications.checkPermission() == 0) - { - $.cookie("notification", true); - $('btnnotify').addClass("active"); - } + } else { + Notification.requestPermission(function (permission) { + if(!('permission' in Notification)) { + Notification.permission = permission; + } + + if (permission === "granted") { + $.cookie("notification", true); + $('btnnotify').addClass("active"); + } + }); } }); @@ -577,7 +581,7 @@ $('#mpd_password_set > button').on('click', function (e) { }) function notificationsSupported() { - return "webkitNotifications" in window; + return "Notification" in window; } function songNotify(title, artist, album) { @@ -595,14 +599,13 @@ function songNotify(title, artist, album) { //chrome.notifications.create(id, options, creationCallback); var textNotification = ""; - if(artist.length > 0) + if(typeof artist != 'undefined' && artist.length > 0) textNotification += " " + artist; - if(album.length > 0) + if(typeof album != 'undefined' && album.length > 0) textNotification += "\n " + album; - var notification = window.webkitNotifications.createNotification("assets/favicon.ico", textNotification, title); - notification.show(); - setTimeout(function(notification) { - notification.cancel(); - }, 3000, notification); + var notification = new Notification(title, {icon: 'assets/favicon.ico', body: textNotification}); + setTimeout(function(notification) { + notification.close(); + }, 3000, notification); } From 9f001aa26457d22a1a6de162cd1ea3377d1636bb Mon Sep 17 00:00:00 2001 From: ajs124 Date: Sat, 24 May 2014 03:12:51 +0200 Subject: [PATCH 2/2] change notification cookie from session to "permanent" --- htdocs/js/mpd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js index a0a0cd0..b6db9af 100644 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@ -502,7 +502,7 @@ $('#btnnotify').on('click', function (e) { } if (permission === "granted") { - $.cookie("notification", true); + $.cookie("notification", true, { expires: 424242 }); $('btnnotify').addClass("active"); } });