show: ESC twice to close (to avoid unwanted stops)
Massimo Melina committed
Aug 17, 2024 at 19:18 UTC
8a28f71d5e2f020b3be6266ea72cfdf17a06fdcc
1 file changed
+14
-2
frontend/src/show.ts
+14
-2
@@ -8,7 +8,7 @@ import { EntryDetails, useMidnight } from './BrowseFiles'
8
import { Btn, FlexV, iconBtn, Spinner } from './components'
9
import { openFileMenu } from './fileMenu'
10
import { t, useI18N } from './i18n'
11
-import { alertDialog } from './dialog'
11
+import { alertDialog, toast } from './dialog'
12
import _ from 'lodash'
13
import { getId3Tags } from './id3'
14
import { subscribeKey } from 'valtio/utils'
@@ -20,9 +20,14 @@ enum ZoomMode {
20
}
21
22
export function fileShow(entry: DirEntry, { startPlaying=false } = {}) {
23
+ let escOnce = false
24
+ let onClose: any
25
const { close } = newDialog({
26
noFrame: true,
27
className: 'file-show',
28
+ onClose() {
29
+ onClose?.()
30
+ },
31
Content() {
32
const [cur, setCur] = useState(entry)
33
const moving = useRef(0)
@@ -42,7 +47,14 @@ export function fileShow(entry: DirEntry, { startPlaying=false } = {}) {
47
goTo(shuffle[0])
48
}, [Boolean(shuffle)])
49
useEventListener('keydown', ({ key }) => {
45
- if (key === 'Escape') return close()
50
+ if (key === 'Escape') {
51
+ if (escOnce)
52
+ return close()
53
+ escOnce = true
54
+ onClose = toast(t('esc_again', "Press ESC twice to close")).close
55
+ return
56
+ }
57
+ escOnce = false
58
if (key === 'ArrowLeft') return goPrev()
59
if (key === 'ArrowRight') return goNext()
60
if (key === 'ArrowDown') return scrollY(1)