Fix race condition while restarting (fixes #560)
This commit is contained in:
parent
3b1603cadf
commit
9e1fd3454f
File diff suppressed because one or more lines are too long
32
gui/app.js
32
gui/app.js
|
@ -22,18 +22,10 @@ syncthing.config(function ($httpProvider, $translateProvider) {
|
||||||
|
|
||||||
syncthing.controller('EventCtrl', function ($scope, $http) {
|
syncthing.controller('EventCtrl', function ($scope, $http) {
|
||||||
$scope.lastEvent = null;
|
$scope.lastEvent = null;
|
||||||
var online = false;
|
|
||||||
var lastID = 0;
|
var lastID = 0;
|
||||||
|
|
||||||
$(window).bind('beforeunload', function() {
|
|
||||||
online = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
var successFn = function (data) {
|
var successFn = function (data) {
|
||||||
if (!online) {
|
$scope.$emit('UIOnline');
|
||||||
$scope.$emit('UIOnline');
|
|
||||||
online = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastID > 0) {
|
if (lastID > 0) {
|
||||||
data.forEach(function (event) {
|
data.forEach(function (event) {
|
||||||
|
@ -53,10 +45,8 @@ syncthing.controller('EventCtrl', function ($scope, $http) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var errorFn = function (data) {
|
var errorFn = function (data) {
|
||||||
if (online) {
|
$scope.$emit('UIOffline');
|
||||||
$scope.$emit('UIOffline');
|
|
||||||
online = false;
|
|
||||||
}
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$http.get(urlbase + '/events?limit=1')
|
$http.get(urlbase + '/events?limit=1')
|
||||||
.success(successFn)
|
.success(successFn)
|
||||||
|
@ -72,6 +62,8 @@ syncthing.controller('EventCtrl', function ($scope, $http) {
|
||||||
syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $location) {
|
syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $location) {
|
||||||
var prevDate = 0;
|
var prevDate = 0;
|
||||||
var getOK = true;
|
var getOK = true;
|
||||||
|
var navigatingAway = false;
|
||||||
|
var online = false;
|
||||||
var restarting = false;
|
var restarting = false;
|
||||||
|
|
||||||
$scope.completion = {};
|
$scope.completion = {};
|
||||||
|
@ -108,6 +100,10 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$(window).bind('beforeunload', function() {
|
||||||
|
navigatingAway = true;
|
||||||
|
});
|
||||||
|
|
||||||
$scope.$on("$locationChangeSuccess", function () {
|
$scope.$on("$locationChangeSuccess", function () {
|
||||||
var lang = $location.search().lang;
|
var lang = $location.search().lang;
|
||||||
if (lang) {
|
if (lang) {
|
||||||
|
@ -129,8 +125,13 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.$on('UIOnline', function (event, arg) {
|
$scope.$on('UIOnline', function (event, arg) {
|
||||||
|
if (online && !restarting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log('UIOnline');
|
console.log('UIOnline');
|
||||||
$scope.init();
|
$scope.init();
|
||||||
|
online = true;
|
||||||
restarting = false;
|
restarting = false;
|
||||||
$('#networkError').modal('hide');
|
$('#networkError').modal('hide');
|
||||||
$('#restarting').modal('hide');
|
$('#restarting').modal('hide');
|
||||||
|
@ -138,7 +139,12 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.$on('UIOffline', function (event, arg) {
|
$scope.$on('UIOffline', function (event, arg) {
|
||||||
|
if (navigatingAway || !online) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log('UIOffline');
|
console.log('UIOffline');
|
||||||
|
online = false;
|
||||||
if (!restarting) {
|
if (!restarting) {
|
||||||
$('#networkError').modal();
|
$('#networkError').modal();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue