feat: prevent refreshing when setting passcode

This commit is contained in:
Baptiste Grob
2020-08-26 17:32:00 +02:00
parent c4506a5407
commit 5b72f4e88f
4 changed files with 29 additions and 17 deletions

View File

@@ -135,3 +135,16 @@ if (!Array.prototype.includes) {
}
});
}
export async function preventRefreshing(
message: string,
operation: () => Promise<void> | void
) {
const onBeforeUnload = window.onbeforeunload;
try {
window.onbeforeunload = () => message;
await operation();
} finally {
window.onbeforeunload = onBeforeUnload;
}
}