0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-12-26 02:23:48 +01:00

Override status in update api

This commit is contained in:
peteruithoven 2014-05-26 17:27:20 +02:00
parent 8258673a89
commit c521cd4438

View File

@ -27,6 +27,15 @@ function UpdateAPI() {
var _autoRefreshing = false; var _autoRefreshing = false;
var _refreshDelay; var _refreshDelay;
this.refreshDelayTime = 2000; this.refreshDelayTime = 2000;
var _installing = false;
var _ignoreNextStatusResponse = false;
// When the updater doesn't preserve settings the box can't reconnect
// to the same network, so we can't retrieve whether the update was
// successfull, so we override the state to INSTALLED after a fixed delay
var INSTALL_TIME = 90*1000;
var _installedDelayer; // setTimout instance
//callbacks //callbacks
this.refreshing; // I'm refreshing this.refreshing; // I'm refreshing
this.updated; // New network status info this.updated; // New network status info
@ -47,6 +56,10 @@ function UpdateAPI() {
timeout: _timeoutTime, timeout: _timeoutTime,
success: function(response){ success: function(response){
//console.log("UpdateAPI:status response: ",response); //console.log("UpdateAPI:status response: ",response);
if(_ignoreNextStatusResponse) {
_ignoreNextStatusResponse = false;
return;
}
if(response.status == "error" || response.status == "fail") { if(response.status == "error" || response.status == "fail") {
if(failedHandler) failedHandler(response); if(failedHandler) failedHandler(response);
} else { } else {
@ -58,10 +71,18 @@ function UpdateAPI() {
} else { } else {
data.newest_version_is_newer = true; data.newest_version_is_newer = true;
} }
completeHandler(response.data); if(_installing && data.state_code === UpdateAPI.STATUS.NONE) {
data.state_code = UpdateAPI.STATUS.INSTALLED;
_installing = false;
}
completeHandler(data);
} }
} }
}).fail(function() { }).fail(function() {
if(_ignoreNextStatusResponse) {
_ignoreNextStatusResponse = false;
return;
}
if(failedHandler) failedHandler(); if(failedHandler) failedHandler();
}); });
} }
@ -77,13 +98,14 @@ function UpdateAPI() {
if(failedHandler) failedHandler(response); if(failedHandler) failedHandler(response);
} else { } else {
var data = response.data; var data = response.data;
completeHandler(response.data); if(completeHandler) completeHandler(response.data);
} }
} }
}).fail(function() { }).fail(function() {
//console.log("UpdatePanel:downloadUpdate: failed"); //console.log("UpdatePanel:downloadUpdate: failed");
if(failedHandler) failedHandler(); if(failedHandler) failedHandler();
}); });
overrideStatus(UpdateAPI.STATUS.DOWNLOADING);
} }
this.install = function(noRetain, completeHandler,failedHandler) { this.install = function(noRetain, completeHandler,failedHandler) {
//console.log("UpdateAPI:install"); //console.log("UpdateAPI:install");
@ -95,10 +117,24 @@ function UpdateAPI() {
dataType: 'json', dataType: 'json',
success: function(response){ success: function(response){
//console.log("UpdatePanel:installUpdate response: ",response); //console.log("UpdatePanel:installUpdate response: ",response);
if(response.status == "error" || response.status == "fail") {
if(failedHandler) failedHandler(response);
} else {
var data = response.data;
if(completeHandler) completeHandler(response.data);
}
} }
}).fail(function() { }).fail(function() {
//console.log("UpdatePanel:installUpdate: no respons (there shouldn't be)"); //console.log("UpdatePanel:installUpdate: no respons (there shouldn't be)");
}); });
overrideStatus(UpdateAPI.STATUS.INSTALLING);
clearTimeout(_installedDelayer);
if(noRetain) {
_installedDelayer = setTimeout(function() {
overrideStatus(UpdateAPI.STATUS.INSTALLED);
},INSTALL_TIME);
}
_installing = true;
} }
@ -137,6 +173,18 @@ function UpdateAPI() {
}); });
} }
function overrideStatus(status) {
_self.state = status;
var data = {state_code:status,override:true};
if(_self.updated) {
_self.updated(data);
}
if(_autoRefreshing) {
_ignoreNextStatusResponse = true;
_self.refresh();
}
}
function versionIsBeta(version) { function versionIsBeta(version) {
return version ? /.*-.*/g.test(version) : null; return version ? /.*-.*/g.test(version) : null;
} }