ui: Day 3 — global toast system + first error-toast wiring on DictationPage
THE PROBLEM (Codex review + architecture-review.md §1, §14):
Multiple critical paths discard errors silently — `let _ = insert_transcript(...)`,
`.catch(() => {})`, inline `error = ...` state that not every page surfaces. ND
users in particular need explicit feedback when something fails; silent
failure is worse than no feature.
SHIPPED:
src/lib/stores/toasts.svelte.js (new):
- Minimal in-house toast store (~80 lines, no svelte-french-toast dep)
- Severity → palette: info/success → moss, warn → signal, error → ember
- Auto-dismiss durations per severity (success 3s, info 4s, warn 6s,
error sticky)
- `invokeWithToast(invoke, command, args, errorTitle?)` helper wraps a
Tauri invoke and toasts on failure while still throwing for callers
that need to handle the error themselves
src/lib/components/ToastViewport.svelte (new):
- Reads from the toasts store
- Bottom-right stack, max-width clamp on small screens
- aria-live=polite + role=alert on error toasts (screen-reader friendly)
- Slide-in animation honours `html.reduce-motion` for the existing
preferences toggle
- Severity left-border in brand colours via existing CSS variables
src/routes/+layout.svelte:
- Mounts <ToastViewport /> once at the app root so toasts work from any
page or window
src/lib/pages/DictationPage.svelte:
- First error-toast wiring: failures starting recording now show a
sticky toast in addition to the inline `error` panel
- Replaces a previously easy-to-miss failure-mode
NEXT (Day 4 batch):
- Wire toasts into FilesPage, HistoryPage, SettingsPage, ModelDownloader
(all currently swallow errors)
- Add `add_transcript`, `list_transcripts`, `update_transcript` (closes the
long-standing TODO Codex flagged), `delete_transcript` Tauri commands
wrapping the existing storage layer
- Switch addToHistory to dual-write (localStorage + SQLite) so the
canonical store catches up with the actual transcript flow
- FTS5 transcripts_fts virtual table + search command
- Wrap multi-row writes (decompose_and_store) in DB transactions
This commit is contained in:
@@ -5,14 +5,17 @@
|
||||
import Sidebar from "$lib/Sidebar.svelte";
|
||||
import TaskSidebar from "$lib/components/TaskSidebar.svelte";
|
||||
import Titlebar from "$lib/components/Titlebar.svelte";
|
||||
import ToastViewport from "$lib/components/ToastViewport.svelte";
|
||||
import { page, settings, saveSettings } from "$lib/stores/page.svelte.js";
|
||||
import { getPreferences, updatePreferences } from "$lib/stores/preferences.svelte.js";
|
||||
import { hasTauriRuntime } from "$lib/utils/runtime.js";
|
||||
|
||||
import { page as sveltePage } from "$app/stores";
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
const prefs = getPreferences();
|
||||
const tauriRuntimeAvailable = hasTauriRuntime();
|
||||
|
||||
|
||||
// Detect secondary windows (float, viewer) — they use +layout@.svelte
|
||||
@@ -49,6 +52,10 @@
|
||||
let hotkeyBackend = $state("unknown"); // "evdev" | "tauri" | "unavailable"
|
||||
|
||||
async function initHotkeyBackend() {
|
||||
if (!tauriRuntimeAvailable) {
|
||||
hotkeyBackend = "unavailable";
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const isWayland = await invoke("is_wayland_session");
|
||||
if (isWayland) {
|
||||
@@ -73,6 +80,7 @@
|
||||
}
|
||||
|
||||
async function registerGlobalHotkey(hotkey) {
|
||||
if (!tauriRuntimeAvailable) return;
|
||||
if (hotkeyBackend === "unknown") return; // not yet initialised
|
||||
|
||||
try {
|
||||
@@ -106,6 +114,7 @@
|
||||
// Listen for evdev hotkey events from the Rust backend
|
||||
let unlistenEvdev = null;
|
||||
async function setupEvdevListener() {
|
||||
if (!tauriRuntimeAvailable) return;
|
||||
const { listen } = await import("@tauri-apps/api/event");
|
||||
unlistenEvdev = await listen("kon:hotkey-pressed", () => {
|
||||
if (page.current !== "dictation") page.current = "dictation";
|
||||
@@ -161,6 +170,11 @@
|
||||
handleResize();
|
||||
window.addEventListener("resize", handleResize);
|
||||
|
||||
if (!tauriRuntimeAvailable) {
|
||||
hotkeyBackend = "unavailable";
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect and initialise the correct hotkey backend
|
||||
await initHotkeyBackend();
|
||||
|
||||
@@ -177,6 +191,9 @@
|
||||
|
||||
onDestroy(() => {
|
||||
window.removeEventListener("resize", handleResize);
|
||||
if (!tauriRuntimeAvailable) {
|
||||
return;
|
||||
}
|
||||
if (hotkeyBackend === "evdev") {
|
||||
invoke("stop_evdev_hotkey").catch(() => {});
|
||||
} else if (hotkeyBackend === "tauri" && registeredHotkey) {
|
||||
@@ -220,3 +237,8 @@
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Global toast viewport. Mounted once at the app root so any component
|
||||
can call toasts.error(...), toasts.success(...) etc and have it render
|
||||
in the bottom-right of the viewport. (Day 3 of the upgrade plan) -->
|
||||
<ToastViewport />
|
||||
|
||||
Reference in New Issue
Block a user