gui: Fix race in online event callback (fixes #7733) (#7771)

This commit is contained in:
Simon Frei
2021-06-16 19:32:30 +02:00
committed by GitHub
parent adb7763f87
commit 2c7d9b59c6
@@ -109,46 +109,49 @@ angular.module('syncthing.core')
console.log('UIOnline'); console.log('UIOnline');
refreshSystem();
refreshDiscoveryCache();
refreshConfig();
refreshCluster();
refreshConnectionStats();
refreshDeviceStats(); refreshDeviceStats();
refreshFolderStats(); refreshFolderStats();
refreshGlobalChanges(); refreshGlobalChanges();
refreshThemes(); refreshThemes();
$http.get(urlbase + '/system/version').success(function (data) { $q.all([
console.log("version", data); refreshSystem(),
if ($scope.version.version && $scope.version.version !== data.version) { refreshDiscoveryCache(),
// We already have a version response, but it differs from refreshConfig(),
// the new one. Reload the full GUI in case it's changed. refreshCluster(),
document.location.reload(true); refreshConnectionStats(),
} ]).then(function() {
$http.get(urlbase + '/system/version').success(function (data) {
console.log("version", data);
if ($scope.version.version && $scope.version.version !== data.version) {
// We already have a version response, but it differs from
// the new one. Reload the full GUI in case it's changed.
document.location.reload(true);
}
$scope.version = data; $scope.version = data;
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
$http.get(urlbase + '/svc/report').success(function (data) { $http.get(urlbase + '/svc/report').success(function (data) {
$scope.reportData = data; $scope.reportData = data;
if ($scope.system && $scope.config.options.urAccepted > -1 && $scope.config.options.urSeen < $scope.system.urVersionMax && $scope.config.options.urAccepted < $scope.system.urVersionMax) { if ($scope.system && $scope.config.options.urAccepted > -1 && $scope.config.options.urSeen < $scope.system.urVersionMax && $scope.config.options.urAccepted < $scope.system.urVersionMax) {
// Usage reporting format has changed, prompt the user to re-accept. // Usage reporting format has changed, prompt the user to re-accept.
$('#ur').modal(); $('#ur').modal();
} }
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
$http.get(urlbase + '/system/upgrade').success(function (data) { $http.get(urlbase + '/system/upgrade').success(function (data) {
$scope.upgradeInfo = data; $scope.upgradeInfo = data;
}).error(function () { }).error(function () {
$scope.upgradeInfo = null; $scope.upgradeInfo = null;
}); });
online = true; online = true;
restarting = false; restarting = false;
$('#networkError').modal('hide'); $('#networkError').modal('hide');
$('#restarting').modal('hide'); $('#restarting').modal('hide');
$('#shutdown').modal('hide'); $('#shutdown').modal('hide');
}).catch($scope.emitHTTPError);
}); });
$scope.$on(Events.OFFLINE, function () { $scope.$on(Events.OFFLINE, function () {
@@ -462,7 +465,7 @@ angular.module('syncthing.core')
} }
function refreshSystem() { function refreshSystem() {
$http.get(urlbase + '/system/status').success(function (data) { return $http.get(urlbase + '/system/status').success(function (data) {
$scope.myID = data.myID; $scope.myID = data.myID;
$scope.system = data; $scope.system = data;
@@ -526,18 +529,20 @@ angular.module('syncthing.core')
} }
function refreshCluster() { function refreshCluster() {
$http.get(urlbase + '/cluster/pending/devices').success(function (data) { return $q.all([
$scope.pendingDevices = data; $http.get(urlbase + '/cluster/pending/devices').success(function (data) {
console.log("refreshCluster devices", data); $scope.pendingDevices = data;
}).error($scope.emitHTTPError); console.log("refreshCluster devices", data);
$http.get(urlbase + '/cluster/pending/folders').success(function (data) { }).error($scope.emitHTTPError),
$scope.pendingFolders = data; $http.get(urlbase + '/cluster/pending/folders').success(function (data) {
console.log("refreshCluster folders", data); $scope.pendingFolders = data;
}).error($scope.emitHTTPError); console.log("refreshCluster folders", data);
}).error($scope.emitHTTPError),
]);
} }
function refreshDiscoveryCache() { function refreshDiscoveryCache() {
$http.get(urlbase + '/system/discovery').success(function (data) { return $http.get(urlbase + '/system/discovery').success(function (data) {
for (var device in data) { for (var device in data) {
for (var i = 0; i < data[device].addresses.length; i++) { for (var i = 0; i < data[device].addresses.length; i++) {
// Relay addresses are URLs with // Relay addresses are URLs with
@@ -618,7 +623,7 @@ angular.module('syncthing.core')
} }
function refreshConnectionStats() { function refreshConnectionStats() {
$http.get(urlbase + '/system/connections').success(function (data) { return $http.get(urlbase + '/system/connections').success(function (data) {
var now = Date.now(), var now = Date.now(),
td = (now - prevDate) / 1000, td = (now - prevDate) / 1000,
id; id;
@@ -660,14 +665,15 @@ angular.module('syncthing.core')
} }
function refreshConfig() { function refreshConfig() {
$http.get(urlbase + '/config').success(function (data) { return $q.all([
updateLocalConfig(data); $http.get(urlbase + '/config').success(function (data) {
console.log("refreshConfig", data); updateLocalConfig(data);
}).error($scope.emitHTTPError); console.log("refreshConfig", data);
}),
$http.get(urlbase + '/config/insync').success(function (data) { $http.get(urlbase + '/config/insync').success(function (data) {
$scope.configInSync = data.configInSync; $scope.configInSync = data.configInSync;
}).error($scope.emitHTTPError); }),
]);
} }
$scope.refreshNeed = function (page, perpage) { $scope.refreshNeed = function (page, perpage) {
@@ -1413,16 +1419,11 @@ angular.module('syncthing.core')
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}; };
$http.put(urlbase + '/config', cfg, opts).success(function () { $http.put(urlbase + '/config', cfg, opts).finally(refreshConfig).then(function() {
refreshConfig();
if (callback) { if (callback) {
callback(); callback();
} }
}).error(function (data, status, headers, config) { }, $scope.emitHTTPError);
refreshConfig();
$scope.emitHTTPError(data, status, headers, config);
});
}; };
$scope.urVersions = function () { $scope.urVersions = function () {