Merge pull request #432 from glowing-bear/disconnect-when-closing

When closing the window, disconnect instead of asking the user to do it
This commit is contained in:
Lorenz Hübschle-Schneider 2014-08-31 16:25:36 +01:00
commit 6a26c61c9e
3 changed files with 16 additions and 6 deletions

View File

@ -280,7 +280,7 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
</table>
</div>
<div class="footer" ng-class="{'withnicklist': showNicklist}">
<div input-bar input-id="sendMessage"></div>
<div input-bar input-id="sendMessage" command="command"></div>
</div>
</div>
<div id="soundNotification"></div>

View File

@ -2,6 +2,8 @@ var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatMode
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', 'notifications', 'utils', function ($rootScope, $scope, $store, $timeout, $log, models, connection, notifications, utils) {
$scope.command = '';
// From: http://stackoverflow.com/a/18539624 by StackOverflow user "plantian"
$rootScope.countWatchers = function () {
var q = [$rootScope], watchers = 0, scope;
@ -611,12 +613,19 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// Prevent user from accidentally leaving the page
window.onbeforeunload = function(event) {
if ($rootScope.connected) {
if ($scope.command !== null && $scope.command !== '') {
event.preventDefault();
// Chrome requires us to set this or it will not show the dialog
event.returnValue = "You have an active connection to your WeeChat relay. Please disconnect using the button in the top-right corner or by double-tapping the Escape key.";
// Chrome requires this
// Firefox does not show the site provides message
event.returnValue = "Any unsent input will be lost. Are you sure that you want to quit?";
} else {
if ($rootScope.connected) {
$scope.disconnect();
}
$scope.favico.reset();
}
$rootScope.favico.reset();
};
}]);

View File

@ -7,7 +7,8 @@ weechat.directive('inputBar', function() {
templateUrl: 'directives/input.html',
scope: {
inputId: '@inputId'
inputId: '@inputId',
command: '=command'
},
controller: ['$rootScope', '$scope', '$element', '$log', 'connection', 'models', function($rootScope,