Improve documentation & cordova checks

This commit is contained in:
Lorenz Hübschle-Schneider 2017-04-23 14:34:12 +02:00 committed by Lorenz Hübschle-Schneider
parent 8ba2b1acf6
commit 56d190ab5c
5 changed files with 35 additions and 25 deletions

View file

@ -135,11 +135,13 @@ 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) { weechat.filter('linksForCordova', ['$sce', function($sce) {
return function(text) { return function(text) {
// Cordova: need to use window.open instead of href
// XXX TODO this needs to be improved // 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')\""); 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); return $sce.trustAsHtml(text);
}; };
}]); }]);

View file

@ -44,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': '',
@ -96,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
@ -232,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');
@ -241,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 (window.cordova === undefined && settings.useFavico && $rootScope.favico) { if (!utils.isCordova() && settings.useFavico && $rootScope.favico) {
notifications.updateFavico(); notifications.updateFavico();
} }
}); });
@ -250,17 +252,18 @@ 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');
$scope.connectbutton = 'Connect'; $scope.connectbutton = 'Connect';
$scope.connectbuttonicon = 'glyphicon-chevron-right'; $scope.connectbuttonicon = 'glyphicon-chevron-right';
bufferResume.reset(); bufferResume.reset();
if (window.plugin !== undefined && window.plugin.notification !== undefined && window.plugin.notification.local !== undefined) {
window.plugin.notification.local.cancelAll();
}
}); });
$scope.connectbutton = 'Connect'; $scope.connectbutton = 'Connect';
$scope.connectbuttonicon = 'glyphicon-chevron-right'; $scope.connectbuttonicon = 'glyphicon-chevron-right';
@ -381,8 +384,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
return; return;
} }
if (window.cordova !== undefined) { if (utils.isCordova()) {
return; return; // cordova doesn't have a favicon
} }
if (useFavico) { if (useFavico) {
@ -398,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 (window.cordova === undefined && 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;
@ -820,7 +824,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$scope.disconnect(); $scope.disconnect();
} }
if (window.cordova !== undefined) { if (!utils.isCordova()) {
$scope.favico.reset(); $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
@ -37,7 +37,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
document.addEventListener('deviceready', function() { document.addEventListener('deviceready', function() {
// Add cordova local notification click handler // Add cordova local notification click handler
if (window.cordova !== null && window.cordova.plugins !== undefined && window.cordova.plugins.notification !== undefined && if (utils.isCordova() && window.cordova.plugins !== undefined && window.cordova.plugins.notification !== undefined &&
window.cordova.plugins.notification.local !== undefined) { window.cordova.plugins.notification.local !== undefined) {
window.cordova.plugins.notification.local.on("click", function (notification) { window.cordova.plugins.notification.local.on("click", function (notification) {
// go to buffer // go to buffer
@ -112,7 +112,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
delete notifications[this.id]; delete notifications[this.id];
}; };
} else if (window.cordova !== undefined && window.cordova.plugins !== undefined && window.cordova.plugins.notification !== undefined && window.cordova.plugins.notification.local !== undefined) { } else if (utils.isCordova() && window.cordova.plugins !== undefined && window.cordova.plugins.notification !== undefined && window.cordova.plugins.notification.local !== undefined) {
// Cordova local notification // Cordova local notification
// Calculate notification id from buffer ID // Calculate notification id from buffer ID
// Needs to be unique number, but we'll only ever have one per buffer // Needs to be unique number, but we'll only ever have one per buffer
@ -166,8 +166,8 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
}; };
var updateFavico = function() { var updateFavico = function() {
if (window.cordova !== undefined) { if (utils.isCordova()) {
return; return; // cordova doesn't have a favicon
} }
var notifications = unreadCount('notification'); var notifications = unreadCount('notification');
@ -235,8 +235,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
showNotification(buffer, title, body); showNotification(buffer, title, body);
if (window.cordova === undefined && 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://www.glowing-bear.org/" "https://www.glowing-bear.org/"
], ],
"launch": { "launch": {
"container": "panel", "container": "panel",
"web_url": "http://www.glowing-bear.org/" "web_url": "https://www.glowing-bear.org/"
} }
}, },
"permissions": [ "permissions": [