Skip to content

Commit

Permalink
Add button to cancel path autodetection
Browse files Browse the repository at this point in the history
  • Loading branch information
drojf committed Apr 10, 2021
1 parent 4efd0b9 commit e6371a5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions httpGUI/installer.html
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ <h4>This patch is only for WINDOWS. It does not work on Mac or Linux</h4>
<br>
<h3><span>Please wait, path autodetection in progress</span><span class="loader"></span></h3>
<h4>Detection may take up to {{ TIMEOUT_AUTO_DETECT_PATHS }} seconds.</h4>
<button type="button" class="btn" v-on:click="abortGamePaths()">Cancel Path Autodetection (Select Manually)</button>
</div>
<!-- Section allowing you to start install or choose game path to install -->
<div v-bind:class="{ 'greyed-out-disabled': pathAutoDetectionInProgress }">
Expand Down
17 changes: 14 additions & 3 deletions httpGUI/python-patcher-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ window.onload = function onWindowLoaded() {
installErrorDescription: "",
installDataLoaded: false,
TIMEOUT_AUTO_DETECT_PATHS: 15,
gamePathsXHR: null //The last gamePaths XMLHttpRequest, or null if none exists
},
methods: {
doInstall(deleteVersionInformation) {
Expand Down Expand Up @@ -299,6 +300,12 @@ Continue install anyway?`)) {
app.installFinished = true;
window.location = 'shutdown.html';
},
abortGamePaths() {
// Abort game path autodetection if one is in progress
if (app.gamePathsXHR !== null) {
app.gamePathsXHR.abort();
}
},
},
computed: {
modHandles() {
Expand Down Expand Up @@ -331,7 +338,8 @@ Continue install anyway?`)) {
if (app.installStarted) { return; }
if (newSelectedSubMod !== null) {
app.pathAutoDetectionInProgress = true;
doPost('gamePaths', { id: newSelectedSubMod.id }, (responseData) => {
app.gamePathsXHR = doPost('gamePaths', { id: newSelectedSubMod.id }, (responseData) => {
app.gamePathsXHR = null;
app.pathAutoDetectionInProgress = false;
this.partiallyUninstalledPaths = responseData.partiallyUninstalledPaths;
this.fullInstallConfigs = responseData.fullInstallConfigHandles;
Expand All @@ -342,9 +350,12 @@ Continue install anyway?`)) {
}
},
app.TIMEOUT_AUTO_DETECT_PATHS * 1000,
(errorMessage) => {
(errorMessage, reason) => {
app.gamePathsXHR = null;
app.pathAutoDetectionInProgress = false;
alert(`Couldn't autodetect game path due to an error - please select game path manually.\n\nError: ${errorMessage}`);
if (reason !== 'abort') {
alert(`Couldn't autodetect game path due to an error - please select game path manually.\n\nError: ${errorMessage}`);
}
});
} else {
this.fullInstallConfigs = [];
Expand Down
20 changes: 12 additions & 8 deletions httpGUI/python-patcher-rest-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ function doPost(requestType, requestData, onSuccessCallback, timeout, onErrorCal
const http = new XMLHttpRequest();
const url = 'installer_data'; // in python, is stored in 'self.path' on the handler class

function errorHandler(msg) {
function errorHandler(msg, reason) {
const message = `[${requestType}] POST Error - "${msg}" - You must have the install loader window/console open - it is required for the installation.`;
console.log(message);
POSTNotificationErrorCallback(message);
if (reason !== 'abort') {
POSTNotificationErrorCallback(message);
}
if (typeof onErrorCallback !== 'undefined') {
onErrorCallback(msg);
onErrorCallback(msg, reason);
}
}

Expand All @@ -74,28 +76,30 @@ function doPost(requestType, requestData, onSuccessCallback, timeout, onErrorCal
onSuccessCallback(responseDataObject);
}
} else {
errorHandler(`Unexpected HTTP Status [${http.status}]`);
errorHandler(`Unexpected HTTP Status [${http.status}]`, 'status');
}
}
};

http.onabort = () => {
errorHandler('POST Aborted');
http.onabort = function () {
errorHandler('POST Aborted', 'abort');
};

http.onerror = function () {
errorHandler('POST Error');
errorHandler('POST Error', 'error');
};

http.ontimeout = function (e) {
errorHandler(`POST Timeout (${http.timeout / 1000}s)`);
errorHandler(`POST Timeout (${http.timeout / 1000}s)`, 'timeout');
};

// Use a timeout of 8 seconds by default.
// After this errorHandler()/POSTNotificationErrorCallback() will be called
http.timeout = timeout !== 'undefined' ? timeout : 8000;

http.send(makeJSONRequest(requestType, requestData));

return http
}

// TODO: should always navigate to the same install page, as it is shared amongst all games
Expand Down

0 comments on commit e6371a5

Please sign in to comment.