summaryrefslogtreecommitdiff
path: root/packages/client/src/scripts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-01-16 15:02:15 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2022-01-16 15:02:15 +0900
commit3e9677904d25df368bb1038963a914ffa717077d (patch)
tree7cf48641be7ba5609a6cbfd19931924ec4c4173c /packages/client/src/scripts
parentwip: refactor(client): migrate components to composition api (diff)
downloadsharkey-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.ts34
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);
+ });
+ */
+}