keep the recording frame frameless

This commit is contained in:
2026-10-16 21:17:00 +03:00
parent 3298d2c9e0
commit 271613f6f9
10 changed files with 381 additions and 524 deletions
+148 -192
View File
@@ -3,214 +3,170 @@
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"
import { listen, emit } from "@tauri-apps/api/event"
import { invoke } from "@tauri-apps/api/core"
import { IconAppWindow, IconGripVertical, IconPlayerPauseFilled, IconPlayerPlayFilled, IconPlayerRecordFilled, IconPlayerStopFilled, IconX } from "./ui/icons"
import { api, type CaptureRect } from "./api"
import { appear, timecode } from "./ui/motion"
const win = getCurrentWebviewWindow()
type Rect = { x: number; y: number; width: number; height: number }
type ResizeDirection = Parameters<typeof win.startResizeDragging>[0]
const corners = [
{ id:"nw", direction:"NorthWest" }, { id:"ne", direction:"NorthEast" },
{ id:"sw", direction:"SouthWest" }, { id:"se", direction:"SouthEast" },
] as const
type Phase = "idle" | "recording" | "paused"
let rect: CaptureRect | null = $state(null)
let phase: Phase = $state("idle")
let elapsed = $state(0)
let hotkey = $state<string | null>(null)
let failure = $state("")
let timer: number | undefined
let resizeDelay: number | undefined
let lockedRatio: number | null = null
let enforcing = false
let width: number = $state(0)
let height: number = $state(0)
let phase: "idle" | "recording" | "paused" = $state("idle")
let elapsed: number = $state(0)
let timer: number | null = null
let lockedRatio: number | null = $state(null)
let enforceTimer: number | null = null
let skipEnforce = false
async function refresh() {
const next = await api.getOverlayRect()
rect = next
await emit("overlay-rect", next)
return next
}
function fail(error: unknown) { failure = String(error) }
function move(event: MouseEvent) {
if (event.button === 0 && phase === "idle") void win.startDragging().catch(fail)
}
function resize(event: PointerEvent, direction: ResizeDirection) {
if (event.button !== 0 || phase !== "idle") return
event.preventDefault()
void win.startResizeDragging(direction).catch(fail)
}
async function command(kind: "start"|"pause"|"stop") {
failure = ""
try { await emit("overlay-control", kind) } catch (error) { fail(error) }
}
async function pick() {
failure = ""
try { await api.openWindowPicker() } catch (error) { fail(error) }
}
async function close() {
try { await api.hideOverlay(); await emit("overlay-closed") } catch (error) { fail(error) }
}
onMount(() => {
const updateSize = async () => {
const sz = await win.innerSize()
const sf = await win.scaleFactor()
width = Math.round(sz.width / sf)
height = Math.round(sz.height / sf)
let mounted = true
const listeners: (() => void)[] = []
function keep(promise: Promise<() => void>) {
void promise.then(fn => { if (mounted) listeners.push(fn); else fn() }).catch(fail)
}
updateSize()
// Get initial ratio
invoke<number | null>("get_overlay_aspect").then(r => { lockedRatio = r }).catch(() => {})
let cleanup: (() => void)[] = []
// Listen for ratio changes from Main window via event
listen<{ ratio: number | null }>("overlay-set-ratio", (e) => {
lockedRatio = e.payload.ratio
}).then(fn => cleanup.push(fn))
win.onResized(async () => {
if (skipEnforce) return
await updateSize()
if (lockedRatio === null) return
// Debounce: only enforce after resize settles (user released mouse)
if (enforceTimer !== null) clearTimeout(enforceTimer)
enforceTimer = window.setTimeout(async () => {
skipEnforce = true
try { await invoke("enforce_overlay_aspect") } catch {}
await updateSize()
// Skip events from our own enforcement for a bit
setTimeout(() => { skipEnforce = false }, 100)
}, 200)
}).then(fn => cleanup.push(fn))
listen<{ phase: "idle"|"recording"|"paused" }>(
"recording-state", (e) => {
if (e.payload.phase === "recording") {
if (phase !== "recording") elapsed = 0
startTimer()
} else {
stopTimer()
}
if (e.payload.phase === "idle") elapsed = 0
phase = e.payload.phase
void refresh().catch(fail)
const loadHotkey = () => api.getConfig().then(config => { hotkey = config.hotkeys.start }).catch(fail)
void loadHotkey()
void invoke<number | null>("get_overlay_aspect").then(value => { lockedRatio = value }).catch(fail)
keep(win.onFocusChanged(event => { if (event.payload) { failure = ""; void refresh().catch(fail); void loadHotkey() } }))
keep(win.onMoved(() => { void refresh().catch(fail) }))
keep(win.onScaleChanged(() => { void refresh().catch(fail) }))
keep(win.onResized(() => {
void refresh().catch(fail)
if (enforcing || lockedRatio === null || phase !== "idle") return
window.clearTimeout(resizeDelay)
resizeDelay = window.setTimeout(async () => {
enforcing = true
try { await invoke("enforce_overlay_aspect"); await refresh() } catch (error) { fail(error) }
finally { enforcing = false }
}, 150)
}))
keep(listen<{ratio: number | null}>("overlay-set-ratio", event => {
lockedRatio = event.payload.ratio
window.clearTimeout(resizeDelay)
}))
keep(listen<{phase: Phase; elapsed: number}>("recording-state", event => {
window.clearInterval(timer)
phase = event.payload.phase
elapsed = event.payload.elapsed
if (phase === "recording") {
const start = performance.now(), initial = elapsed
timer = window.setInterval(() => elapsed = initial + (performance.now() - start) / 1000, 100)
}
).then(fn => cleanup.push(fn))
listen<Rect>("picker-pick", async (e: { payload: Rect }) => {
try { await invoke("set_overlay_to_window", e.payload) } catch {}
try { await invoke("close_window_picker") } catch {}
}).then(fn => cleanup.push(fn))
listen("picker-cancel", async () => {
try { await invoke("close_window_picker") } catch {}
}).then(fn => cleanup.push(fn))
}))
keep(listen<CaptureRect>("picker-pick", async event => {
const next = event.payload
failure = ""
try {
lockedRatio = null
await api.setOverlayAspect(null)
await api.setOverlayToWindow(next.x, next.y, next.width, next.height)
await emit("overlay-window-selected", await refresh())
} catch (error) { fail(error); await emit("picker-cancel") }
finally { await invoke("close_window_picker").catch(fail) }
}))
keep(listen("picker-cancel", () => { void invoke("close_window_picker").catch(fail) }))
return () => {
stopTimer()
if (enforceTimer !== null) clearTimeout(enforceTimer)
cleanup.forEach(fn => fn())
mounted = false
window.clearInterval(timer)
window.clearTimeout(resizeDelay)
listeners.forEach(fn => fn())
}
})
function startTimer() {
if (timer !== null) return
timer = window.setInterval(() => { elapsed += 0.1 }, 100)
}
function stopTimer() {
if (timer !== null) { clearInterval(timer); timer = null }
}
function drag(e: MouseEvent) {
if (e.button === 0) win.startDragging().catch(() => {})
}
async function openPicker() {
try { await invoke("open_window_picker") } catch (err) { console.error(err) }
}
async function closeOverlay() {
try { await invoke("hide_overlay") } catch {}
try { await emit("overlay-closed", {}) } catch {}
}
</script>
<div class="overlay">
<div class="titlebar" onmousedown={drag} role="presentation">
<span class="grip" aria-hidden="true">::</span>
<span class="dims" aria-label="dimensions">{width} x {height}</span>
<div class="spacer"></div>
<button class="pick-btn" onclick={openPicker} onmousedown={(e) => e.stopPropagation()} title="snap to window" aria-label="snap capture frame to a window">
<svg width="10" height="10" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round">
<rect x="1" y="1" width="4" height="4" rx="0.5"/>
<rect x="7" y="1" width="4" height="4" rx="0.5"/>
<rect x="1" y="7" width="4" height="4" rx="0.5"/>
<rect x="7" y="7" width="4" height="4" rx="0.5"/>
</svg>
</button>
<button class="close-btn" onclick={closeOverlay} onmousedown={(e) => e.stopPropagation()} title="close frame" aria-label="close capture frame">
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round">
<line x1="2" y1="2" x2="8" y2="8"/>
<line x1="8" y1="2" x2="2" y2="8"/>
</svg>
</button>
{#if phase !== "idle"}
<span class="status" class:recording={phase === "recording"}>
{phase === "recording" ? "REC" : "PAUSE"}
<span class="sep">/</span>
{elapsed.toFixed(1)}s
</span>
<div class="overlay" data-phase={phase}>
<div class="capture-box" aria-hidden="true"></div>
{#if phase === "idle"}
{#each corners as corner}
<button type="button" class={"handle " + corner.id} aria-label={"Resize " + corner.direction}
title={"Resize " + corner.direction} onpointerdown={event => resize(event,corner.direction)}></button>
{/each}
{/if}
<div class="toolbar row" aria-label="Recording frame controls">
{#if phase === "idle"}
<span class="grip" role="presentation" onmousedown={move} title="Move capture frame"><IconGripVertical size={18} /></span>
{#if rect}<span class="measure mono">{rect.width} × {rect.height}</span>{/if}
<button type="button" class="button primary" onclick={() => command("start")} aria-label="Start recording">
<IconPlayerRecordFilled size={15} /><span class="word">Record</span>
</button>
{#if hotkey}<kbd class="shortcut">{hotkey}</kbd>{/if}
<button type="button" class="button ghost icon-only" onclick={pick} aria-label="Pick a window" title="Pick a window"><IconAppWindow size={16} /></button>
<button type="button" class="button ghost icon-only" onclick={close} aria-label="Close capture frame" title="Close capture frame"><IconX size={16} /></button>
{:else}
<span class="live-label mono"><i class="dot" class:live={phase === "recording"}></i><span class="word">{phase === "recording" ? "REC" : "PAUSED"}</span></span>
<span class="mono measure">{timecode(elapsed)}</span>
<button type="button" class="button ghost" onclick={() => command("pause")} aria-label={phase === "recording" ? "Pause recording" : "Resume recording"}>
{#if phase === "recording"}<IconPlayerPauseFilled size={15} />{:else}<IconPlayerPlayFilled size={15} />{/if}
<span class="word">{phase === "recording" ? "Pause" : "Resume"}</span>
</button>
<button type="button" class="button danger" onclick={() => command("stop")} aria-label="Stop recording"><IconPlayerStopFilled size={15} /><span class="word">Stop</span></button>
{/if}
</div>
{#if failure}<p class="frame-error mono" role="alert" use:appear>{failure}</p>{/if}
</div>
<style>
:global(html), :global(body), :global(#overlay) {
margin: 0; padding: 0;
background: transparent;
height: 100vh; width: 100vw;
overflow: hidden;
:global(html), :global(body), :global(#overlay) { width:100%; height:100%; overflow:hidden; background:transparent; }
.overlay { width:100%; height:100%; position:relative; container-type:inline-size; --guide:#d8f578; }
.overlay[data-phase="recording"] { --guide:#ff9582; }
.overlay[data-phase="paused"] { --guide:#e9ece6; }
.capture-box { position:absolute; inset:44px 0 0; border:4px solid var(--guide); pointer-events:none; }
[data-phase="paused"] .capture-box { border-style:dashed; }
.toolbar {
position:absolute; top:4px; left:4px; height:36px; width:min(380px,calc(100% - 8px));
border:3px solid #516067; background:#20292d; color:#f3f4ed; border-radius:8px;
padding:2px 4px; gap:4px; font-size:12px; user-select:none;
}
.overlay {
box-sizing: border-box;
height: 100vh; width: 100vw;
border: 2px solid var(--accent);
display: flex; flex-direction: column;
background: transparent;
border-radius: var(--r-sm);
}
.titlebar {
height: 24px;
background: rgba(9, 9, 11, 0.92);
backdrop-filter: blur(8px);
color: rgba(228, 228, 231, 0.7);
display: flex; align-items: center; gap: 6px;
padding: 0 6px;
font: 10px/1 var(--mono, 'JetBrains Mono', monospace);
cursor: grab;
flex-shrink: 0;
user-select: none;
border-bottom: 1px solid rgba(20, 184, 166, 0.2);
border-radius: 2px 2px 0 0;
}
.titlebar:active { cursor: grabbing; }
.grip { opacity: 0.35; font-size: 11px; flex-shrink: 0; letter-spacing: 1px; }
.dims {
font-family: var(--mono, 'JetBrains Mono', monospace);
font-size: 10px;
color: rgba(228, 228, 231, 0.4);
letter-spacing: 0.02em;
flex-shrink: 0;
}
.spacer { flex: 1; min-width: 0; }
.pick-btn, .close-btn {
display: grid; place-items: center;
width: 18px; height: 18px;
border-radius: 3px;
cursor: pointer;
flex-shrink: 0;
transition: all 80ms;
border: 1px solid transparent;
padding: 0;
}
.pick-btn {
background: rgba(20, 184, 166, 0.1);
border-color: rgba(20, 184, 166, 0.25);
color: rgba(20, 184, 166, 0.7);
}
.pick-btn:hover { background: rgba(20, 184, 166, 0.18); border-color: rgba(20, 184, 166, 0.5); color: var(--accent); }
.close-btn {
background: rgba(239, 68, 68, 0.1);
border-color: rgba(239, 68, 68, 0.25);
color: rgba(239, 68, 68, 0.7);
}
.close-btn:hover { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.5); color: var(--stop); }
.status {
margin-left: 4px;
font-family: var(--mono, 'JetBrains Mono', monospace);
font-size: 10px; font-weight: 500;
color: rgba(228, 228, 231, 0.5);
display: flex; align-items: center; gap: 4px;
background: rgba(255,255,255,0.04);
padding: 1px 6px;
border-radius: 2px;
flex-shrink: 0;
}
.status.recording {
background: rgba(34, 197, 94, 0.15);
color: var(--recording);
}
.sep { opacity: 0.3; }
.toolbar .button { min-height:24px; gap:4px; padding:1px 6px; font-size:12px; border-radius:5px; flex-shrink:0; }
.toolbar .ghost { color:#f3f4ed; }
.toolbar .icon-only { width:26px; padding:0; }
.toolbar .danger { background:#ff9582; color:#291914; }
.toolbar kbd { background:#151c1f; color:#c0cbc8; font-size:10px; white-space:nowrap; min-width:0; overflow:hidden; text-overflow:ellipsis; }
.grip { display:grid; place-items:center; width:24px; flex:0 0 auto; cursor:grab; }
.grip:active { cursor:grabbing; }
.measure { font-size:11px; white-space:nowrap; color:#d7e2db; margin-right:auto; }
.live-label { display:inline-flex; align-items:center; gap:5px; }
.handle { position:absolute; z-index:1; width:13px; height:13px; border:3px solid #172125; border-radius:2px; padding:0; background:var(--guide); }
.nw { left:0; top:44px; cursor:nwse-resize; }
.ne { right:0; top:44px; cursor:nesw-resize; }
.sw { left:0; bottom:0; cursor:nesw-resize; }
.se { right:0; bottom:0; cursor:nwse-resize; }
.frame-error { position:absolute; left:12px; top:56px; max-width:calc(100% - 24px); padding:8px; border-radius:5px; background:#382925; color:#ff9582; pointer-events:none; }
@container (max-width:320px) { .shortcut { display:none; } }
@container (max-width:263px) { .word { display:none; } }
@container (max-width:184px) { .measure { font-size:9px; } .grip { width:16px; } }
</style>
+17 -94
View File
@@ -6,13 +6,12 @@
type Rect = { x: number; y: number; width: number; height: number }
let hover: Rect | null = $state(null)
let originX = 0, originY = 0, scale = 1
let originX = $state(0), originY = $state(0), scale = $state(1)
let mounted = true
onMount(() => {
const win = getCurrentWebviewWindow()
const unlisten: (() => void)[] = []
let hoverDebounce = 0
// A registration that lands after the window is gone still has to
// unregister, so a late unlisten runs immediately rather than being dropped.
@@ -34,15 +33,12 @@
console.warn("could not read the picker window geometry:", e)
}
keep(win.onMoved(refresh))
keep(listen<Rect>("picker-hover", (e) => {
clearTimeout(hoverDebounce)
hoverDebounce = window.setTimeout(() => { hover = e.payload }, 30)
}))
keep(win.onScaleChanged(refresh))
keep(listen<Rect | null>("picker-hover", (e) => { hover = e.payload }))
})()
return () => {
mounted = false
clearTimeout(hoverDebounce)
unlisten.forEach(fn => fn())
emit("picker-cancel", {}).catch(() => {})
}
@@ -58,102 +54,29 @@
})
</script>
<div class="picker" aria-label="window picker - click a window to capture it, Esc to cancel">
<div class="dim" aria-hidden="true"></div>
<div class="picker" aria-label="Window picker">
{#if hover}
<div class="frame" style={rectStyle} aria-hidden="true">
<span class="frame-label">{hover.width} x {hover.height}</span>
<span class="window-size mono">{hover.width} × {hover.height}</span>
</div>
{:else}
<div class="shade" aria-hidden="true"></div>
{/if}
<div class="hint" aria-live="polite">
{#if hover}
click to capture - <kbd>{hover.width}x{hover.height}</kbd>
{:else}
move mouse over a window to select it - <kbd>Esc</kbd> to cancel
{/if}
</div>
<p class="hint row" aria-live="polite">{hover ? "Click to select this window" : "Point at the window to record"} <kbd>Esc</kbd> Cancel</p>
</div>
<style>
:global(html), :global(body), :global(#picker) {
margin: 0; padding: 0;
background: transparent;
height: 100vh; width: 100vw;
overflow: hidden;
cursor: crosshair;
margin:0; background:transparent; width:100%; height:100%; overflow:hidden; cursor:crosshair;
}
.picker {
position: relative;
width: 100vw; height: 100vh;
font-family: var(--mono, 'JetBrains Mono', monospace);
}
.dim {
position: absolute; inset: 0;
background: rgba(9, 9, 11, 0.15);
}
.picker { position:relative; width:100%; height:100%; overflow:hidden; }
.shade { position:absolute; inset:0; background:#10171e60; }
.frame {
position: absolute;
pointer-events: none;
border: 2px solid var(--accent);
background: transparent;
background-image:
repeating-linear-gradient(90deg, var(--accent) 0px, var(--accent) 8px, transparent 8px, transparent 12px),
repeating-linear-gradient(0deg, var(--accent) 0px, var(--accent) 8px, transparent 8px, transparent 12px),
repeating-linear-gradient(90deg, var(--accent) 0px, var(--accent) 8px, transparent 8px, transparent 12px),
repeating-linear-gradient(0deg, var(--accent) 0px, var(--accent) 8px, transparent 8px, transparent 12px);
background-position: 0 0, 0 0, 0 100%, 100% 0;
background-size: 12px 2px, 2px 12px, 12px 2px, 2px 12px;
background-repeat: repeat-x, repeat-y, repeat-x, repeat-y;
animation: march 0.4s linear infinite;
transition: left 0.08s ease, top 0.08s ease, width 0.08s ease, height 0.08s ease;
}
@keyframes march {
to { background-position: 12px 0, 0 12px, -12px 100%, 100% -12px; }
}
.frame-label {
position: absolute;
top: -20px; left: 0;
padding: 2px 6px;
background: var(--accent);
color: #020617;
font-size: 9px;
font-weight: 600;
font-family: var(--mono, 'JetBrains Mono', monospace);
letter-spacing: 0.04em;
border-radius: 2px;
white-space: nowrap;
}
.hint {
position: fixed;
bottom: 20px; left: 50%; transform: translateX(-50%);
padding: 7px 18px;
background: rgba(9, 9, 11, 0.9);
backdrop-filter: blur(10px);
color: rgba(228, 228, 231, 0.85);
font-size: 12px;
font-family: var(--sans, system-ui, sans-serif);
border: 1px solid rgba(20, 184, 166, 0.2);
border-radius: 999px;
white-space: nowrap;
pointer-events: none;
}
kbd {
display: inline-block;
padding: 0 4px;
background: rgba(20, 184, 166, 0.12);
border: 1px solid rgba(20, 184, 166, 0.3);
border-radius: 2px;
font-family: var(--mono, 'JetBrains Mono', monospace);
font-size: 10px;
color: var(--accent);
position:absolute; pointer-events:none; border:4px solid #d8f578;
outline:3px solid #172125; box-shadow:0 0 0 100vmax #10171e99;
}
.window-size, .hint { background:#20292d; color:#f3f4ed; border:3px solid #516067; border-radius:8px; }
.window-size { position:absolute; top:8px; left:8px; padding:3px 8px; }
.hint { position:fixed; bottom:18px; left:50%; transform:translateX(-50%); padding:7px 12px; white-space:nowrap; pointer-events:none; }
.hint kbd { background:#151c1f; color:#d7e2db; }
</style>
-19
View File
@@ -1,19 +0,0 @@
@import url('https://fonts.bunny.net/css2?family=JetBrains+Mono:wght@400;500&display=swap');
:root {
--accent: #14B8A6;
--accent-dim: rgba(20, 184, 166, 0.10);
--accent-glow: rgba(20, 184, 166, 0.25);
--accent-text: #020617;
--recording: #22C55E;
--recording-dim: rgba(34, 197, 94, 0.10);
--stop: #EF4444;
--stop-dim: rgba(239, 68, 68, 0.10);
--bg-elev: rgba(9, 9, 11, 0.92);
--text: #E4E4E7;
--text-2: rgba(228, 228, 231, 0.7);
--text-3: rgba(228, 228, 231, 0.4);
--border: rgba(255, 255, 255, 0.06);
--border-2: rgba(255, 255, 255, 0.10);
--mono: 'JetBrains Mono', ui-monospace, monospace;
--r-sm: 3px;
}
+4 -1
View File
@@ -1,6 +1,9 @@
import { mount } from "svelte"
import "./overlay.css"
import "./ui.css"
import Overlay from "./lib/Overlay.svelte"
import { installMotion } from "./lib/ui/motion"
installMotion()
const app = mount(Overlay, {
target: document.getElementById("overlay")!,
+1 -1
View File
@@ -1,5 +1,5 @@
import { mount } from "svelte"
import "./app.css"
import "./ui.css"
import Picker from "./lib/Picker.svelte"
const app = mount(Picker, {