mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-29 19:26:44 -06:00
63df2c851e
Co-authored-by: tamaina <tamaina@hotmail.co.jp>
45 lines
872 B
TypeScript
45 lines
872 B
TypeScript
import { Ref } from 'vue';
|
|
|
|
export function useLeaveGuard(enabled: Ref<boolean>) {
|
|
/* TODO
|
|
const setLeaveGuard = inject('setLeaveGuard');
|
|
|
|
if (setLeaveGuard) {
|
|
setLeaveGuard(async () => {
|
|
if (!enabled.value) return false;
|
|
|
|
const { canceled } = await os.confirm({
|
|
type: 'warning',
|
|
text: i18n.ts.leaveConfirm,
|
|
});
|
|
|
|
return canceled;
|
|
});
|
|
} else {
|
|
onBeforeRouteLeave(async (to, from) => {
|
|
if (!enabled.value) return true;
|
|
|
|
const { canceled } = await os.confirm({
|
|
type: 'warning',
|
|
text: i18n.ts.leaveConfirm,
|
|
});
|
|
|
|
return !canceled;
|
|
});
|
|
}
|
|
*/
|
|
|
|
/*
|
|
function onBeforeLeave(ev: BeforeUnloadEvent) {
|
|
if (enabled.value) {
|
|
ev.preventDefault();
|
|
ev.returnValue = '';
|
|
}
|
|
}
|
|
|
|
window.addEventListener('beforeunload', onBeforeLeave);
|
|
onUnmounted(() => {
|
|
window.removeEventListener('beforeunload', onBeforeLeave);
|
|
});
|
|
*/
|
|
}
|