diff options
author | LASER-Yi <[email protected]> | 2021-08-24 09:31:47 +0800 |
---|---|---|
committer | LASER-Yi <[email protected]> | 2021-08-24 09:31:47 +0800 |
commit | 81507b9e750228de6d52cb3f7cbd631ecfac3713 (patch) | |
tree | 8f88568274f58cb3a28588d1a365e209a375a32b /frontend | |
parent | 45e93df2ebb4a4b6707a0e7f3c612bc83813bcff (diff) | |
download | bazarr-81507b9e750228de6d52cb3f7cbd631ecfac3713.tar.gz bazarr-81507b9e750228de6d52cb3f7cbd631ecfac3713.zip |
Add a dialog before closing the page to inform user when there're still background tasks running
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/src/@modules/task/index.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/frontend/src/@modules/task/index.ts b/frontend/src/@modules/task/index.ts index aee555b0d..02483e990 100644 --- a/frontend/src/@modules/task/index.ts +++ b/frontend/src/@modules/task/index.ts @@ -12,6 +12,17 @@ class BackgroundTask { private groups: Task.Group; constructor() { 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>[]) { |