Add a dialog before closing the page to inform user when there're still background tasks running

pull/1523/head
LASER-Yi 3 years ago
parent 45e93df2eb
commit 81507b9e75

@ -12,6 +12,17 @@ class BackgroundTask {
private groups: Task.Group; private groups: Task.Group;
constructor() { constructor() {
this.groups = {}; this.groups = {};
window.addEventListener("beforeunload", this.onBeforeUnload.bind(this));
}
private onBeforeUnload(e: BeforeUnloadEvent) {
const message = "Background tasks are still running";
if (Object.keys(this.groups).length !== 0) {
e.preventDefault();
e.returnValue = message;
return;
}
delete e["returnValue"];
} }
dispatch<T extends Task.Callable>(groupName: string, tasks: Task.Task<T>[]) { dispatch<T extends Task.Callable>(groupName: string, tasks: Task.Task<T>[]) {

Loading…
Cancel
Save