current state before improvement pass

This commit is contained in:
2026-05-27 18:56:36 +03:00
parent 5eb27ab779
commit f0775b8ff0
23 changed files with 3563 additions and 1853 deletions
+107 -143
View File
@@ -5,129 +5,94 @@
import { invoke } from "@tauri-apps/api/core"
const win = getCurrentWebviewWindow()
type Rect = { x: number; y: number; width: number; height: number }
let width: number = $state(0)
let width: number = $state(0)
let height: number = $state(0)
let phase: "idle" | "recording" | "paused" = $state("idle")
let fps: number = $state(30)
let fps: number = $state(30)
let elapsed: number = $state(0)
let timer: number | null = null
onMount(() => {
const updateSize = async () => {
const size = await win.innerSize()
const scale = await win.scaleFactor()
width = Math.round(size.width / scale)
height = Math.round(size.height / scale)
const sz = await win.innerSize()
const sf = await win.scaleFactor()
width = Math.round(sz.width / sf)
height = Math.round(sz.height / sf)
}
updateSize()
const unlistenResize = win.onResized(updateSize)
const rp = win.onResized(updateSize)
const unlistenStatePromise = listen<{
phase: "idle" | "recording" | "paused"
fps: number
}>("recording-state", (e) => {
const next = e.payload.phase
fps = e.payload.fps
if (next === "recording") {
if (phase === "idle") elapsed = 0
startTimer()
} else {
stopTimer()
}
if (next === "idle") elapsed = 0
phase = next
})
let rp2: Promise<() => void> | null = null
void (async () => {
rp2 = listen<{ phase: "idle"|"recording"|"paused"; fps: number }>(
"recording-state", (e) => {
fps = e.payload.fps
if (e.payload.phase === "recording") {
if (phase !== "recording") elapsed = 0
startTimer()
} else {
stopTimer()
}
if (e.payload.phase === "idle") { elapsed = 0; phase = "idle" }
phase = e.payload.phase
}
)
})()
return () => {
stopTimer()
unlistenResize.then((fn) => fn())
unlistenStatePromise.then((fn) => fn())
}
let rp3: Promise<() => void> | null = null
void (async () => {
rp3 = 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 {}
})
})()
void (async () => {
await listen("picker-cancel", async () => {
try { await invoke("close_window_picker") } catch {}
})
})()
return () => { stopTimer(); void rp.then(fn => fn()); void rp2?.then(fn => fn()); void rp3?.then(fn => fn()) }
})
function startTimer() {
if (timer !== null) return
timer = window.setInterval(() => {
elapsed += 0.1
}, 100)
timer = window.setInterval(() => { elapsed += 0.1 }, 100)
}
function stopTimer() {
if (timer !== null) {
clearInterval(timer)
timer = null
}
if (timer !== null) { clearInterval(timer); timer = null }
}
function startDrag(e: MouseEvent) {
if (e.button === 0) {
e.preventDefault()
void win.startDragging().catch((err) => console.error("startDragging", err))
}
function drag(e: MouseEvent) {
if (e.button === 0) void win.startDragging()
}
async function openPicker() {
try {
await invoke("open_window_picker")
} catch (e) {
console.error("open_window_picker", e)
}
try { await invoke("open_window_picker") } catch (err) { console.error(err) }
}
onMount(() => {
let unlistenPick: (() => void) | null = null
let unlistenCancel: (() => void) | null = null
void (async () => {
unlistenPick = await listen<{ x: number; y: number; width: number; height: number }>(
"picker-pick",
async (e) => {
try {
await invoke("set_overlay_to_window", e.payload)
} catch (err) {
console.error("set_overlay_to_window", err)
}
try {
await invoke("close_window_picker")
} catch (err) {
console.error("close_window_picker", err)
}
},
)
unlistenCancel = await listen("picker-cancel", async () => {
try {
await invoke("close_window_picker")
} catch (err) {
console.error("close_window_picker", err)
}
})
})()
return () => {
unlistenPick?.()
unlistenCancel?.()
}
})
</script>
<div class="frame">
<div
class="titlebar"
data-tauri-drag-region
onmousedown={startDrag}
role="presentation"
>
<span class="grip" data-tauri-drag-region>⠿</span>
<span class="dim" data-tauri-drag-region>{width} x {height}</span>
<button
class="pick-btn"
onclick={openPicker}
onmousedown={(e) => e.stopPropagation()}
title="snap to window"
type="button"
>▦</button>
<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>
<button class="pick-btn" onclick={openPicker} 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>
{#if phase !== "idle"}
<span class="status" class:rec={phase === "recording"}>
{phase === "recording" ? "REC" : "PAUSE"} · {elapsed.toFixed(1)}s · {fps}fps
<span class="status" class:recording={phase === "recording"}>
{phase === "recording" ? "REC" : "PAUSE"}
<span class="sep">/</span>
{elapsed.toFixed(1)}s
<span class="sep">/</span>
{fps}fps
</span>
{/if}
</div>
@@ -135,72 +100,71 @@
<style>
:global(html), :global(body), :global(#overlay) {
margin: 0;
padding: 0;
margin: 0; padding: 0;
background: transparent;
height: 100vh;
width: 100vw;
height: 100vh; width: 100vw;
overflow: hidden;
}
.frame {
.overlay {
box-sizing: border-box;
height: 100vh;
width: 100vw;
border: 2px solid #4a8;
display: flex;
flex-direction: column;
height: 100vh; width: 100vw;
border: 2px solid #14B8A6;
display: flex; flex-direction: column;
background: transparent;
border-radius: var(--r-sm);
}
.titlebar {
height: 22px;
background: rgba(74, 170, 136, 0.85);
color: #0e1a16;
display: flex;
align-items: center;
gap: 8px;
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: 8px;
padding: 0 8px;
font: 11px ui-monospace, monospace;
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;
.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;
}
.grip {
font-size: 14px;
opacity: 0.7;
}
.dim {
font-variant-numeric: tabular-nums;
.pick-btn {
display: grid; place-items: center;
width: 20px; height: 20px;
background: rgba(20, 184, 166, 0.1);
border: 1px solid rgba(20, 184, 166, 0.25);
color: rgba(20, 184, 166, 0.7);
border-radius: var(--r-sm);
cursor: pointer;
flex-shrink: 0;
transition: all 80ms;
}
.pick-btn:hover { background: rgba(20, 184, 166, 0.18); border-color: rgba(20, 184, 166, 0.5); color: #14B8A6; }
.status {
margin-left: auto;
font-variant-numeric: tabular-nums;
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: 999px;
background: rgba(0, 0, 0, 0.25);
color: #eee;
border-radius: 2px;
}
.status.rec {
background: #c33;
color: #fff;
}
.pick-btn {
background: rgba(0, 0, 0, 0.2);
border: 1px solid rgba(14, 26, 22, 0.4);
color: #0e1a16;
font: inherit;
font-size: 12px;
padding: 1px 6px;
border-radius: 3px;
cursor: pointer;
line-height: 1;
}
.pick-btn:hover {
background: rgba(0, 0, 0, 0.35);
color: #fff;
.status.recording {
background: rgba(34, 197, 94, 0.15);
color: #22C55E;
}
.sep { opacity: 0.3; }
</style>