Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

feat: add ConfirmCloseDialog and ShortcutsDialog components with localization support

Tonho2b76f945daf1
diff --git a/src/components/dialog/ConfirmCloseDialog.svelte b/src/components/dialog/ConfirmCloseDialog.svelte
new file mode 100644
index 00000000..2659a5b6
--- /dev/null
+++ b/src/components/dialog/ConfirmCloseDialog.svelte
@@ -0,0 +1,110 @@
+<script lang="ts">
+ import { onMount } from "svelte";
+ import { listen } from "@tauri-apps/api/event";
+ import { invoke } from "@tauri-apps/api/core";
+ import DialogContainer from "./DialogContainer.svelte";
+ import { t } from "$lib/i18n";
+
+ let isOpen = $state(false);
+ let activeCount = $state(0);
+
+ onMount(() => {
+ let unlisten: (() => void) | undefined;
+ listen<number>("exit-confirm-required", (event) => {
+ activeCount = typeof event.payload === "number" ? event.payload : 0;
+ isOpen = true;
+ }).then((fn) => {
+ unlisten = fn;
+ });
+ return () => {
+ unlisten?.();
+ };
+ });
+
+ function cancel() {
+ isOpen = false;
+ }
+
+ async function confirm() {
+ isOpen = false;
+ await invoke("force_exit_app");
+ }
+</script>
+
+<DialogContainer bind:isOpen titleId="confirm-close-title" onClose={cancel}>
+ <h3 id="confirm-close-title" class="dialog-title">
+ {$t("confirm_close.title")}
+ </h3>
+ <p class="dialog-body">
+ {$t("confirm_close.message", { values: { count: activeCount } })}
+ </p>
+ <div class="dialog-actions">
+ <button type="button" class="button button-secondary" onclick={cancel}>
+ {$t("confirm_close.cancel")}
+ </button>
+ <button type="button" class="button button-danger" onclick={confirm}>
+ {$t("confirm_close.confirm")}
+ </button>
+ </div>
+</DialogContainer>
+
+<style>
+ .dialog-title {
+ margin: 0;
+ padding: calc(var(--padding) * 1.25) calc(var(--padding) * 1.5) calc(var(--padding) * 0.75);
+ font-size: 15px;
+ font-weight: 600;
+ color: var(--secondary);
+ }
+
+ .dialog-body {
+ margin: 0;
+ padding: 0 calc(var(--padding) * 1.5) calc(var(--padding) * 1.25);
+ font-size: 13px;
+ line-height: 1.5;
+ color: var(--secondary);
+ opacity: 0.85;
+ }
+
+ .dialog-actions {
+ display: flex;
+ justify-content: flex-end;
+ gap: calc(var(--padding) * 0.5);
+ padding: calc(var(--padding) * 0.75) calc(var(--padding) * 1.5) calc(var(--padding) * 1.25);
+ border-top: 1px solid var(--content-border);
+ }
+
+ .button {
+ padding: 8px 16px;
+ font-size: 12.5px;
+ font-weight: 500;
+ border-radius: var(--border-radius);
+ border: none;
+ cursor: pointer;
+ transition: background 0.15s, color 0.15s;
+ }
+
+ .button-secondary {
+ background: transparent;
+ color: var(--secondary);
+ border: 1px solid var(--content-border);
+ }
+
+ .button-secondary:hover {
+ background: var(--sidebar-highlight);
+ }
+
+ .button-danger {
+ background: var(--red, #ed2236);
+ color: var(--on-accent, #fff);
+ }
+
+ .button-danger:hover {
+ filter: brightness(1.08);
+ }
+
+ .button:focus-visible {
+ outline: var(--focus-ring);
+ outline-offset: var(--focus-ring-offset);
+ }
+</style>
diff --git a/src/components/dialog/ShortcutsDialog.svelte b/src/components/dialog/ShortcutsDialog.svelte
new file mode 100644
index 00000000..e16ae010
--- /dev/null
+++ b/src/components/dialog/ShortcutsDialog.svelte
@@ -0,0 +1,208 @@
+<script lang="ts">
+ import { onMount } from "svelte";
+ import { t } from "$lib/i18n";
+ import { getSettings } from "$lib/stores/settings-store.svelte";
+ import DialogContainer from "./DialogContainer.svelte";
+
+ let isOpen = $state(false);
+
+ const settings = $derived(getSettings());
+ const globalHotkey = $derived(settings?.download.hotkey || "Ctrl+Shift+V");
+
+ type Shortcut = { keysKey?: string; keys?: string; labelKey: string };
+ type Section = { titleKey: string; items: Shortcut[] };
+
+ const sections = $derived<Section[]>([
+ {
+ titleKey: "shortcuts.section_application",
+ items: [
+ { keys: globalHotkey, labelKey: "shortcuts.paste_url" },
+ { keys: "Ctrl+?", labelKey: "shortcuts.show_shortcuts" },
+ { keys: "Ctrl+,", labelKey: "shortcuts.open_settings" },
+ { keys: "Ctrl+F", labelKey: "shortcuts.search_settings" },
+ ],
+ },
+ {
+ titleKey: "shortcuts.section_downloads",
+ items: [
+ { keys: "Enter", labelKey: "shortcuts.start_download" },
+ { keys: "Esc", labelKey: "shortcuts.cancel_dialog" },
+ ],
+ },
+ {
+ titleKey: "shortcuts.section_navigation",
+ items: [
+ { keys: "Ctrl+1", labelKey: "shortcuts.nav_home" },
+ { keys: "Ctrl+2", labelKey: "shortcuts.nav_downloads" },
+ ],
+ },
+ ]);
+
+ function open() {
+ isOpen = true;
+ }
+
+ function close() {
+ isOpen = false;
+ }
+
+ function onKey(e: KeyboardEvent) {
+ const target = e.target as HTMLElement | null;
+ const tag = target?.tagName?.toLowerCase();
+ const isEditable =
+ tag === "input" ||
+ tag === "textarea" ||
+ tag === "select" ||
+ target?.isContentEditable;
+ if (isEditable) return;
+
+ if (e.ctrlKey && !e.altKey && !e.metaKey && (e.key === "?" || e.key === "/")) {
+ e.preventDefault();
+ isOpen ? close() : open();
+ return;
+ }
+ if (!e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey && e.key === "?") {
+ e.preventDefault();
+ isOpen ? close() : open();
+ }
+ }
+
+ onMount(() => {
+ window.addEventListener("keydown", onKey);
+ return () => window.removeEventListener("keydown", onKey);
+ });
+
+ function keyTokens(combo: string): string[] {
+ return combo.split("+").map((k) => k.trim()).filter(Boolean);
+ }
+</script>
+
+<DialogContainer bind:isOpen onClose={close} titleId="shortcuts-dialog-title">
+ <div class="shortcuts-header">
+ <h2 id="shortcuts-dialog-title">{$t("shortcuts.title")}</h2>
+ <button class="dialog-close" onclick={close} aria-label={$t("common.close")}>
+ <svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+ <path d="M18 6L6 18M6 6l12 12" />
+ </svg>
+ </button>
+ </div>
+
+ <div class="shortcuts-body">
+ {#each sections as section}
+ <section class="shortcut-section">
+ <h3>{$t(section.titleKey)}</h3>
+ <ul>
+ {#each section.items as s}
+ <li>
+ <span class="shortcut-label">{$t(s.labelKey)}</span>
+ <span class="shortcut-keys">
+ {#each keyTokens(s.keys ?? "") as token, i}
+ {#if i > 0}<span class="plus">+</span>{/if}
+ <kbd>{token}</kbd>
+ {/each}
+ </span>
+ </li>
+ {/each}
+ </ul>
+ </section>
+ {/each}
+ </div>
+</DialogContainer>
+
+<style>
+ .shortcuts-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 16px 20px 8px;
+ }
+
+ .shortcuts-header h2 {
+ margin: 0;
+ font-size: 16px;
+ font-weight: 600;
+ color: var(--foreground);
+ }
+
+ .dialog-close {
+ background: transparent;
+ border: none;
+ color: var(--foreground-secondary);
+ padding: 4px;
+ cursor: pointer;
+ border-radius: var(--border-radius);
+ }
+
+ .dialog-close:hover {
+ background: var(--secondary);
+ color: var(--foreground);
+ }
+
+ .shortcuts-body {
+ padding: 8px 20px 20px;
+ overflow-y: auto;
+ max-height: 60vh;
+ }
+
+ .shortcut-section + .shortcut-section {
+ margin-top: 16px;
+ }
+
+ .shortcut-section h3 {
+ margin: 0 0 8px 0;
+ font-size: 12px;
+ font-weight: 600;
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+ color: var(--foreground-secondary);
+ }
+
+ ul {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ }
+
+ li {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 6px 8px;
+ border-radius: var(--border-radius);
+ background: var(--secondary);
+ }
+
+ .shortcut-label {
+ font-size: 13px;
+ color: var(--foreground);
+ }
+
+ .shortcut-keys {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ }
+
+ kbd {
+ display: inline-block;
+ min-width: 20px;
+ padding: 2px 6px;
+ border: 1px solid var(--border);
+ border-bottom-width: 2px;
+ border-radius: 4px;
+ background: var(--background);
+ color: var(--foreground);
+ font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
+ font-size: 11px;
+ line-height: 1.2;
+ text-align: center;
+ }
+
+ .plus {
+ color: var(--foreground-secondary);
+ font-size: 11px;
+ }
+</style>
diff --git a/src/components/download/DownloadLog.svelte b/src/components/download/DownloadLog.svelte
new file mode 100644
index 00000000..470ece71
--- /dev/null
+++ b/src/components/download/DownloadLog.svelte
@@ -0,0 +1,196 @@
+<script lang="ts">
+ import { invoke } from "@tauri-apps/api/core";
+ import { listen, type UnlistenFn } from "@tauri-apps/api/event";
+ import { t } from "$lib/i18n";
+ import { showToast } from "$lib/stores/toast-store.svelte";
+
+ type Props = { id: number };
+ let { id }: Props = $props();
+
+ let expanded = $state(false);
+ let lines = $state<string[]>([]);
+ let loading = $state(false);
+ let preEl: HTMLPreElement | null = $state(null);
+ let atBottom = $state(true);
+ let unlisten: UnlistenFn | null = null;
+
+ async function refresh() {
+ try {
+ const next = await invoke<string[]>("get_download_log", { downloadId: id });
+ lines = next;
+ } catch (_) {
+ lines = [];
+ }
+ }
+
+ async function toggle() {
+ expanded = !expanded;
+ if (expanded) {
+ loading = true;
+ await refresh();
+ loading = false;
+ atBottom = true;
+ unlisten = await listen<{ id: number }>("download-log-update", (event) => {
+ if (event.payload && event.payload.id === id) {
+ refresh();
+ }
+ });
+ } else if (unlisten) {
+ unlisten();
+ unlisten = null;
+ }
+ }
+
+ $effect(() => {
+ if (expanded && atBottom && preEl && lines.length) {
+ queueMicrotask(() => {
+ if (preEl) preEl.scrollTop = preEl.scrollHeight;
+ });
+ }
+ });
+
+ function onScroll() {
+ if (!preEl) return;
+ const threshold = 12;
+ atBottom = preEl.scrollHeight - preEl.scrollTop - preEl.clientHeight <= threshold;
+ }
+
+ async function copyLog() {
+ try {
+ await navigator.clipboard.writeText(lines.join("\n"));
+ showToast("success", $t("downloads.log.copied"));
+ } catch (_) {
+ showToast("error", $t("downloads.log.copy_failed"));
+ }
+ }
+
+ $effect(() => {
+ return () => {
+ if (unlisten) {
+ unlisten();
+ unlisten = null;
+ }
+ };
+ });
+</script>
+
+<div class="download-log">
+ <button
+ type="button"
+ class="log-toggle"
+ onclick={toggle}
+ aria-expanded={expanded}
+ title={expanded ? $t("downloads.log.hide") : $t("downloads.log.show")}
+ >
+ <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+ <path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z" />
+ <polyline points="14 2 14 8 20 8" />
+ <line x1="8" y1="13" x2="16" y2="13" />
+ <line x1="8" y1="17" x2="14" y2="17" />
+ </svg>
+ <span>{expanded ? $t("downloads.log.hide") : $t("downloads.log.show")}</span>
+ </button>
+
+ {#if expanded}
+ <div class="log-panel">
+ <div class="log-header">
+ <span class="log-count">
+ {lines.length}{loading ? "…" : ""}
+ </span>
+ <button type="button" class="log-copy" onclick={copyLog} disabled={!lines.length}>
+ {$t("downloads.log.copy")}
+ </button>
+ </div>
+ {#if !lines.length && !loading}
+ <div class="log-empty">{$t("downloads.log.empty")}</div>
+ {:else}
+ <pre bind:this={preEl} onscroll={onScroll}>{lines.join("\n")}</pre>
+ {/if}
+ </div>
+ {/if}
+</div>
+
+<style>
+ .download-log {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ margin-top: 6px;
+ }
+
+ .log-toggle {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ padding: 4px 8px;
+ background: transparent;
+ border: 1px solid var(--border);
+ border-radius: var(--border-radius);
+ color: var(--foreground-secondary);
+ font-size: 11px;
+ cursor: pointer;
+ align-self: flex-start;
+ transition: background-color 0.12s, color 0.12s, border-color 0.12s;
+ }
+
+ .log-toggle:hover {
+ background: var(--secondary);
+ color: var(--foreground);
+ }
+
+ .log-panel {
+ border: 1px solid var(--border);
+ border-radius: var(--border-radius);
+ background: var(--secondary);
+ overflow: hidden;
+ }
+
+ .log-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 6px 8px;
+ border-bottom: 1px solid var(--border);
+ font-size: 11px;
+ color: var(--foreground-secondary);
+ }
+
+ .log-copy {
+ padding: 2px 8px;
+ border: 1px solid var(--border);
+ background: transparent;
+ border-radius: var(--border-radius);
+ color: var(--foreground);
+ font-size: 11px;
+ cursor: pointer;
+ }
+
+ .log-copy:hover:not(:disabled) {
+ background: var(--background);
+ }
+
+ .log-copy:disabled {
+ opacity: 0.5;
+ cursor: not-allowed;
+ }
+
+ pre {
+ margin: 0;
+ padding: 8px;
+ max-height: 220px;
+ overflow-y: auto;
+ font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
+ font-size: 11px;
+ color: var(--foreground);
+ white-space: pre-wrap;
+ word-break: break-all;
+ background: var(--background);
+ }
+
+ .log-empty {
+ padding: 12px;
+ text-align: center;
+ font-size: 11px;
+ color: var(--foreground-secondary);
+ }
+</style>
diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.json
index 705d80f2..d29e0c5a 100644
--- a/src/lib/i18n/en.json
+++ b/src/lib/i18n/en.json
@@ -5,6 +5,20 @@
"cancel": "Keep running",
"confirm": "Close anyway"
},
+ "shortcuts": {
+ "title": "Keyboard shortcuts",
+ "section_application": "Application",
+ "section_downloads": "Downloads",
+ "section_navigation": "Navigation",
+ "paste_url": "Paste URL and download",
+ "show_shortcuts": "Show this dialog",
+ "open_settings": "Open settings",
+ "search_settings": "Search settings",
+ "start_download": "Start download",
+ "cancel_dialog": "Close dialog or cancel",
+ "nav_home": "Go to Home",
+ "nav_downloads": "Go to Downloads"
+ },
"nav": {
"home": "Home",
"downloads": "Downloads",
diff --git a/src/lib/i18n/pt.json b/src/lib/i18n/pt.json
index a982d404..13456cd0 100644
--- a/src/lib/i18n/pt.json
+++ b/src/lib/i18n/pt.json
@@ -5,6 +5,20 @@
"cancel": "Manter rodando",
"confirm": "Fechar mesmo assim"
},
+ "shortcuts": {
+ "title": "Atalhos de teclado",
+ "section_application": "Aplicativo",
+ "section_downloads": "Downloads",
+ "section_navigation": "Navegação",
+ "paste_url": "Colar URL e baixar",
+ "show_shortcuts": "Mostrar este diálogo",
+ "open_settings": "Abrir configurações",
+ "search_settings": "Buscar configurações",
+ "start_download": "Iniciar download",
+ "cancel_dialog": "Fechar diálogo ou cancelar",
+ "nav_home": "Ir para Início",
+ "nav_downloads": "Ir para Downloads"
+ },
"nav": {
"home": "Início",
"downloads": "Downloads",
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 20d7ff5b..a2b98784 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -17,6 +17,7 @@
import { initChangelog } from "$lib/stores/changelog-store.svelte";
import ChangelogDialog from "$components/dialog/ChangelogDialog.svelte";
import ConfirmCloseDialog from "$components/dialog/ConfirmCloseDialog.svelte";
+ import ShortcutsDialog from "$components/dialog/ShortcutsDialog.svelte";
import OnboardingWizard from "$components/onboarding/OnboardingWizard.svelte";
import { needsOnboarding } from "$lib/stores/onboarding-store.svelte";
import { isYtdlpAvailable, isDepsChecked, refreshYtdlpStatus } from "$lib/stores/dependency-store.svelte";
@@ -241,6 +242,7 @@
<DebugPanel />
<ChangelogDialog />
<ConfirmCloseDialog />
+<ShortcutsDialog />
{#if showOnboarding}
<OnboardingWizard />
{/if}