Correctly exit from web request

This commit is contained in:
Yukino Song
2024-08-24 05:42:56 +08:00
parent 94e0542157
commit 29e20eb02d
3 changed files with 28 additions and 45 deletions

View File

@@ -260,34 +260,17 @@
quit() {
if (window.confirm("Do you really want to quit Apollo? You'll not be able to start Apollo again if you have no other methods to operate your computer.")) {
this.serverQuitting = true;
const timeoutID = setTimeout(() => {
this.serverQuitting = false;
}, 5000);
fetch("/api/quit", {
method: "POST",
})
.then(() => {
clearTimeout(timeoutID);
return new Promise((resolve, reject) => {
setTimeout(() => {
fetch("/", {
signal: AbortSignal.timeout(1000)
}).then(() => {
reject();
}).catch(() => {
resolve();
})
}, 1000);
});
})
.then(() => {
this.serverQuitting = false;
this.serverQuit = true;
})
.catch(() => {
this.serverQuitting = false;
this.serverQuit = false;
alert("Exit failed!");
})
.catch(() => {
this.serverQuitting = false;
this.serverQuit = true;
});
}
}