From a9ce798490c0c9909d5c238e1010be74df5fa491 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Tue, 5 Oct 2021 13:23:32 +0200 Subject: [PATCH] Confirm page unload when save is 5 Min+ old --- src/App.svelte | 16 ++++++++++++++++ src/shark/SaveHandler.ts | 13 ++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/App.svelte b/src/App.svelte index e313ddf..39f1a87 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -31,9 +31,25 @@ closeAllModals(); } } + + function handleBeforeUnload(event: BeforeUnloadEvent) { + console.debug( + "beforeUnload", + Date.now() - SharkGame.SaveHandler.lastSaved >= 60 * 1000, + Date.now() - SharkGame.SaveHandler.lastSaved, + 60 * 1000 + ); + // If last save is over a minute old + if (Date.now() - SharkGame.SaveHandler.lastSaved >= 60 * 1000) { + // Annotyingly, the standardized way isn't supported, so both outdated ones will have to suffice + event.preventDefault(); + return (event.returnValue = "Last save is over a minute old."); + } + } +