feat: add ESC key support to close all modals and fullscreen modes

This commit is contained in:
2026-03-02 23:58:50 +00:00
parent 60fc774586
commit dcde3b0799
4 changed files with 55 additions and 3 deletions

View File

@@ -377,11 +377,18 @@ watch(scannedCodes, (newVal) => {
localStorage.setItem('qr-history', JSON.stringify(newVal))
}, { deep: true })
const handleKeydown = (e) => {
if (e.key === 'Escape' && isFullscreen.value) {
toggleFullscreen()
}
}
onMounted(() => {
checkCameras()
loadHistory()
window.addEventListener('resize', updateVideoAspect)
window.addEventListener('resize', startBackgroundLoop)
window.addEventListener('keydown', handleKeydown)
watch(isFullscreen, (fs) => {
if (fs) {
startBackgroundLoop()
@@ -389,13 +396,14 @@ onMounted(() => {
stopBackgroundLoop()
}
}, { immediate: true })
startScan()
})
onUnmounted(() => {
window.removeEventListener('resize', updateVideoAspect)
window.removeEventListener('resize', startBackgroundLoop)
window.removeEventListener('keydown', handleKeydown)
stopScan()
})