diff --git a/assets/audio/sonar.mp3 b/assets/audio/sonar.mp3 deleted file mode 100644 index 3cc376a..0000000 Binary files a/assets/audio/sonar.mp3 and /dev/null differ diff --git a/assets/audio/sonar.ogg b/assets/audio/sonar.ogg deleted file mode 100644 index 77aadec..0000000 Binary files a/assets/audio/sonar.ogg and /dev/null differ diff --git a/index.html b/index.html index 630491c..e56b593 100644 --- a/index.html +++ b/index.html @@ -303,7 +303,6 @@ chown -R username:username ~username -

Connection to WeeChat lost

diff --git a/js/glowingbear.js b/js/glowingbear.js index 015b6a9..aca8c72 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -242,6 +242,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.connectbutton = 'Connect'; $scope.connectbuttonicon = 'glyphicon-chevron-right'; bufferResume.reset(); + + // Clear all cordova notifications + if (window.plugin !== undefined && window.plugin.notification !== undefined && window.plugin.notification.local !== undefined) { + window.plugin.notification.local.cancelAll(); + } }); $scope.connectbutton = 'Connect'; $scope.connectbuttonicon = 'glyphicon-chevron-right'; diff --git a/js/notifications.js b/js/notifications.js index a0a3afa..b607778 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -34,6 +34,21 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu $log.info('Service Worker err:', err); }); } + + document.addEventListener('deviceready', function() { + // Add cordova local notification click handler + if (cordova !== null && cordova.plugins !== undefined && cordova.plugins.notification !== undefined && + cordova.plugins.notification.local !== undefined) { + cordova.plugins.notification.local.on("click", function (notification) { + // go to buffer + var data = JSON.parse(notification.data); + models.setActiveBuffer(data.buffer); + window.focus(); + // clear this notification + cordova.plugins.notification.local.clear(notification.id); + }); + } + }); }; var showNotification = function(buffer, title, body) { @@ -66,8 +81,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu toastNotifier.show(toast); - } else { - + } else if (typeof Notification !== 'undefined') { var notification = new Notification(title, { body: body, icon: 'assets/img/favicon.png' @@ -96,6 +110,22 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu notification.onclose = function() { delete notifications[this.id]; }; + } else if (cordova !== undefined && cordova.plugins !== undefined && cordova.plugins.notification !== undefined && cordova.plugins.notification.local !== undefined) { + // Cordova local notification + // Calculate notification id from buffer ID + // Needs to be unique number, but we'll only ever have one per buffer + var id = parseInt(buffer.id, 16); + + // Cancel previous notification for buffer (if there was one) + cordova.plugins.notification.local.clear(id); + + // Send new notification + cordova.plugins.notification.local.schedule({ + id: id, + text: body, + title: title, + data: { buffer: buffer.id } // remember buffer id for when the notification is clicked + }); } @@ -173,13 +203,6 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu title += buffer.shortName + " (" + buffer.server + ")"; showNotification(buffer, title, body); - - if (settings.soundnotification) { - // TODO fill in a sound file - var audioFile = "assets/audio/sonar"; - var soundHTML = ''; - document.getElementById("soundNotification").innerHTML = soundHTML; - } }; var cancelAll = function() {