Add confirm dialog on window close

This commit is contained in:
huchenlei
2024-08-30 16:05:54 -04:00
committed by Chenlei Hu
parent 70d5e98c73
commit 68d6b1f172
4 changed files with 32 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
<script setup lang="ts">
import { useSettingStore } from '@/stores/settingStore'
import { onMounted, onUnmounted } from 'vue'
const settingStore = useSettingStore()
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
if (settingStore.get('Comfy.Window.UnloadConfirmation')) {
event.preventDefault()
return true
}
return undefined
}
onMounted(() => {
window.addEventListener('beforeunload', handleBeforeUnload)
})
onUnmounted(() => {
window.removeEventListener('beforeunload', handleBeforeUnload)
})
</script>