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 4a268c4..667583a 100644 --- a/index.html +++ b/index.html @@ -287,7 +287,6 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
-

Connection to WeeChat lost

diff --git a/js/glowingbear.js b/js/glowingbear.js index 2d4a927..f3fabb4 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -245,6 +245,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $rootScope.$emit('notificationChanged'); $scope.connectbutton = 'Connect'; $scope.connectbuttonicon = 'glyphicon-chevron-right'; + + // 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 3a67975..27c2f04 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -33,6 +33,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) { @@ -45,7 +60,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu tag: 'gb-highlight-vib' }); }); - } else { + } else if (typeof Notification !== 'undefined') { var notification = new Notification(title, { body: body, icon: 'assets/img/favicon.png' @@ -74,6 +89,23 @@ 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 + }); + } }; @@ -138,13 +170,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() {