The full-screen backdrop (fixed inset-0 z-40) was eating all pointer events, making the app unusable when the task sidebar was open. Replace with a backdrop that only covers the content area (not titlebar) and sits beside the sidebar rather than wrapping it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
232 lines
7.5 KiB
Svelte
232 lines
7.5 KiB
Svelte
<script>
|
|
import "../app.css";
|
|
import { onMount, onDestroy } from "svelte";
|
|
import { invoke } from "@tauri-apps/api/core";
|
|
import Sidebar from "$lib/Sidebar.svelte";
|
|
import TaskSidebar from "$lib/components/TaskSidebar.svelte";
|
|
import Titlebar from "$lib/components/Titlebar.svelte";
|
|
import { page, settings, saveSettings } from "$lib/stores/page.svelte.js";
|
|
import { getPreferences, updatePreferences } from "$lib/stores/preferences.svelte.js";
|
|
|
|
import { page as sveltePage } from "$app/stores";
|
|
|
|
let { children } = $props();
|
|
|
|
const prefs = getPreferences();
|
|
|
|
// Detect secondary windows (float, viewer) — they use +layout@.svelte
|
|
// but as a fallback, hide chrome if the URL matches
|
|
let isSecondaryWindow = $derived(
|
|
$sveltePage.url.pathname.startsWith("/float") ||
|
|
$sveltePage.url.pathname.startsWith("/viewer")
|
|
);
|
|
|
|
// Recording indicator dot (follows mouse)
|
|
let mouseX = $state(0);
|
|
let mouseY = $state(0);
|
|
|
|
function handleMouseMove(e) {
|
|
mouseX = e.clientX;
|
|
mouseY = e.clientY;
|
|
}
|
|
|
|
// Theme — migrate from old class-based to new data-attribute system
|
|
// The preferences store handles DOM application via data-theme attribute
|
|
$effect(() => {
|
|
// Sync legacy settings.theme → preferences store
|
|
const legacyTheme = settings.theme;
|
|
const mapped = legacyTheme === "Light" ? "light" : legacyTheme === "Dark" ? "dark" : "system";
|
|
if (prefs.theme !== mapped) {
|
|
updatePreferences({ theme: mapped });
|
|
}
|
|
});
|
|
|
|
// Global hotkey registration — dual backend
|
|
// Wayland: evdev via kon-hotkey crate (works without display server)
|
|
// X11/macOS/Windows: tauri-plugin-global-shortcut (native)
|
|
let registeredHotkey = null;
|
|
let hotkeyBackend = $state("unknown"); // "evdev" | "tauri" | "unavailable"
|
|
|
|
async function initHotkeyBackend() {
|
|
try {
|
|
const isWayland = await invoke("is_wayland_session");
|
|
if (isWayland) {
|
|
// Try evdev backend first (Wayland-compatible)
|
|
try {
|
|
await invoke("check_hotkey_access");
|
|
hotkeyBackend = "evdev";
|
|
console.log("Hotkey backend: evdev (Wayland)");
|
|
} catch (err) {
|
|
console.warn("evdev hotkey access denied:", err);
|
|
console.warn("Add your user to the 'input' group for global hotkeys on Wayland");
|
|
hotkeyBackend = "unavailable";
|
|
}
|
|
} else {
|
|
hotkeyBackend = "tauri";
|
|
console.log("Hotkey backend: tauri-plugin-global-shortcut (X11)");
|
|
}
|
|
} catch {
|
|
// Fallback to tauri plugin if detection fails
|
|
hotkeyBackend = "tauri";
|
|
}
|
|
}
|
|
|
|
async function registerGlobalHotkey(hotkey) {
|
|
if (hotkeyBackend === "unknown") return; // not yet initialised
|
|
|
|
try {
|
|
if (hotkeyBackend === "evdev") {
|
|
// evdev backend: start or update the Rust-side listener
|
|
if (registeredHotkey) {
|
|
await invoke("update_evdev_hotkey", { hotkey });
|
|
} else {
|
|
await invoke("start_evdev_hotkey", { hotkey });
|
|
}
|
|
registeredHotkey = hotkey;
|
|
} else if (hotkeyBackend === "tauri") {
|
|
// Tauri plugin backend (X11/macOS/Windows)
|
|
const mod = await import("@tauri-apps/plugin-global-shortcut");
|
|
if (registeredHotkey) {
|
|
await mod.unregister(registeredHotkey).catch(() => {});
|
|
}
|
|
await mod.register(hotkey, () => {
|
|
if (page.current !== "dictation") page.current = "dictation";
|
|
requestAnimationFrame(() => {
|
|
window.dispatchEvent(new CustomEvent("kon:toggle-recording"));
|
|
});
|
|
});
|
|
registeredHotkey = hotkey;
|
|
}
|
|
} catch (err) {
|
|
console.error("Hotkey registration failed:", err);
|
|
}
|
|
}
|
|
|
|
// Listen for evdev hotkey events from the Rust backend
|
|
let unlistenEvdev = null;
|
|
async function setupEvdevListener() {
|
|
const { listen } = await import("@tauri-apps/api/event");
|
|
unlistenEvdev = await listen("kon:hotkey-pressed", () => {
|
|
if (page.current !== "dictation") page.current = "dictation";
|
|
requestAnimationFrame(() => {
|
|
window.dispatchEvent(new CustomEvent("kon:toggle-recording"));
|
|
});
|
|
});
|
|
}
|
|
|
|
$effect(() => {
|
|
if (hotkeyBackend === "evdev" && !unlistenEvdev) {
|
|
setupEvdevListener();
|
|
}
|
|
});
|
|
|
|
$effect(() => {
|
|
if (hotkeyBackend !== "unknown") {
|
|
registerGlobalHotkey(settings.globalHotkey);
|
|
}
|
|
});
|
|
|
|
// Apply font size setting as CSS variable (legacy — kept for backwards compat)
|
|
$effect(() => {
|
|
document.documentElement.style.setProperty("--font-size-transcript", `${settings.fontSize}px`);
|
|
});
|
|
|
|
// Check whether the keydown originates from a text input (avoid triggering while typing)
|
|
function isInputFocused(e) {
|
|
const tag = e.target?.tagName;
|
|
return tag === "INPUT" || tag === "TEXTAREA" || e.target?.isContentEditable;
|
|
}
|
|
|
|
function handleKeydown(e) {
|
|
if (e.key === "Escape" && page.taskSidebarOpen) {
|
|
page.taskSidebarOpen = false;
|
|
return;
|
|
}
|
|
if (e.key === "[" && !isInputFocused(e)) {
|
|
settings.sidebarCollapsed = !settings.sidebarCollapsed;
|
|
saveSettings();
|
|
}
|
|
}
|
|
|
|
function handleResize() {
|
|
if (window.innerWidth < 900 && !settings.sidebarCollapsed) {
|
|
settings.sidebarCollapsed = true;
|
|
saveSettings();
|
|
}
|
|
}
|
|
|
|
onMount(async () => {
|
|
// Auto-collapse if window is already narrow on first load
|
|
handleResize();
|
|
window.addEventListener("resize", handleResize);
|
|
|
|
// Detect and initialise the correct hotkey backend
|
|
await initHotkeyBackend();
|
|
|
|
try {
|
|
const whisper = await invoke("list_models");
|
|
const parakeet = await invoke("list_parakeet_models");
|
|
if (whisper.length === 0 && parakeet.length === 0) {
|
|
page.current = "first-run";
|
|
}
|
|
} catch {
|
|
// If commands fail, skip first-run check
|
|
}
|
|
});
|
|
|
|
onDestroy(() => {
|
|
window.removeEventListener("resize", handleResize);
|
|
if (hotkeyBackend === "evdev") {
|
|
invoke("stop_evdev_hotkey").catch(() => {});
|
|
} else if (hotkeyBackend === "tauri" && registeredHotkey) {
|
|
import("@tauri-apps/plugin-global-shortcut")
|
|
.then((mod) => mod.unregister(registeredHotkey))
|
|
.catch(() => {});
|
|
}
|
|
if (unlistenEvdev) {
|
|
unlistenEvdev();
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<svelte:window onmousemove={handleMouseMove} onkeydown={handleKeydown} />
|
|
|
|
{#if page.recording}
|
|
<div
|
|
class="fixed w-3 h-3 rounded-full bg-danger animate-pulse-soft pointer-events-none"
|
|
style="left: {mouseX + 18}px; top: {mouseY + 18}px; z-index: 100;"
|
|
></div>
|
|
{/if}
|
|
|
|
{#if isSecondaryWindow}
|
|
<!-- Secondary windows (float, viewer) render children only — no shell chrome -->
|
|
{@render children()}
|
|
{:else}
|
|
<div class="flex flex-col h-screen w-screen overflow-hidden grain">
|
|
<Titlebar />
|
|
<div class="flex flex-1 min-h-0 relative">
|
|
{#if page.current !== "first-run"}
|
|
<Sidebar />
|
|
{/if}
|
|
<div class="flex-1 overflow-hidden bg-bg">
|
|
{@render children()}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Task sidebar as overlay — doesn't shrink main content -->
|
|
{#if page.taskSidebarOpen && page.current !== "first-run" && !isSecondaryWindow}
|
|
<!-- Backdrop — below titlebar only, closes sidebar on click -->
|
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
<div
|
|
class="fixed top-[36px] left-0 right-[280px] bottom-0 z-40"
|
|
onclick={() => { page.taskSidebarOpen = false; }}
|
|
></div>
|
|
<!-- Sidebar panel -->
|
|
<div class="fixed top-[36px] right-0 bottom-0 w-[280px] z-50 shadow-xl">
|
|
<TaskSidebar />
|
|
</div>
|
|
{/if}
|
|
{/if}
|