Ask before leaving the page while a world is open (Ctrl+W closed the game)
Ctrl (replace) + W (fly) hits the browser's close-tab shortcut, which a page cannot block. A beforeunload prompt now catches it. Autosave on hiding the tab no longer depends on the audio context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+5
-1
@@ -69,7 +69,11 @@ canvas.addEventListener('wheel', e => {
|
||||
}, { passive: false });
|
||||
window.addEventListener('resize', () => { if (R.canvas) resizeRender(); });
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.hidden && GAME.running) saveWorld('auto', true);
|
||||
if (!AU.ctx) return;
|
||||
if (document.hidden) { if (SET.muteUnfocused) AU.ctx.suspend(); if (GAME.running) saveWorld('auto', true); }
|
||||
if (document.hidden) { if (SET.muteUnfocused) AU.ctx.suspend(); }
|
||||
else AU.ctx.resume();
|
||||
});
|
||||
// Ctrl+W closes the tab and the page cannot stop it, and Ctrl (replace) + W (fly) is an easy slip:
|
||||
// while a world is open, ask the browser to confirm leaving
|
||||
window.addEventListener('beforeunload', e => { if (GAME.running) { e.preventDefault(); e.returnValue = ''; } });
|
||||
|
||||
Reference in New Issue
Block a user