Speed up click on host by using cached serverinfo

This commit is contained in:
Cameron Gutman 2016-08-27 13:07:43 -07:00
parent 9401443c4f
commit 682246fa27

View File

@ -213,22 +213,28 @@ function hostChosen(sourceEvent) {
} }
api = hosts[serverUid]; api = hosts[serverUid];
if(!!api.refreshServerInfo == false) { // bang bang, you're a bool (cast the function into truthiness to check for existance) stopBackgroundPollingOfHost(api);
console.log('error: revival of object failed!');
} // Use the cached state of this host from the last poll
api.refreshServerInfo().then(function (ret) {
if(!api.paired) { if(!api.paired) {
// It doesn't think we're paired. Refresh our serverinfo to make sure.
api.refreshServerInfo().then(function (ret) {
if (!api.paired) {
// Still not paired; go to the pairing flow
pairTo(api, function(){ showApps(api); saveHosts();}, function(){}); pairTo(api, function(){ showApps(api); saveHosts();}, function(){});
} else { } else {
// When we queried again, it was paired, so show apps.
showApps(api); showApps(api);
} }
stopBackgroundPollingOfHost(api);
}, function (failedRefreshInfo) { }, function (failedRefreshInfo) {
snackbarLog('Failed to connect to ' + api.address + '! Are you sure the host is on?'); snackbarLog('Failed to connect to ' + api.address + '! Are you sure the host is on?');
console.log('Returned error was: ' + failedRefreshInfo); console.log('Returned error was: ' + failedRefreshInfo);
console.log('failed API object: '); console.log('failed API object: ');
console.log(api.toString()); console.log(api.toString());
}); });
} else {
showApps(api);
}
} }
// the `+` was selected on the host grid. // the `+` was selected on the host grid.