Move initialisation code to functions
This commit is contained in:
parent
e301849a73
commit
3f68a156a4
1 changed files with 33 additions and 25 deletions
|
@ -462,15 +462,6 @@ function($rootScope,
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', function ($rootScope, $scope, $store, $timeout, $log, models, connection) {
|
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', function ($rootScope, $scope, $store, $timeout, $log, models, connection) {
|
||||||
if (window.Notification) {
|
|
||||||
// Request notification permission
|
|
||||||
Notification.requestPermission(function (status) {
|
|
||||||
$log.info('Notification permission status:',status);
|
|
||||||
if (Notification.permission !== status) {
|
|
||||||
Notification.permission = status;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.mobile_cutoff = 968;
|
$scope.mobile_cutoff = 968;
|
||||||
|
|
||||||
|
@ -501,7 +492,20 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
console.log(watchers.length);
|
console.log(watchers.length);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.requestWebkitNotificationPermission = function() {
|
|
||||||
|
// Ask for permission to display desktop notifications
|
||||||
|
$scope.requestNotificationPermission = function() {
|
||||||
|
// Firefox
|
||||||
|
if (window.Notification) {
|
||||||
|
Notification.requestPermission(function(status) {
|
||||||
|
$log.info('Notification permission status: ', status);
|
||||||
|
if (Notification.permission !== status) {
|
||||||
|
Notification.permission = status;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Webkit
|
||||||
if (window.webkitNotifications !== undefined) {
|
if (window.webkitNotifications !== undefined) {
|
||||||
var havePermission = window.webkitNotifications.checkPermission();
|
var havePermission = window.webkitNotifications.checkPermission();
|
||||||
if (havePermission !== 0) { // 0 is PERMISSION_ALLOWED
|
if (havePermission !== 0) { // 0 is PERMISSION_ALLOWED
|
||||||
|
@ -511,19 +515,23 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
$scope.isinstalled = (function() {
|
||||||
// Check for firefox & app installed
|
// Check for firefox & app installed
|
||||||
if (navigator.mozApps !== undefined) {
|
if (navigator.mozApps !== undefined) {
|
||||||
navigator.mozApps.getSelf().onsuccess = function _onAppReady(evt) {
|
navigator.mozApps.getSelf().onsuccess = function _onAppReady(evt) {
|
||||||
var app = evt.target.result;
|
var app = evt.target.result;
|
||||||
if (app) {
|
if (app) {
|
||||||
$scope.isinstalled = true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$scope.isinstalled = false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
$scope.isinstalled = false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
|
|
||||||
// Reduce buffers with "+" operation over a key. Mostly useful for unread/notification counts.
|
// Reduce buffers with "+" operation over a key. Mostly useful for unread/notification counts.
|
||||||
$rootScope.unreadCount = function(type) {
|
$rootScope.unreadCount = function(type) {
|
||||||
|
@ -774,7 +782,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
|
|
||||||
|
|
||||||
$scope.connect = function() {
|
$scope.connect = function() {
|
||||||
$scope.requestWebkitNotificationPermission();
|
$scope.requestNotificationPermission();
|
||||||
connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl);
|
connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl);
|
||||||
};
|
};
|
||||||
$scope.disconnect = function() {
|
$scope.disconnect = function() {
|
||||||
|
|
Loading…
Reference in a new issue