From 6de8bdc41a51ddce6e787563b805ba2ce0121e2b Mon Sep 17 00:00:00 2001 From: Alice Jenkinson Date: Fri, 17 Mar 2017 21:45:44 +1300 Subject: [PATCH] Initial rework of Cordova branch --- bower.json | 13 +++++++++++-- js/app.js | 5 +++++ js/glowingbear.js | 18 +++++++++++++++--- js/notifications.js | 39 +++++++++++++++++++++++++++++++++++++-- manifest.webapp | 10 +++++----- 5 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 js/app.js diff --git a/bower.json b/bower.json index 06d8ae5..b0979c1 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,16 @@ "angular-mocks": "1.5.x", "html5-boilerplate": "~4.3.0", "underscore": "~1.8", - "bootstrap": "~3.1", + "bootstrap": "~3.3", "emojione": "~2.2" - } + }, + "keywords": [ + "weechat", + "irc" + ], + "ignore": [ + "**/.*", + "node_modules", + "bower_components" + ] } diff --git a/js/app.js b/js/app.js new file mode 100644 index 0000000..8455e56 --- /dev/null +++ b/js/app.js @@ -0,0 +1,5 @@ +document.addEventListener("deviceready", function () { + if (navigator.splashscreen !== undefined) { + navigator.splashscreen.hide(); + } +}, false); \ No newline at end of file diff --git a/js/glowingbear.js b/js/glowingbear.js index 3bbce1e..caaed46 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -234,7 +234,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.notifications = notifications.unreadCount('notification'); $scope.unread = notifications.unreadCount('unread'); - if (settings.useFavico && $rootScope.favico) { + if (cordova === undefined && settings.useFavico && $rootScope.favico) { notifications.updateFavico(); } }); @@ -250,6 +250,10 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.connectbutton = 'Connect'; $scope.connectbuttonicon = 'glyphicon-chevron-right'; bufferResume.reset(); + + 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'; @@ -369,6 +373,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', if (!$rootScope.connected) { return; } + + if (cordova !== undefined) { + return; + } + if (useFavico) { notifications.updateFavico(); } else { @@ -382,7 +391,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // This also fires when the page is loaded if enabled. // Note that this says MathJax but we switched to KaTeX settings.addCallback('enableMathjax', function(enabled) { - if (enabled && !$rootScope.mathjax_init) { + if (cordova === undefined && enabled && !$rootScope.mathjax_init) { // Load MathJax only once $rootScope.mathjax_init = true; @@ -803,7 +812,10 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', if ($rootScope.connected) { $scope.disconnect(); } - $scope.favico.reset(); + + if (cordova !== undefined) { + $scope.favico.reset(); + } } }; diff --git a/js/notifications.js b/js/notifications.js index 2f9752f..487aed8 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,7 +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, @@ -97,6 +112,22 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu 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 + }); } }; @@ -135,6 +166,10 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu }; var updateFavico = function() { + if (cordova !== undefined) { + return; + } + var notifications = unreadCount('notification'); if (notifications > 0) { $rootScope.favico.badge(notifications, { @@ -200,7 +235,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu showNotification(buffer, title, body); - if (settings.soundnotification) { + if (cordova === undefined && settings.soundnotification) { // TODO fill in a sound file var audioFile = "assets/audio/sonar"; var soundHTML = ''; diff --git a/manifest.webapp b/manifest.webapp index d324eda..3bb8b1c 100644 --- a/manifest.webapp +++ b/manifest.webapp @@ -1,12 +1,12 @@ { "name": "Glowing Bear", "description": "WeeChat Web frontend", - "launch_path": "/glowing-bear/index.html", + "launch_path": "/index.html", "icons": { - "128": "/glowing-bear/assets/img/glowing_bear_128x128.png", - "60": "/glowing-bear/assets/img/glowing_bear_60x60.png", - "90": "/glowing-bear/assets/img/glowing_bear_90x90.png", - "32": "/glowing-bear/assets/img/favicon.png" + "128": "/assets/img/glowing_bear_128x128.png", + "60": "/assets/img/glowing_bear_60x60.png", + "90": "/assets/img/glowing_bear_90x90.png", + "32": "/assets/img/favicon.png" }, "installs_allowed_from": [ "*"