Improve documentation & cordova checks
This commit is contained in:
parent
8ba2b1acf6
commit
56d190ab5c
5 changed files with 35 additions and 25 deletions
|
@ -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) {
|
||||
return function(text) {
|
||||
// Cordova: need to use window.open instead of href
|
||||
// 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);
|
||||
};
|
||||
}]);
|
||||
|
|
|
@ -44,12 +44,12 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
'onlyUnread': false,
|
||||
'hotlistsync': true,
|
||||
'orderbyserver': true,
|
||||
'useFavico': true,
|
||||
'useFavico': !utils.isCordova(),
|
||||
'soundnotification': true,
|
||||
'fontsize': '14px',
|
||||
'fontfamily': (utils.isMobileUi() ? 'sans-serif' : 'Inconsolata, Consolas, Monaco, Ubuntu Mono, monospace'),
|
||||
'readlineBindings': false,
|
||||
'enableJSEmoji': (utils.isMobileUi() ? false : true),
|
||||
'enableJSEmoji': !utils.isMobileUi(),
|
||||
'enableMathjax': false,
|
||||
'enableQuickKeys': true,
|
||||
'customCSS': '',
|
||||
|
@ -96,10 +96,10 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
})();
|
||||
|
||||
// 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:") &&
|
||||
(["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) {
|
||||
// Use packaged emojione sprite in the electron app
|
||||
|
@ -232,7 +232,9 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
}
|
||||
});
|
||||
|
||||
if (!utils.isCordova()) {
|
||||
$rootScope.favico = new Favico({animation: 'none'});
|
||||
}
|
||||
$scope.notifications = notifications.unreadCount('notification');
|
||||
$scope.unread = notifications.unreadCount('unread');
|
||||
|
||||
|
@ -241,7 +243,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
$scope.notifications = notifications.unreadCount('notification');
|
||||
$scope.unread = notifications.unreadCount('unread');
|
||||
|
||||
if (window.cordova === undefined && settings.useFavico && $rootScope.favico) {
|
||||
if (!utils.isCordova() && settings.useFavico && $rootScope.favico) {
|
||||
notifications.updateFavico();
|
||||
}
|
||||
});
|
||||
|
@ -250,17 +252,18 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
// Reset title
|
||||
$rootScope.pageTitle = '';
|
||||
$rootScope.notificationStatus = '';
|
||||
|
||||
// cancel outstanding notifications (incl cordova)
|
||||
notifications.cancelAll();
|
||||
if (window.plugin !== undefined && window.plugin.notification !== undefined && window.plugin.notification.local !== undefined) {
|
||||
window.plugin.notification.local.cancelAll();
|
||||
}
|
||||
|
||||
models.reinitialize();
|
||||
$rootScope.$emit('notificationChanged');
|
||||
$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';
|
||||
|
@ -381,8 +384,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
return;
|
||||
}
|
||||
|
||||
if (window.cordova !== undefined) {
|
||||
return;
|
||||
if (utils.isCordova()) {
|
||||
return; // cordova doesn't have a favicon
|
||||
}
|
||||
|
||||
if (useFavico) {
|
||||
|
@ -398,7 +401,8 @@ 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 (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
|
||||
$rootScope.mathjax_init = true;
|
||||
|
||||
|
@ -820,7 +824,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
$scope.disconnect();
|
||||
}
|
||||
|
||||
if (window.cordova !== undefined) {
|
||||
if (!utils.isCordova()) {
|
||||
$scope.favico.reset();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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 notifications = [];
|
||||
// Ask for permission to display desktop notifications
|
||||
|
@ -37,7 +37,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
|
|||
|
||||
document.addEventListener('deviceready', function() {
|
||||
// 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.on("click", function (notification) {
|
||||
// go to buffer
|
||||
|
@ -112,7 +112,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
|
|||
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
|
||||
// Calculate notification id from buffer ID
|
||||
// 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() {
|
||||
if (window.cordova !== undefined) {
|
||||
return;
|
||||
if (utils.isCordova()) {
|
||||
return; // cordova doesn't have a favicon
|
||||
}
|
||||
|
||||
var notifications = unreadCount('notification');
|
||||
|
@ -235,8 +235,7 @@ weechat.factory('notifications', ['$rootScope', '$log', 'models', 'settings', fu
|
|||
|
||||
showNotification(buffer, title, body);
|
||||
|
||||
if (window.cordova === undefined && settings.soundnotification) {
|
||||
// TODO fill in a sound file
|
||||
if (!utils.isCordova() && settings.soundnotification) {
|
||||
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>';
|
||||
document.getElementById("soundNotification").innerHTML = soundHTML;
|
||||
|
|
|
@ -21,6 +21,10 @@ weechat.factory('utils', function() {
|
|||
return (document.body.clientWidth < mobile_cutoff);
|
||||
};
|
||||
|
||||
var isCordova = function() {
|
||||
return window.cordova !== undefined;
|
||||
};
|
||||
|
||||
|
||||
// Inject a javascript (used by KaTeX)
|
||||
var inject_script = function(script_url) {
|
||||
|
@ -46,6 +50,7 @@ weechat.factory('utils', function() {
|
|||
changeClassStyle: changeClassStyle,
|
||||
getClassStyle: getClassStyle,
|
||||
isMobileUi: isMobileUi,
|
||||
isCordova: isCordova,
|
||||
inject_script: inject_script,
|
||||
inject_css: inject_css,
|
||||
};
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
},
|
||||
"app": {
|
||||
"urls": [
|
||||
"http://www.glowing-bear.org/"
|
||||
"https://www.glowing-bear.org/"
|
||||
],
|
||||
"launch": {
|
||||
"container": "panel",
|
||||
"web_url": "http://www.glowing-bear.org/"
|
||||
"web_url": "https://www.glowing-bear.org/"
|
||||
}
|
||||
},
|
||||
"permissions": [
|
||||
|
|
Loading…
Reference in a new issue