From 3dd713c19dcd43f2e704894b0b6bf19a07d7debb Mon Sep 17 00:00:00 2001 From: Andrew <66430340+aandrew-me@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:35:53 +0600 Subject: [PATCH] App quit feature and removing useless code --- assets/css/index.css | 11 ++++++ html/index.html | 53 +++++++++++++++---------- main.js | 4 ++ src/renderer.js | 92 ++++++-------------------------------------- translations/en.json | 3 +- 5 files changed, 61 insertions(+), 102 deletions(-) diff --git a/assets/css/index.css b/assets/css/index.css index 40c271a..2619449 100644 --- a/assets/css/index.css +++ b/assets/css/index.css @@ -443,6 +443,17 @@ button { #advanced { display: none; } +.advancedItem{ + border: 1.5px solid gray; + border-radius: 10px; + padding:20px; + margin: 10px; +} + +#subHeader{ + font-weight: bold; + margin-top: 0; +} /* Scrollbar */ diff --git a/html/index.html b/html/index.html index 22cfc67..9a831df 100644 --- a/html/index.html +++ b/html/index.html @@ -107,26 +107,39 @@
-

Download particular time-range

- - - : - - - -

- -
Current download location -
- -

- - -

-

Subtitles

- Download subtitles if available - +
+ Close app when download finishes + +
+ +
+ Download particular time-range +

+ + + : + + +
+ + +
+
Current download location -
+
+ +
+ +
+

Subtitles

+ Download subtitles if available + +
+ + + +
diff --git a/main.js b/main.js index b10ee83..c96821d 100644 --- a/main.js +++ b/main.js @@ -247,6 +247,10 @@ ipcMain.on("select-config", () => { } }); +ipcMain.on("quit", ()=>{ + app.quit() +}) + // Auto update let autoUpdate = false; diff --git a/src/renderer.js b/src/renderer.js index a46fcc2..f42f697 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -677,44 +677,6 @@ getId("extractBtn").addEventListener("click", () => { } }); -// Restore previous uncompleted downloads - -// function restorePrevious() { -// if (!localStorage.getItem("itemList")) return; -// const items = JSON.parse(localStorage.getItem("itemList")); -// if (items) { -// console.log(items); -// items.forEach((item) => { -// const newItem = ` -//
-// -// thumbnail - -//
-//
${item.title}
-//
${item.type}
-// -// -//
Progress: ${ -// item.progress -// }%
-// -//
-//
-// `; -// getId("list").innerHTML += newItem; -// }); -// } -// } - -// restorePrevious() - // Time formatting function timeFormat(duration) { @@ -795,6 +757,9 @@ function download( let format_id; const randomId = "a" + Math.random().toFixed(10).toString().slice(2); + // Whether to close app + let quit = Boolean(getId("quitChecked").checked) + if (type === "video") { const videoValue = getId("videoFormatSelect").value; format_id = videoValue.split("|")[0]; @@ -812,23 +777,6 @@ function download( } console.log("video extension:", ext); - // localStorage.setItem("itemList", ""); - // let itemList = []; - // if (localStorage.getItem("itemList")) { - // itemList = JSON.parse(localStorage.getItem("itemList")); - // } - // const itemInfo = { - // id: randomId, - // format_id: format_id, - // title: title, - // url: url, - // ext: ext, - // type: type, - // thumbnail: thumbnail, - // }; - // itemList.push(itemInfo); - // localStorage.setItem("itemList", JSON.stringify(itemList)); - const newItem = `
@@ -923,8 +871,6 @@ function download( `"${path.join(downloadDir, filename + `.${ext}`)}"`, "--ffmpeg-location", ffmpeg, - // "--downloader", - // `'m3u8,dash:${ffmpeg}'`, subs1 || subs, subs2 || subLangs, "--no-playlist", @@ -955,8 +901,6 @@ function download( `"${path.join(downloadDir, filename + `.${extractExt}`)}"`, "--ffmpeg-location", ffmpeg, - // "--downloader", - // `'m3u8,dash:${ffmpeg}'`, "--no-playlist", cookieArg, browser, @@ -983,8 +927,6 @@ function download( `"${path.join(downloadDir, filename + `.${ext}`)}"`, "--ffmpeg-location", ffmpeg, - // "--downloader", - // `'m3u8:${ffmpeg}'`, subs1 || subs, subs2 || subLangs, "--no-playlist", @@ -1017,16 +959,6 @@ function download( randomId + "prog" ).innerHTML = ``; } - - // const items = JSON.parse(localStorage.getItem("itemList")); - // // Clearing item from localstorage - // for (let item of items) { - // if (item.id == randomId) { - // item.progress = progress.percent; - // break; - // } - // } - // localStorage.setItem("itemList", JSON.stringify(items)); }) .once("ytDlpEvent", (eventType, eventData) => { getId(randomId + "prog").textContent = i18n.__("Downloading..."); @@ -1036,16 +968,6 @@ function download( currentDownloads--; console.log("Closed with code " + code); if (code == 0) { - // const items = JSON.parse(localStorage.getItem("itemList")); - // // Clearing item from localstorage - // for (let item of items) { - // if (item.id == randomId) { - // items.splice(items.indexOf(item), 1); - // break; - // } - // } - // localStorage.setItem("itemList", JSON.stringify(items)); - // If extration is done if (type === "extract") { console.log( @@ -1068,6 +990,10 @@ function download( ); } } + if (quit) { + console.log("Quitting app") + quitApp() + } }) .once("error", (error) => { currentDownloads--; @@ -1079,6 +1005,10 @@ function download( }); } +function quitApp(){ + ipcRenderer.send("quit","quit") +} + // Removing item function fadeItem(id) { diff --git a/translations/en.json b/translations/en.json index 8a48fc0..d959a50 100644 --- a/translations/en.json +++ b/translations/en.json @@ -97,5 +97,6 @@ "Worst":"Worst", "Select Quality":"Select Quality", "Disable auto updates":"Disable auto updates", - "ultralow":"ultralow" + "ultralow":"ultralow", + "Close app when download finishes":"Close app when download finishes" }