diff --git a/src/playlist.js b/src/playlist.js index 604e415..c30861f 100644 --- a/src/playlist.js +++ b/src/playlist.js @@ -253,6 +253,15 @@ const playlistDownloader = { controller.signal ); + document.addEventListener("beforeunload", () => { + if ( + this.state.currentDownloadProcess && + !this.state.currentDownloadProcess.killed + ) { + this.state.currentDownloadProcess.kill(); + } + }); + this.handleDownloadEvents(this.state.currentDownloadProcess, type); }, diff --git a/src/renderer.js b/src/renderer.js index 90227f4..45b5342 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -953,6 +953,12 @@ class YtDownloaderApp { const process = this.state.ytDlp.exec(args, {shell: true}); + window.addEventListener("beforeunload", () => { + if (process && !process.killed) { + process.kill(); + } + }); + console.log( "Spawned yt-dlp with args:", process.ytDlpProcess.spawnargs.join(" "), @@ -1012,6 +1018,12 @@ class YtDownloaderApp { signal: controller.signal, }); + window.addEventListener("beforeunload", () => { + if (downloadProcess && !downloadProcess.killed) { + downloadProcess.kill(); + } + }); + console.log( "Spawned yt-dlp with args:", downloadProcess.ytDlpProcess.spawnargs.join(" "),