Initial rework of Cordova branch

This commit is contained in:
Alice Jenkinson 2017-03-17 21:45:44 +13:00 committed by Lorenz Hübschle-Schneider
parent e7fdf05890
commit 6de8bdc41a
5 changed files with 73 additions and 12 deletions

View file

@ -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"
]
}

5
js/app.js Normal file
View file

@ -0,0 +1,5 @@
document.addEventListener("deviceready", function () {
if (navigator.splashscreen !== undefined) {
navigator.splashscreen.hide();
}
}, false);

View file

@ -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,8 +812,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
if ($rootScope.connected) {
$scope.disconnect();
}
if (cordova !== undefined) {
$scope.favico.reset();
}
}
};
$scope.init = function() {

View file

@ -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 = '<audio autoplay="autoplay"><source src="' + audioFile + '.ogg" type="audio/ogg" /><source src="' + audioFile + '.mp3" type="audio/mpeg" /></audio>';

View file

@ -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": [
"*"