diff --git a/src-tauri/src/terminal.rs b/src-tauri/src/terminal.rs index 123a22fb..952eb22a 100644 --- a/src-tauri/src/terminal.rs +++ b/src-tauri/src/terminal.rs @@ -5,6 +5,8 @@ use tauri::State; use crate::AppState; use crate::steam::SteamDownload; +/* Parts of this file are derived from https://github.com/cablehead/tauri-xtermjs-nushell/blob/0bdd4a27ee2874de12e99bccd6c91d6ec5d28fbc/src-tauri/src/main.rs */ + #[tauri::command] pub async fn async_write_to_pty(data: &str, state: State<'_, AppState>) -> Result<(), ()> { write!(state.writer.lock().await, "{}", data).map_err(|_| ()) @@ -18,7 +20,7 @@ pub async fn async_read_from_pty(state: State<'_, AppState>) -> Result 0 { + if !data.is_empty() { std::str::from_utf8(data) .map(|v| Some(v.to_string())) .map_err(|_| ())? @@ -64,14 +66,14 @@ pub fn create_depotdownloader_command(steam_download: &SteamDownload, cwd: &Path command.cwd(cwd); if !steam_download.is_anonymous() { - command.args(["-username", &*steam_download.username().clone().unwrap()]); - command.args(["-password", &*steam_download.password().clone().unwrap()]); + command.args(["-username", &steam_download.username().clone().unwrap()]); + command.args(["-password", &steam_download.password().clone().unwrap()]); } - command.args(["-app", &*steam_download.app_id()]); - command.args(["-depot", &*steam_download.depot_id()]); - command.args(["-manifest", &*steam_download.manifest_id()]); - command.args(["-dir", &*steam_download.output_path()]); + command.args(["-app", steam_download.app_id()]); + command.args(["-depot", steam_download.depot_id()]); + command.args(["-manifest", steam_download.manifest_id()]); + command.args(["-dir", &steam_download.output_path()]); command } diff --git a/src/index.html b/src/index.html index 015549ef..de799bf7 100644 --- a/src/index.html +++ b/src/index.html @@ -17,7 +17,7 @@
Steam Depot Downloader
-
+
@@ -159,10 +159,15 @@
-
+
- Download output +
+ Download output + +
diff --git a/src/ts/main.ts b/src/ts/main.ts index 3de34dd7..395c3851 100644 --- a/src/ts/main.ts +++ b/src/ts/main.ts @@ -7,8 +7,10 @@ import {Terminal} from "@xterm/xterm"; import { FitAddon } from "@xterm/addon-fit"; import { listen } from "@tauri-apps/api/event"; -function setLoader(state: boolean) { - $("#busy").prop("hidden", !state); +/* Parts of this file are derived from https://github.com/cablehead/tauri-xtermjs-nushell/blob/0bdd4a27ee2874de12e99bccd6c91d6ec5d28fbc/src/main.ts */ + +function blockTerminalClearButton(state: boolean) { + $("#clear-terminal").prop( "disabled", state ); } @@ -16,8 +18,9 @@ function setLoadingState(state: boolean) { $("#busy").prop("hidden", !state); // loop through all buttons and input fields and disable them - for (const element of document.querySelectorAll("button, input")) { + for (const element of document.querySelectorAll("button, input, div[role='button']")) { if (element.closest("#settings-content")) continue; + if (element.closest("#right-side")) continue; (element as any).disabled = state; } @@ -49,7 +52,7 @@ const invalidFields = () => { return invalidFields; }; -const registerTerminal = async (terminalElement: HTMLElement) => { +const registerTerminal: (terminalElement: HTMLElement) => Promise = async (terminalElement: HTMLElement) => { const fitAddon = new FitAddon(); const term = new Terminal({ fontSize: 10, @@ -57,7 +60,7 @@ const registerTerminal = async (terminalElement: HTMLElement) => { rows: 100, cols: 100, theme: { - background: "rgb(47, 47, 47)", + background: "rgb(33, 33, 33)", }, }); term.loadAddon(fitAddon); @@ -97,11 +100,13 @@ const registerTerminal = async (terminalElement: HTMLElement) => { } window.requestAnimationFrame(readFromPty); + + return term; }; $(async () => { - await registerTerminal($("#xtermjs")[0]); + let terminal = await registerTerminal($("#xtermjs")[0]); let downloadDirectory: string | null; // Startup logic @@ -109,6 +114,9 @@ $(async () => { await invoke("preload_vectum"); setLoadingState(false); + $("#clear-terminal").on("click", async () => { + terminal.reset() + }) $("#pickpath").on("click", async () => { // Open a dialog @@ -196,6 +204,9 @@ $(async () => { setLoadingState(true); await invoke("start_download", {steamDownload: steamDownload}); + + // Block clear terminal button (to avoid clearing ongoing download logs) + blockTerminalClearButton(true); console.log("Send frontend data over to backend. Ready for next download."); }); @@ -230,4 +241,5 @@ $(async () => { listen("command-exited", () => { setLoadingState(false); + blockTerminalClearButton(false); }); \ No newline at end of file