diff --git a/downloader.js b/downloader.js index 0494c6b7..3aece6df 100644 --- a/downloader.js +++ b/downloader.js @@ -8,14 +8,17 @@ const { // Initializes the variable that holds the path to the specified download location let exportedFile let ready = true +let os const DOTNET_DOWNLOAD_URL = "https://github.com/SteamRE/DepotDownloader/releases/download/DepotDownloader_2.5.0/depotdownloader-2.5.0.zip" // the url to the depotdownloader zip const DOTNET_DIR = "depotdownloader" // folder where zip is extracted const DOTNET_ZIP_FILE = DOTNET_DOWNLOAD_URL.split("/").pop() // the file that is being downloaded. function submitForm() { + ///console.log(terminal[1][0]) // Check if the form is filled in and if dotnet is installed preDownloadCheck().then(async function () { + //console.log(terminal[1][0]) document.getElementById("dotnetwarning").hidden = true document.getElementById("emptywarning").hidden = true console.info("dotnet found in PATH") @@ -25,16 +28,30 @@ function submitForm() { // Download a prebuild DepotDownloader binary, so it doesn't have to be included in the source code await download(DOTNET_DOWNLOAD_URL) + console.log("downld") // Unzip the DepotDownloader binary await unzip(DOTNET_ZIP_FILE, DOTNET_DIR) + console.log("unzip") // Clean up the old files await removeFile(DOTNET_ZIP_FILE) + console.log("removeFile") // Run the final command - if (document.getElementById("osdropdown").selectedIndex !== 3) await console.debug("Command issued: " + createCommand()) - await runCommand(createCommand()) + + let terminal + if (document.getElementById("terminal-dropdown").selectedIndex !== 11) { + terminal = document.getElementById("terminal-dropdown").selectedIndex + } else terminal = "default" + if (document.getElementById("os-dropdown").selectedIndex !== 4) { + os = document.getElementById("os-dropdown").selectedIndex + } else os = "default" + if (document.getElementById("os-dropdown").selectedIndex !== 3) await console.debug("Command issued: " + createCommand(terminal,os)) + + await runCommand(createCommand(terminal,os)) + + console.log("runCommand") }).catch(function (error) { if (error === "noDotnet") { console.error("Dotnet not found in PATH") @@ -108,13 +125,16 @@ function checkPath() { */ function fillDefaultValues() { // [0]: Windows, [1]: macOS [2]: Linux [3]: manual - const os_dropdown = document.getElementById("osdropdown") + //const os_dropdown = document.getElementById("os-dropdown") if (process.platform.toString().includes("linux")) { - os_dropdown.selectedIndex = 2 + //os_dropdown.selectedIndex = 2 + document.getElementById("default-os").innerText = "Linux" } else if (process.platform.toString().includes("win")) { - os_dropdown.selectedIndex = 0 + //os_dropdown.selectedIndex = 0 + document.getElementById("default-os").innerText = "Windows" } else if (process.platform.toString().includes("darwin")) { - os_dropdown.selectedIndex = 1 + //os_dropdown.selectedIndex = 1 + document.getElementById("default-os").innerText = "macOS" } } @@ -126,17 +146,16 @@ function fillDefaultValues() { */ function validateChoice() { // [0]: Windows, [1]: macOS [2]: Linux [3]: manual - const os_dropdown = document.getElementById("osdropdown") - const terminal_dropdown = document.getElementById("osdropdown2") + const os_dropdown = document.getElementById("os-dropdown") + const terminal_dropdown = document.getElementById("terminal-dropdown") // if the choice = 2, enable the terminal selection dropdown. - if (os_dropdown.selectedIndex === 2) { + if (os_dropdown.selectedIndex === (2 || 3)) { terminal_dropdown.disabled = false - document.getElementById("osdropdown2label").classList.add("required") } else { terminal_dropdown.disabled = true terminal_dropdown.selectedIndex = 11 - document.getElementById("osdropdown2label").classList.remove("required") } + if (os_dropdown.selectedIndex === 4) if (process.platform.includes("linux")) terminal_dropdown.disabled = false } /** @@ -154,10 +173,10 @@ function toggleFormAccessibility(disable) { document.getElementById("appid").disabled = disable document.getElementById("depotid").disabled = disable document.getElementById("manifestid").disabled = disable - document.getElementById("osdropdown").disabled = disable + document.getElementById("os-dropdown").disabled = disable // if the OS dropdown value was 2 (Linux), don't disable the Terminal dropdown. - document.getElementById("osdropdown2").disabled = (((document.getElementById("osdropdown").selectedIndex !== 2))) + document.getElementById("terminal-dropdown").disabled = (((document.getElementById("os-dropdown").selectedIndex !== 2))) document.getElementById("pickpath").ariaDisabled = disable document.getElementById("pickpath").disabled = disable @@ -175,9 +194,10 @@ function setTheme(theme) { // main.js sends a ready message if the page is loaded in. This will be received here. ipcRenderer.on("ready", async () => { + if (!ready) return - let terminal_dropdown = document.getElementById("osdropdown2") + //let terminal_dropdown = document.getElementById("terminal-dropdown") await toggleFormAccessibility(true) // disables the form, while loading document.getElementById("loader").hidden = false @@ -191,12 +211,15 @@ ipcRenderer.on("ready", async () => { /* forceTerminals() returns two values: [1,2] 1: true/false. if true, there are terminals found. if false none are, or not on linux - 2: a list of availible terminals with their associated number in the terminal dropdown index. + 2: a list of available terminals with their associated number in the terminal dropdown index. */ if (terminals[0]) { console.log(`${terminals[1].length} terminals found in PATH.`) document.getElementById("terminals-found").innerText = terminals[1].length.toString() - terminal_dropdown.selectedIndex = terminals[1][0] // set the terminal dropdown to the first available terminal found. + document.getElementById("default-terminal").innerText = terminals[2][0] + //terminal_dropdown.selectedIndex = terminals[1][0] // set the terminal dropdown to the first available terminal found. + console.log(terminals[1][0]) + } else { console.log("No terminals found in PATH. Continuing with default values") // when no terminals are found on the system, or when linux is not used. } @@ -221,7 +244,7 @@ window.addEventListener("DOMContentLoaded", () => { document.getElementById("checkpath").addEventListener("click", () => { if (document.getElementById("checkpath").disabled === false) checkPath() }) - document.getElementById("osdropdown").addEventListener("input", validateChoice) + document.getElementById("os-dropdown").addEventListener("input", validateChoice) document.getElementById("downloadbtn").addEventListener("click", () => { if (document.getElementById("downloadbtn").disabled === false) submitForm() }) diff --git a/index.html b/index.html index 2007ca5a..74a0921a 100644 --- a/index.html +++ b/index.html @@ -97,7 +97,7 @@ -
+ @@ -227,7 +227,7 @@
- @@ -240,7 +240,27 @@ - found: none + + found: none +
default: none +
+
+ +
+
+
+ +
+
+
+ + default: none
diff --git a/style.css b/style.css index abdb553c..1d2b7531 100644 --- a/style.css +++ b/style.css @@ -14,7 +14,7 @@ /* The grey part */ .settings-surrounding { - display: block; + display: none; position: fixed; z-index: 1; left: 0; diff --git a/utils.js b/utils.js index 3fcfb0f8..fa8c4a2a 100644 --- a/utils.js +++ b/utils.js @@ -1,3 +1,4 @@ +var defaultTerminal = "" /** * Checks if all required fields are filled and if dotnet is installed in the system path. * It returns a promise that resolves to true if dotnet is installed and all required fields are filled, false otherwise. @@ -20,10 +21,10 @@ function preDownloadCheck() { if (isInvalid) unfilledFields++ } // If the selected OS is Linux, and the terminal selection is the default (11), error. - if (document.getElementById("osdropdown").selectedIndex === 2 && document.getElementById("osdropdown2").selectedIndex === 11) { - document.getElementById("osdropdown2label").classList.add("errored") - unfilledFields++ - } else document.getElementById("osdropdown2label").classList.remove("errored") + // if (document.getElementById("osdropdown").selectedIndex === 2 && document.getElementById("osdropdown2").selectedIndex === 11) { + // document.getElementById("osdropdown2label").classList.add("errored") + // unfilledFields++ + // } else document.getElementById("osdropdown2label").classList.remove("errored") if (unfilledFields > 0) { reject("emptyField") @@ -166,11 +167,25 @@ function unzip(file, target) { /** * Creates a command based on the operating system/terminal being selected and the form values * @returns {string} The final command to run + * TODO: create a builder, so the different terminals can be put in one variable and more can be added easily. */ -const createCommand = () => { - // TODO: create a builder, so the different terminals can be put in one variable and more can be added easily. +const createCommand = (terminal, os) => { + if (terminal === "default") { + terminal = defaultTerminal[0] + } else console.log("terminal is manually chosen.") + // Import path so \ can be put in a string const path = require("path") + if (os === "default") { + if (process.platform.toString().includes("win")) { + os = 0 + } else if (process.platform.toString().includes("linux")) { + os = 2 + } + } else console.log("os is manually chosen") + + console.log("terminal: " + terminal.toString()) + // The values inputted by the user in the form let username = document.forms["theform"]["username"].value @@ -178,8 +193,6 @@ const createCommand = () => { let appid = document.forms["theform"]["appid"].value let depotid = document.forms["theform"]["depotid"].value let manifestid = document.forms["theform"]["manifestid"].value - let os = document.getElementById("osdropdown").selectedIndex - let terminal = document.getElementById("osdropdown2").selectedIndex /* OS dropdown choices [0] - Windows @@ -217,6 +230,7 @@ const createCommand = () => { const finalPath = (exportedFile + path.sep + appid).replaceAll(" ", "\\ ") // The final command to run, returned by this function if (os === 0) { + console.log("win") return `start cmd.exe /k dotnet ${platformpath()}${path.sep}depotdownloader${path.sep}DepotDownloader.dll ${userpass} -app ${appid} -depot ${depotid} -manifest ${manifestid} -dir ${finalPath}/ -max-servers 50 -max-downloads 16` } else if (os === 1) { return `osascript -c 'tell application "Terminal" to do script 'dotnet ./depotdownloader/DepotDownloader.dll ${userpass} -app ${appid} -depot ${depotid} -manifest ${manifestid} -dir ${finalPath}/ -max-servers 50 -max-downloads 16'` @@ -308,17 +322,20 @@ const platformpath = () => { const forceTerminals = async () => { const commands = [["gnome-terminal", "--version", 0], ["konsole", "--version", 1], ["xfce4-terminal", "--version", 2], ["terminator", "--version", 3], ["terminology", "--version", 4], ["xterm", "-v", 5], ["kitty", "--version", 6], ["lxterminal", "--version", 7], ["tilix", "--version", 8], ["deepin-terminal", "--version", 9], ["cool-retro-term", "--version", 10]] let availableTerminals = [] + let availableNames = [] if (process.platform === "linux") { for (let i = 0; i < commands.length; i++) { await runCommand(`${commands[i][0]} ${commands[i][1]}`).then(() => { console.log(`Found ${commands[i][0]}`) availableTerminals.push(commands[i][2]) + availableNames.push(commands[i][0]) }).catch(() => { console.log(`${commands[i][0]} not found on system.`) }) } if (availableTerminals.length > 0) { - return [true, availableTerminals] + defaultTerminal = availableTerminals + return [true, availableTerminals, availableNames] //return false } else return false } else return false