From 64575289900c593aea965d218f9d06907d25d415 Mon Sep 17 00:00:00 2001 From: An Phan Date: Sun, 20 Dec 2015 10:07:39 +0800 Subject: [PATCH] Fix notification bug #67 --- resources/assets/js/services/playback.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/resources/assets/js/services/playback.js b/resources/assets/js/services/playback.js index 842705b0..95f8040f 100644 --- a/resources/assets/js/services/playback.js +++ b/resources/assets/js/services/playback.js @@ -94,14 +94,20 @@ export default { return; } - var notification = new Notification(`♫ ${song.title}`, { - icon: song.album.cover, - body: `${song.album.name} – ${song.album.artist.name}` - }); + try { + var notification = new Notification(`♫ ${song.title}`, { + icon: song.album.cover, + body: `${song.album.name} – ${song.album.artist.name}` + }); - window.setTimeout(() => { - notification.close(); - }, 5000); + notification.onclick = () => window.focus(); + + // Close the notif after 5 secs. + window.setTimeout(() => notification.close(), 5000); + } catch (e) { + // Notification fails. + // @link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification + } }, /**