diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2022-01-16 15:02:15 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2022-01-16 15:02:15 +0900 |
| commit | 3e9677904d25df368bb1038963a914ffa717077d (patch) | |
| tree | 7cf48641be7ba5609a6cbfd19931924ec4c4173c /packages/client/src/scripts | |
| parent | wip: refactor(client): migrate components to composition api (diff) | |
| download | sharkey-3e9677904d25df368bb1038963a914ffa717077d.tar.gz sharkey-3e9677904d25df368bb1038963a914ffa717077d.tar.bz2 sharkey-3e9677904d25df368bb1038963a914ffa717077d.zip | |
wip: refactor(client): migrate components to composition api
Diffstat (limited to 'packages/client/src/scripts')
| -rw-r--r-- | packages/client/src/scripts/use-leave-guard.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/client/src/scripts/use-leave-guard.ts b/packages/client/src/scripts/use-leave-guard.ts new file mode 100644 index 0000000000..21899af59a --- /dev/null +++ b/packages/client/src/scripts/use-leave-guard.ts @@ -0,0 +1,34 @@ +import { inject, onUnmounted, Ref } from 'vue'; +import { i18n } from '@/i18n'; +import * as os from '@/os'; + +export function useLeaveGuard(enabled: Ref<boolean>) { + const setLeaveGuard = inject('setLeaveGuard'); + + if (setLeaveGuard) { + setLeaveGuard(async () => { + if (!enabled.value) return false; + + const { canceled } = await os.confirm({ + type: 'warning', + text: i18n.locale.leaveConfirm, + }); + + return canceled; + }); + } + + /* + function onBeforeLeave(ev: BeforeUnloadEvent) { + if (enabled.value) { + ev.preventDefault(); + ev.returnValue = ''; + } + } + + window.addEventListener('beforeunload', onBeforeLeave); + onUnmounted(() => { + window.removeEventListener('beforeunload', onBeforeLeave); + }); + */ +} |