20 fixes: mutex poisoning recovery, clickthrough shutdown, audio cleanup, config corruption, GIF aspect ratio, ffmpeg crash detection, cancel export, discard confirm, thumbnail cache, keyboard nav, right-click tracking, multi-monitor overlay, click injection fix, update script robustness, effect cleanup, concat guard, dead code removal

This commit is contained in:
2026-05-27 19:14:33 +03:00
parent f0775b8ff0
commit e4141f8be8
10 changed files with 310 additions and 140 deletions
+74 -5
View File
@@ -48,6 +48,8 @@
let audioWarning: string | null = $state(null)
let useFrame: boolean = $state(false)
let previewTimer: number | null = null
let thumbCache: Map<string, string[]> = $state(new Map())
let showDiscardConfirm: boolean = $state(false)
const PRESETS: [number, number, string][] = [
[1280, 720, "720p"],
@@ -182,9 +184,14 @@
async function loadThumbnails() {
if (format !== "gif") { thumbnails = []; return }
const cacheKey = `${format}-${fps}`
const cached = thumbCache.get(cacheKey)
if (cached) { thumbnails = cached; deletedFrames = new Set(); return }
loadingThumbs = true
try {
thumbnails = await api.extractThumbnails(fps)
const thumbs = await api.extractThumbnails(fps)
thumbCache.set(cacheKey, thumbs)
thumbnails = thumbs
deletedFrames = new Set()
} catch (e) { errMsg = String(e) }
finally { loadingThumbs = false }
@@ -220,10 +227,30 @@
function startOver() {
clip = null; exportResult = null; errMsg = null; encodeProgress = null
thumbnails = []; deletedFrames = new Set()
thumbCache = new Map()
if (previewTimer !== null) { clearTimeout(previewTimer); previewTimer = null }
elapsed = 0; phase = "idle"
}
async function cancelExport() {
try { await api.cancelExport() } catch {}
phase = "editing"
encodeProgress = null
}
function confirmDiscard() {
showDiscardConfirm = true
}
function cancelDiscard() {
showDiscardConfirm = false
}
function doDiscard() {
showDiscardConfirm = false
startOver()
}
function tick() { elapsedTimer = window.setInterval(() => { elapsed += 0.1 }, 100) }
function clearTick() { if (elapsedTimer !== null) { clearInterval(elapsedTimer); elapsedTimer = null } }
function minMB(s: number): number { return Math.max(0.1, Math.max(50_000, s * 50_000) / 1_048_576) }
@@ -283,10 +310,9 @@
$effect(() => {
if (phase === "editing" && format) {
if (previewTimer !== null) clearTimeout(previewTimer)
previewTimer = window.setTimeout(() => { previewTimer = null; void refreshPreview() }, 300)
const timer = window.setTimeout(() => { void refreshPreview() }, 300)
return () => { clearTimeout(timer) }
}
return () => { if (previewTimer !== null) { clearTimeout(previewTimer); previewTimer = null } }
})
$effect(() => {
@@ -474,6 +500,12 @@
onpointerdown={(e) => startDrag('start', e)}
onpointermove={onDrag}
onpointerup={endDrag}
onkeydown={(e) => {
if (!clip) return
const step = e.shiftKey ? 0.5 : 0.05
if (e.key === 'ArrowLeft') { trimStart = Math.max(0, trimStart - step); e.preventDefault() }
else if (e.key === 'ArrowRight') { trimStart = Math.min(trimEnd - 0.1, trimStart + step); e.preventDefault() }
}}
></div>
<div
class="trim-handle trim-end"
@@ -487,6 +519,12 @@
onpointerdown={(e) => startDrag('end', e)}
onpointermove={onDrag}
onpointerup={endDrag}
onkeydown={(e) => {
if (!clip) return
const step = e.shiftKey ? 0.5 : 0.05
if (e.key === 'ArrowLeft') { trimEnd = Math.max(trimStart + 0.1, trimEnd - step); e.preventDefault() }
else if (e.key === 'ArrowRight') { trimEnd = Math.min(clip.duration_secs, trimEnd + step); e.preventDefault() }
}}
></div>
</div>
<input type="range" min="0" max={clip.duration_secs} step="0.05" value={trimStart}
@@ -608,7 +646,7 @@
<!-- Actions -->
<div class="edit-actions">
<button class="btn-primary" onclick={doExport}>Export</button>
<button class="btn-ghost" onclick={startOver}>Discard</button>
<button class="btn-ghost" onclick={confirmDiscard}>Discard</button>
</div>
</div>
</div>
@@ -629,6 +667,7 @@
<div class="enc-track"><div class="enc-fill" style="width:0%"></div></div>
{/if}
<p class="enc-hint">ffmpeg is encoding your clip</p>
<button class="btn-ghost" onclick={cancelExport}>Cancel</button>
</div>
<!-- DONE -->
@@ -650,6 +689,18 @@
</div>
</div>
{/if}
{#if showDiscardConfirm}
<div class="confirm-overlay">
<div class="confirm-card">
<p>Discard this recording?</p>
<div class="confirm-actions">
<button class="btn-ghost" onclick={cancelDiscard}>Keep it</button>
<button class="btn-stop" onclick={doDiscard}>Discard</button>
</div>
</div>
</div>
{/if}
</main>
<!-- Error toast -->
@@ -1373,4 +1424,22 @@
}
.mono { font-family: var(--mono); }
/* ---- Confirm overlay ---- */
.confirm-overlay {
position: fixed; inset: 0;
background: rgba(0,0,0,0.5);
display: grid; place-items: center;
z-index: 50;
}
.confirm-card {
background: var(--bg-2);
border: 1px solid var(--border);
border-radius: var(--r-md);
padding: 24px;
min-width: 280px;
text-align: center;
}
.confirm-card p { margin: 0 0 16px; font-size: 14px; color: var(--text); }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }
</style>
+24 -29
View File
@@ -22,39 +22,34 @@
height = Math.round(sz.height / sf)
}
updateSize()
const rp = win.onResized(updateSize)
let cleanup: (() => void)[] = []
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
win.onResized(updateSize).then(fn => cleanup.push(fn))
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
}
).then(fn => cleanup.push(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 {}
})
})()
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))
return () => { stopTimer(); void rp.then(fn => fn()); void rp2?.then(fn => fn()); void rp3?.then(fn => fn()) }
listen("picker-cancel", async () => {
try { await invoke("close_window_picker") } catch {}
}).then(fn => cleanup.push(fn))
return () => { stopTimer(); cleanup.forEach(fn => fn()) }
})
function startTimer() {
+1
View File
@@ -184,6 +184,7 @@ export const api = {
listen<EncodeProgress>("encode-progress", (e) => handler(e.payload)),
onAudioFailed: (handler: (msg: string) => void): Promise<UnlistenFn> =>
listen<string>("audio-failed", (e) => handler(e.payload)),
cancelExport: () => invoke<void>("cancel_export"),
}
export function formatBytes(n: number): string {