feat: display leave confirmation when playing (prevent accidental ctrl+w), but not when paused so can easily close if desired
This commit is contained in:
parent
46bc423935
commit
fd84697db0
1 changed files with 12 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
|||
//@ts-check
|
||||
|
||||
import { proxy, ref } from 'valtio'
|
||||
import { proxy, ref, subscribe } from 'valtio'
|
||||
import { pointerLock } from './utils'
|
||||
|
||||
// todo: refactor structure with support of hideNext=false
|
||||
|
|
@ -110,4 +110,15 @@ export const miscUiState = proxy({
|
|||
currentTouch: null
|
||||
})
|
||||
|
||||
window.addEventListener('beforeunload', (event) => {
|
||||
// todo-low maybe exclude chat?
|
||||
if (!isGameActive(true) && activeModalStack.at(-1)?.elem.id !== 'chat') return
|
||||
// For major browsers doning only this is enough
|
||||
event.preventDefault()
|
||||
|
||||
// Display a confirmation prompt
|
||||
event.returnValue = '' // Required for some browsers
|
||||
return 'The game is running. Are you sure you want to close this page?'
|
||||
});
|
||||
|
||||
window.miscUiState = miscUiState
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue