2018-08-25 05:55:03 +02:00
|
|
|
export function setupCloseListener () {
|
|
|
|
window.appState.isQuitting = false
|
|
|
|
|
|
|
|
const handleClose = async () => {
|
|
|
|
await windows95.saveState()
|
|
|
|
window.appState.isQuitting = true
|
|
|
|
windows95.quit()
|
|
|
|
}
|
|
|
|
|
|
|
|
window.onbeforeunload = (event) => {
|
|
|
|
if (window.appState.isQuitting) return
|
2019-02-04 00:23:20 +01:00
|
|
|
if (window.appState.isResetting) return
|
2018-08-25 05:55:03 +02:00
|
|
|
|
|
|
|
handleClose()
|
|
|
|
event.preventDefault()
|
|
|
|
event.returnValue = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setupEscListener () {
|
|
|
|
document.onkeydown = function (evt) {
|
|
|
|
evt = evt || window.event
|
|
|
|
if (evt.keyCode === 27) {
|
|
|
|
if (window.appState.cursorCaptured) {
|
|
|
|
window.appState.cursorCaptured = false
|
2019-02-03 23:08:09 +01:00
|
|
|
window.emulator.mouse_set_status(false)
|
2018-08-25 05:55:03 +02:00
|
|
|
document.exitPointerLock()
|
|
|
|
} else {
|
|
|
|
window.appState.cursorCaptured = true
|
|
|
|
window.emulator.lock_mouse()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 00:23:20 +01:00
|
|
|
function onDocumentClick () {
|
|
|
|
if (!window.appState.cursorCaptured) {
|
|
|
|
window.appState.cursorCaptured = true
|
|
|
|
window.emulator.mouse_set_status(true)
|
|
|
|
window.emulator.lock_mouse()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-25 05:55:03 +02:00
|
|
|
export function setupClickListener () {
|
2019-02-04 00:23:20 +01:00
|
|
|
document.removeEventListener('click', onDocumentClick)
|
|
|
|
document.addEventListener('click', onDocumentClick)
|
2018-08-25 05:55:03 +02:00
|
|
|
}
|