diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-13 03:29:49 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-13 03:29:49 -0700 |
commit | 63337ba4f8c4f31b7da96e9c3669fc29e0a03b49 (patch) | |
tree | 76ba1cc32be325d76819368325ccb5993f992e8d /web | |
parent | 11332eeb33a039b502eb9f94c0f86917653c025f (diff) | |
download | dartboat-63337ba4f8c4f31b7da96e9c3669fc29e0a03b49.tar.gz dartboat-63337ba4f8c4f31b7da96e9c3669fc29e0a03b49.tar.xz |
web: disable back button when installed as a PWA
Diffstat (limited to 'web')
-rw-r--r-- | web/static/dartboat.js | 13 | ||||
-rw-r--r-- | web/static/sw.js | 2 |
2 files changed, 14 insertions, 1 deletions
diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 39e0371..6051b7e 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -197,3 +197,16 @@ document.addEventListener('keydown', e => { if ('serviceWorker' in navigator) navigator.serviceWorker.register('sw.js'); + +// disable back button when installed as a PWA. a single click exits the app, +// destroying match state without confirmation, so we must resort to this. +if (window.matchMedia('(display-mode: standalone)').matches) { + window.addEventListener('load', () => { + if (!history.state) { + history.replaceState(true, ''); + history.pushState(true, ''); + } + }); + + window.addEventListener('popstate', () => history.pushState(true, '')); +} diff --git a/web/static/sw.js b/web/static/sw.js index 7ed7a85..f5d699a 100644 --- a/web/static/sw.js +++ b/web/static/sw.js @@ -1,5 +1,5 @@ const CACHE_PREFIX = 'dartboat-' -const CACHE_VERSION = '2'; +const CACHE_VERSION = '3'; const CACHE_NAME = `${CACHE_PREFIX}${CACHE_VERSION}`; const FILES = [ |