2023-07-27 05:31:52 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-02-16 14:09:41 +00:00
|
|
|
import { Ref } from 'vue';
|
2022-01-16 06:02:15 +00:00
|
|
|
|
|
|
|
export function useLeaveGuard(enabled: Ref<boolean>) {
|
2022-06-23 15:47:55 +00:00
|
|
|
/* TODO
|
2022-01-16 06:02:15 +00:00
|
|
|
const setLeaveGuard = inject('setLeaveGuard');
|
|
|
|
|
|
|
|
if (setLeaveGuard) {
|
|
|
|
setLeaveGuard(async () => {
|
|
|
|
if (!enabled.value) return false;
|
|
|
|
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.leaveConfirm,
|
2022-01-16 06:02:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return canceled;
|
|
|
|
});
|
2022-01-16 12:31:09 +00:00
|
|
|
} else {
|
|
|
|
onBeforeRouteLeave(async (to, from) => {
|
|
|
|
if (!enabled.value) return true;
|
|
|
|
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.leaveConfirm,
|
2022-01-16 12:31:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return !canceled;
|
|
|
|
});
|
2022-01-16 06:02:15 +00:00
|
|
|
}
|
2022-06-23 15:47:55 +00:00
|
|
|
*/
|
2022-01-16 06:02:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
function onBeforeLeave(ev: BeforeUnloadEvent) {
|
|
|
|
if (enabled.value) {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.returnValue = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('beforeunload', onBeforeLeave);
|
|
|
|
onUnmounted(() => {
|
|
|
|
window.removeEventListener('beforeunload', onBeforeLeave);
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
}
|