From 24f63be25c2148201899fba7fd9fb6ffec3bb7a6 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Sun, 31 Aug 2014 09:59:10 -0400 Subject: [PATCH 1/2] When closing the window, disconnect instead of asking the user to do it --- js/glowingbear.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index ec8fbb1..161b9e2 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -612,9 +612,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // Prevent user from accidentally leaving the page window.onbeforeunload = function(event) { if ($rootScope.connected) { - 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."; + $scope.disconnect(); } $rootScope.favico.reset(); }; From 9438c3844f199dfc41e48957b75ec27a46cdc7b2 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Sun, 31 Aug 2014 10:29:13 -0400 Subject: [PATCH 2/2] Ask confirmation before closing if user has unsent input --- index.html | 2 +- js/glowingbear.js | 17 ++++++++++++++--- js/inputbar.js | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index af653d8..45327bc 100644 --- a/index.html +++ b/index.html @@ -280,7 +280,7 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel
diff --git a/js/glowingbear.js b/js/glowingbear.js index 161b9e2..88801cc 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -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,10 +613,19 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // Prevent user from accidentally leaving the page window.onbeforeunload = function(event) { - if ($rootScope.connected) { - $scope.disconnect(); + + if ($scope.command !== null && $scope.command !== '') { + event.preventDefault(); + // 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(); }; }]); diff --git a/js/inputbar.js b/js/inputbar.js index 8f3ddd2..54ea52c 100644 --- a/js/inputbar.js +++ b/js/inputbar.js @@ -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,