Browse Source

Merge pull request #562 from AudriusButkevicius/restart

Fix race condition while restarting (fixes #560)
Jakob Borg 11 years ago
parent
commit
1a174e75d3
2 changed files with 19 additions and 13 deletions
  1. 0 0
      auto/gui.files.go
  2. 19 13
      gui/app.js

File diff suppressed because it is too large
+ 0 - 0
auto/gui.files.go


+ 19 - 13
gui/app.js

@@ -22,18 +22,10 @@ syncthing.config(function ($httpProvider, $translateProvider) {
 
 syncthing.controller('EventCtrl', function ($scope, $http) {
     $scope.lastEvent = null;
-    var online = false;
     var lastID = 0;
 
-    $(window).bind('beforeunload', function() {
-        online = false;
-    });
-
     var successFn = function (data) {
-        if (!online) {
-            $scope.$emit('UIOnline');
-            online = true;
-        }
+        $scope.$emit('UIOnline');
 
         if (lastID > 0) {
             data.forEach(function (event) {
@@ -53,10 +45,8 @@ syncthing.controller('EventCtrl', function ($scope, $http) {
     };
 
     var errorFn = function (data) {
-        if (online) {
-            $scope.$emit('UIOffline');
-            online = false;
-        }
+        $scope.$emit('UIOffline');
+
         setTimeout(function () {
             $http.get(urlbase + '/events?limit=1')
             .success(successFn)
@@ -72,6 +62,8 @@ syncthing.controller('EventCtrl', function ($scope, $http) {
 syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $location) {
     var prevDate = 0;
     var getOK = true;
+    var navigatingAway = false;
+    var online = false;
     var restarting = false;
 
     $scope.completion = {};
@@ -108,6 +100,10 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
         }
     })
 
+    $(window).bind('beforeunload', function() {
+        navigatingAway = true;
+    });
+
     $scope.$on("$locationChangeSuccess", function () {
         var lang = $location.search().lang;
         if (lang) {
@@ -129,8 +125,13 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
     }
 
     $scope.$on('UIOnline', function (event, arg) {
+        if (online && !restarting) {
+            return;
+        }
+
         console.log('UIOnline');
         $scope.init();
+        online = true;
         restarting = false;
         $('#networkError').modal('hide');
         $('#restarting').modal('hide');
@@ -138,7 +139,12 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
     });
 
     $scope.$on('UIOffline', function (event, arg) {
+        if (navigatingAway || !online) {
+            return;
+        }
+
         console.log('UIOffline');
+        online = false;
         if (!restarting) {
             $('#networkError').modal();
         }

Some files were not shown because too many files changed in this diff