Skip to content

Commit

Permalink
Prevent closing the tab when there are unsaved changes (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Sep 13, 2022
1 parent cf1c54a commit 62dd7d1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions timetagger/app/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,14 @@ def __init__(self):
window.document.addEventListener(
"visibilitychange", lambda: self.sync_soon(1.0), False
)
window.addEventListener("beforeunload", self._beforeunload, False)

def _beforeunload(self, ev):
if self.state == "pending":
msg = "The most recent changes have not yet been stored."
ev.returnValue = msg
return msg
return None

def reset(self):
# The sub stores
Expand Down

0 comments on commit 62dd7d1

Please sign in to comment.