region capture overlay window

This commit is contained in:
2026-05-12 00:06:31 +03:00
parent 03af276a1d
commit 14d02cdad4
11 changed files with 305 additions and 14 deletions
+43 -3
View File
@@ -25,6 +25,7 @@
let targetMB: number = $state(8)
let exportResult: ExportResult | null = $state(null)
let errMsg: string | null = $state(null)
let useFrame: boolean = $state(false)
onMount(async () => {
config = await api.getConfig()
@@ -46,15 +47,39 @@
}
}
async function toggleFrame() {
useFrame = !useFrame
try {
if (useFrame) await api.showOverlay()
else await api.hideOverlay()
} catch (e) {
errMsg = String(e)
useFrame = false
}
}
async function startRec() {
errMsg = null
elapsed = 0
let crop = null
if (useFrame) {
try {
crop = await api.getOverlayRect()
await api.hideOverlay()
} catch (e) {
errMsg = String(e)
return
}
}
try {
await api.startCapture()
await api.startCapture({ crop })
phase = "recording"
tick()
} catch (e) {
errMsg = String(e)
if (useFrame) {
await api.showOverlay().catch(() => {})
}
}
}
@@ -127,10 +152,18 @@
{#if phase === "idle"}
<section class="controls">
<button class="primary big" onclick={startRec}>start recording</button>
<button class:on={useFrame} onclick={toggleFrame}>
{useFrame ? "hide capture frame" : "show capture frame"}
</button>
</section>
<p class="hint">
Captures your primary monitor. Region capture and the draggable overlay
come next.
{#if useFrame}
Drag the green frame on screen to position the region you want to
capture. The frame hides automatically while recording.
{:else}
Captures your full primary monitor. Click "show capture frame" to draw
a region instead.
{/if}
</p>
{:else if phase === "recording"}
<section class="recording">
@@ -288,6 +321,8 @@
.controls {
display: flex;
justify-content: center;
gap: 0.75rem;
flex-wrap: wrap;
margin-top: 2rem;
}
.recording {
@@ -326,6 +361,11 @@
padding: 0.75rem 1.75rem;
font-size: 1rem;
}
button.on {
background: #1a2a24;
border-color: #4a8;
color: #4a8;
}
button.stop {
background: #c33;
border-color: #c33;
+73
View File
@@ -0,0 +1,73 @@
<script lang="ts">
import { onMount } from "svelte"
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"
let width: number = $state(0)
let height: number = $state(0)
onMount(() => {
const win = getCurrentWebviewWindow()
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)
}
updateSize()
const unlisten = win.onResized(updateSize)
return () => {
unlisten.then((fn) => fn())
}
})
</script>
<div class="frame">
<div class="titlebar" data-tauri-drag-region>
<span class="grip" data-tauri-drag-region>⠿</span>
<span class="dim" data-tauri-drag-region>{width} x {height}</span>
</div>
</div>
<style>
:global(html), :global(body), :global(#overlay) {
margin: 0;
padding: 0;
background: transparent;
height: 100vh;
width: 100vw;
overflow: hidden;
}
.frame {
box-sizing: border-box;
height: 100vh;
width: 100vw;
border: 2px solid #4a8;
display: flex;
flex-direction: column;
background: transparent;
}
.titlebar {
height: 22px;
background: rgba(74, 170, 136, 0.85);
color: #0e1a16;
display: flex;
align-items: center;
gap: 8px;
padding: 0 8px;
font: 11px ui-monospace, monospace;
cursor: grab;
flex-shrink: 0;
}
.titlebar:active {
cursor: grabbing;
}
.grip {
font-size: 14px;
opacity: 0.7;
}
.dim {
font-variant-numeric: tabular-nums;
}
</style>
+17 -1
View File
@@ -49,11 +49,23 @@ export type DownloadProgress = {
total: number | null
}
export type CaptureRect = {
x: number
y: number
width: number
height: number
}
export type RecordedClip = {
temp_path: string
duration_secs: number
width: number
height: number
crop: CaptureRect | null
}
export type StartCaptureRequest = {
crop: CaptureRect | null
}
export type ExportRequest = {
@@ -75,10 +87,14 @@ export const api = {
downloadFfmpeg: () => invoke<void>("download_ffmpeg"),
onFfmpegProgress: (handler: (p: DownloadProgress) => void): Promise<UnlistenFn> =>
listen<DownloadProgress>("ffmpeg-progress", (e) => handler(e.payload)),
startCapture: () => invoke<void>("start_capture"),
startCapture: (request: StartCaptureRequest) =>
invoke<void>("start_capture", { request }),
stopCapture: () => invoke<RecordedClip>("stop_capture"),
export: (request: ExportRequest) => invoke<ExportResult>("export", { request }),
revealInExplorer: (path: string) => invoke<void>("reveal_in_explorer", { path }),
showOverlay: () => invoke<void>("show_overlay"),
hideOverlay: () => invoke<void>("hide_overlay"),
getOverlayRect: () => invoke<CaptureRect>("get_overlay_rect"),
}
export function formatBytes(n: number): string {
+8
View File
@@ -0,0 +1,8 @@
import { mount } from "svelte"
import Overlay from "./lib/Overlay.svelte"
const app = mount(Overlay, {
target: document.getElementById("overlay")!,
})
export default app