Merge pull request #919 from txanatan/tidyup-cordova

Move Cordova specific fixes into main branch
This commit is contained in:
Lorenz Hübschle-Schneider 2017-04-28 14:00:39 +02:00 committed by GitHub
commit eaffb17c5a
9 changed files with 115 additions and 30 deletions

View File

@ -14,7 +14,16 @@
"angular-mocks": "1.5.x", "angular-mocks": "1.5.x",
"html5-boilerplate": "~4.3.0", "html5-boilerplate": "~4.3.0",
"underscore": "~1.8", "underscore": "~1.8",
"bootstrap": "~3.1", "bootstrap": "~3.3",
"emojione": "~2.2" "emojione": "~2.2"
} },
"keywords": [
"weechat",
"irc"
],
"ignore": [
"**/.*",
"node_modules",
"bower_components"
]
} }

View File

@ -474,7 +474,7 @@ npm run build-electron-{windows, darwin, linux}</pre>
</div> </div>
</form> </form>
</li> </li>
<li> <li>
<form class="form-inline" role="form"> <form class="form-inline" role="form">
<div class="checkbox"> <div class="checkbox">
<label> <label>

View File

@ -135,6 +135,17 @@ weechat.filter('DOMfilter', ['$filter', '$sce', function($filter, $sce) {
}; };
}]); }]);
// This is used by the cordova app to change link targets to "window.open(<url>, '_system')"
// so that they're opened in a browser window and don't navigate away from Glowing Bear
weechat.filter('linksForCordova', ['$sce', function($sce) {
return function(text) {
// XXX TODO this needs to be improved
text = text.replace(/<a (rel="[a-z ]+"\s+)?(?:target="_[a-z]+"\s+)?href="([^"]+)"/gi,
"<a $1 onClick=\"window.open('$2', '_system')\"");
return $sce.trustAsHtml(text);
};
}]);
weechat.filter('getBufferQuickKeys', function () { weechat.filter('getBufferQuickKeys', function () {
return function (obj, $scope) { return function (obj, $scope) {
if (!$scope) { return obj; } if (!$scope) { return obj; }

View File

@ -1,6 +1,13 @@
(function() { (function() {
'use strict'; 'use strict';
// cordova splash screen
document.addEventListener("deviceready", function () {
if (navigator.splashscreen !== undefined) {
navigator.splashscreen.hide();
}
}, false);
var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'bufferResume', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch'], ['$compileProvider', function($compileProvider) { var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'bufferResume', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch'], ['$compileProvider', function($compileProvider) {
// hacky way to be able to find out if we're in debug mode // hacky way to be able to find out if we're in debug mode
weechat.compileProvider = $compileProvider; weechat.compileProvider = $compileProvider;
@ -37,12 +44,12 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
'onlyUnread': false, 'onlyUnread': false,
'hotlistsync': true, 'hotlistsync': true,
'orderbyserver': true, 'orderbyserver': true,
'useFavico': true, 'useFavico': !utils.isCordova(),
'soundnotification': true, 'soundnotification': true,
'fontsize': '14px', 'fontsize': '14px',
'fontfamily': (utils.isMobileUi() ? 'sans-serif' : 'Inconsolata, Consolas, Monaco, Ubuntu Mono, monospace'), 'fontfamily': (utils.isMobileUi() ? 'sans-serif' : 'Inconsolata, Consolas, Monaco, Ubuntu Mono, monospace'),
'readlineBindings': false, 'readlineBindings': false,
'enableJSEmoji': (utils.isMobileUi() ? false : true), 'enableJSEmoji': !utils.isMobileUi(),
'enableMathjax': false, 'enableMathjax': false,
'enableQuickKeys': true, 'enableQuickKeys': true,
'customCSS': '', 'customCSS': '',
@ -89,10 +96,10 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
})(); })();
// Show a TLS warning if GB was loaded over an unencrypted connection, // Show a TLS warning if GB was loaded over an unencrypted connection,
// except for local instances (testing or electron) // except for local instances (testing, cordova, or electron)
$scope.show_tls_warning = (window.location.protocol !== "https:") && $scope.show_tls_warning = (window.location.protocol !== "https:") &&
(["localhost", "127.0.0.1", "::1"].indexOf(window.location.hostname) === -1) && (["localhost", "127.0.0.1", "::1"].indexOf(window.location.hostname) === -1) &&
!window.is_electron && !window.cordova; !window.is_electron && !utils.isCordova();
if (window.is_electron) { if (window.is_electron) {
// Use packaged emojione sprite in the electron app // Use packaged emojione sprite in the electron app
@ -225,7 +232,9 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
} }
}); });
$rootScope.favico = new Favico({animation: 'none'}); if (!utils.isCordova()) {
$rootScope.favico = new Favico({animation: 'none'});
}
$scope.notifications = notifications.unreadCount('notification'); $scope.notifications = notifications.unreadCount('notification');
$scope.unread = notifications.unreadCount('unread'); $scope.unread = notifications.unreadCount('unread');
@ -234,7 +243,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.notifications = notifications.unreadCount('notification'); $scope.notifications = notifications.unreadCount('notification');
$scope.unread = notifications.unreadCount('unread'); $scope.unread = notifications.unreadCount('unread');
if (settings.useFavico && $rootScope.favico) { if (!utils.isCordova() && settings.useFavico && $rootScope.favico) {
notifications.updateFavico(); notifications.updateFavico();
} }
}); });
@ -243,7 +252,12 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// Reset title // Reset title
$rootScope.pageTitle = ''; $rootScope.pageTitle = '';
$rootScope.notificationStatus = ''; $rootScope.notificationStatus = '';
// cancel outstanding notifications (incl cordova)
notifications.cancelAll(); notifications.cancelAll();
if (window.plugin !== undefined && window.plugin.notification !== undefined && window.plugin.notification.local !== undefined) {
window.plugin.notification.local.cancelAll();
}
models.reinitialize(); models.reinitialize();
$rootScope.$emit('notificationChanged'); $rootScope.$emit('notificationChanged');
@ -369,6 +383,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
if (!$rootScope.connected) { if (!$rootScope.connected) {
return; return;
} }
if (utils.isCordova()) {
return; // cordova doesn't have a favicon
}
if (useFavico) { if (useFavico) {
notifications.updateFavico(); notifications.updateFavico();
} else { } else {
@ -382,7 +401,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// This also fires when the page is loaded if enabled. // This also fires when the page is loaded if enabled.
// Note that this says MathJax but we switched to KaTeX // Note that this says MathJax but we switched to KaTeX
settings.addCallback('enableMathjax', function(enabled) { settings.addCallback('enableMathjax', function(enabled) {
if (enabled && !$rootScope.mathjax_init) { // no latex math support for cordova right now
if (!utils.isCordova() && enabled && !$rootScope.mathjax_init) {
// Load MathJax only once // Load MathJax only once
$rootScope.mathjax_init = true; $rootScope.mathjax_init = true;
@ -803,7 +823,10 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
if ($rootScope.connected) { if ($rootScope.connected) {
$scope.disconnect(); $scope.disconnect();
} }
$scope.favico.reset();
if (!utils.isCordova()) {
$scope.favico.reset();
}
} }
}; };

View File

@ -1,6 +1,6 @@
var weechat = angular.module('weechat'); var weechat = angular.module('weechat');
weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', function($rootScope, $log, models, settings) { weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', 'utils', function($rootScope, $log, models, settings, utils) {
var serviceworker = false; var serviceworker = false;
var notifications = []; var notifications = [];
// Ask for permission to display desktop notifications // Ask for permission to display desktop notifications
@ -34,6 +34,21 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
$log.info('Service Worker err:', err); $log.info('Service Worker err:', err);
}); });
} }
document.addEventListener('deviceready', function() {
// Add cordova local notification click handler
if (utils.isCordova() && window.cordova.plugins !== undefined && window.cordova.plugins.notification !== undefined &&
window.cordova.plugins.notification.local !== undefined) {
window.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
window.cordova.plugins.notification.local.clear(notification.id);
});
}
});
}; };
var showNotification = function(buffer, title, body) { var showNotification = function(buffer, title, body) {
@ -66,7 +81,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
toastNotifier.show(toast); toastNotifier.show(toast);
} else { } else if (typeof Notification !== 'undefined') {
var notification = new Notification(title, { var notification = new Notification(title, {
body: body, body: body,
@ -97,6 +112,22 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
delete notifications[this.id]; delete notifications[this.id];
}; };
} else if (utils.isCordova() && window.cordova.plugins !== undefined && window.cordova.plugins.notification !== undefined && window.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)
window.cordova.plugins.notification.local.clear(id);
// Send new notification
window.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() { var updateFavico = function() {
if (utils.isCordova()) {
return; // cordova doesn't have a favicon
}
var notifications = unreadCount('notification'); var notifications = unreadCount('notification');
if (notifications > 0) { if (notifications > 0) {
$rootScope.favico.badge(notifications, { $rootScope.favico.badge(notifications, {
@ -200,8 +235,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
showNotification(buffer, title, body); showNotification(buffer, title, body);
if (settings.soundnotification) { if (!utils.isCordova() && settings.soundnotification) {
// TODO fill in a sound file
var audioFile = "assets/audio/sonar"; 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>'; var soundHTML = '<audio autoplay="autoplay"><source src="' + audioFile + '.ogg" type="audio/ogg" /><source src="' + audioFile + '.mp3" type="audio/mpeg" /></audio>';
document.getElementById("soundNotification").innerHTML = soundHTML; document.getElementById("soundNotification").innerHTML = soundHTML;

View File

@ -21,6 +21,10 @@ weechat.factory('utils', function() {
return (document.body.clientWidth < mobile_cutoff); return (document.body.clientWidth < mobile_cutoff);
}; };
var isCordova = function() {
return window.cordova !== undefined;
};
// Inject a javascript (used by KaTeX) // Inject a javascript (used by KaTeX)
var inject_script = function(script_url) { var inject_script = function(script_url) {
@ -46,6 +50,7 @@ weechat.factory('utils', function() {
changeClassStyle: changeClassStyle, changeClassStyle: changeClassStyle,
getClassStyle: getClassStyle, getClassStyle: getClassStyle,
isMobileUi: isMobileUi, isMobileUi: isMobileUi,
isCordova: isCordova,
inject_script: inject_script, inject_script: inject_script,
inject_css: inject_css, inject_css: inject_css,
}; };

View File

@ -9,11 +9,11 @@
}, },
"app": { "app": {
"urls": [ "urls": [
"http://glowing-bear.github.io/glowing-bear/" "https://www.glowing-bear.org/"
], ],
"launch": { "launch": {
"container": "panel", "container": "panel",
"web_url": "http://glowing-bear.github.io/glowing-bear/" "web_url": "https://www.glowing-bear.org/"
} }
}, },
"permissions": [ "permissions": [

View File

@ -1,12 +1,12 @@
{ {
"name": "Glowing Bear", "name": "Glowing Bear",
"description": "WeeChat Web frontend", "description": "WeeChat Web frontend",
"launch_path": "/glowing-bear/index.html", "launch_path": "/index.html",
"icons": { "icons": {
"128": "/glowing-bear/assets/img/glowing_bear_128x128.png", "128": "/assets/img/glowing_bear_128x128.png",
"60": "/glowing-bear/assets/img/glowing_bear_60x60.png", "60": "/assets/img/glowing_bear_60x60.png",
"90": "/glowing-bear/assets/img/glowing_bear_90x90.png", "90": "/assets/img/glowing_bear_90x90.png",
"32": "/glowing-bear/assets/img/favicon.png" "32": "/assets/img/favicon.png"
}, },
"installs_allowed_from": [ "installs_allowed_from": [
"*" "*"

View File

@ -17,17 +17,20 @@
"src": "assets/img/glowing_bear_128x128.png", "src": "assets/img/glowing_bear_128x128.png",
"sizes": "128x128" "sizes": "128x128"
}], }],
"scope": "/glowing-bear/", "scope": "/",
"start_url": "/glowing-bear/index.html", "start_url": "/index.html",
"display": "standalone", "display": "standalone",
"orientation": "portrait-primary", "orientation": "portrait-primary",
"theme_color": "#181818", "theme_color": "#181818",
"background_color": "#333", "background_color": "#333",
"prefer_related_applications": false, "prefer_related_applications": false,
"chrome_related_applications": [{ "chrome_related_applications": [
"platform": "web" {
}, { "platform": "web"
"platform": "android", },
"location": "https://play.google.com/store/apps/details?id=com.glowing_bear" {
}] "platform": "android",
"location": "https://play.google.com/store/apps/details?id=com.glowing_bear"
}
]
} }