get the encoder work off the main thread and harden the update path
This commit is contained in:
+18
-7
@@ -11,7 +11,15 @@
|
||||
|
||||
onMount(() => {
|
||||
const win = getCurrentWebviewWindow()
|
||||
let unlisten: (() => void)[] = []
|
||||
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.
|
||||
const keep = (p: Promise<() => void>) => {
|
||||
void p.then(fn => { if (mounted) unlisten.push(fn); else fn() })
|
||||
.catch(e => console.warn("could not register a listener:", e))
|
||||
}
|
||||
|
||||
const refresh = async () => {
|
||||
scale = await win.scaleFactor()
|
||||
@@ -20,18 +28,21 @@
|
||||
}
|
||||
|
||||
void (async () => {
|
||||
await refresh()
|
||||
win.onMoved(refresh).then(fn => { if (mounted) unlisten.push(fn) })
|
||||
.catch(e => console.warn("could not watch the picker window position:", e))
|
||||
let hoverDebounce = 0
|
||||
listen<Rect>("picker-hover", (e) => {
|
||||
try {
|
||||
await refresh()
|
||||
} catch (e) {
|
||||
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)
|
||||
}).then(fn => { if (mounted) unlisten.push(fn) })
|
||||
}))
|
||||
})()
|
||||
|
||||
return () => {
|
||||
mounted = false
|
||||
clearTimeout(hoverDebounce)
|
||||
unlisten.forEach(fn => fn())
|
||||
emit("picker-cancel", {}).catch(() => {})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user