live elapsed and fps readout on capture frame

This commit is contained in:
2026-05-12 01:49:46 +03:00
parent b7ac517381
commit 27d7453ea2
2 changed files with 62 additions and 2 deletions
+5
View File
@@ -10,6 +10,7 @@
type ExportResult,
} from "./api"
import { save } from "@tauri-apps/plugin-dialog"
import { emit } from "@tauri-apps/api/event"
type Phase = "idle" | "recording" | "paused" | "editing" | "exporting" | "done"
@@ -100,6 +101,7 @@
await api.startCapture({ crop })
phase = "recording"
tick()
void emit("recording-state", { phase: "recording", fps })
} catch (e) {
errMsg = String(e)
}
@@ -107,6 +109,7 @@
async function stopRec() {
clearTick()
void emit("recording-state", { phase: "idle", fps })
try {
const c = await api.stopCapture()
clip = c
@@ -149,6 +152,7 @@
try {
await api.pauseCapture()
phase = "paused"
void emit("recording-state", { phase: "paused", fps })
} catch (e) {
errMsg = String(e)
tick()
@@ -160,6 +164,7 @@
await api.resumeCapture()
phase = "recording"
tick()
void emit("recording-state", { phase: "recording", fps })
} catch (e) {
errMsg = String(e)
}
+57 -2
View File
@@ -1,11 +1,16 @@
<script lang="ts">
import { onMount } from "svelte"
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"
import { listen } from "@tauri-apps/api/event"
const win = getCurrentWebviewWindow()
let width: number = $state(0)
let height: number = $state(0)
let phase: "idle" | "recording" | "paused" = $state("idle")
let fps: number = $state(30)
let elapsed: number = $state(0)
let timer: number | null = null
onMount(() => {
const updateSize = async () => {
@@ -15,12 +20,45 @@
height = Math.round(size.height / scale)
}
updateSize()
const unlistenPromise = win.onResized(updateSize)
const unlistenResize = 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
})
return () => {
unlistenPromise.then((fn) => fn())
stopTimer()
unlistenResize.then((fn) => fn())
unlistenStatePromise.then((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 startDrag(e: MouseEvent) {
if (e.button === 0) {
e.preventDefault()
@@ -38,6 +76,11 @@
>
<span class="grip" data-tauri-drag-region>⠿</span>
<span class="dim" data-tauri-drag-region>{width} x {height}</span>
{#if phase !== "idle"}
<span class="status" class:rec={phase === "recording"}>
{phase === "recording" ? "REC" : "PAUSE"} · {elapsed.toFixed(1)}s · {fps}fps
</span>
{/if}
</div>
</div>
@@ -84,4 +127,16 @@
.dim {
font-variant-numeric: tabular-nums;
}
.status {
margin-left: auto;
font-variant-numeric: tabular-nums;
padding: 1px 6px;
border-radius: 999px;
background: rgba(0, 0, 0, 0.25);
color: #eee;
}
.status.rec {
background: #c33;
color: #fff;
}
</style>