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

@@ -3,6 +3,7 @@
<BlockUI full-screen :blocked="isLoading" />
<GlobalDialog />
<GlobalToast />
<UnloadWindowConfirmDialog />
<GraphCanvas />
</template>
@@ -26,6 +27,7 @@ import { useWorkspaceStore } from './stores/workspaceStateStore'
import NodeLibrarySidebarTab from './components/sidebar/tabs/NodeLibrarySidebarTab.vue'
import GlobalDialog from './components/dialog/GlobalDialog.vue'
import GlobalToast from './components/toast/GlobalToast.vue'
import UnloadWindowConfirmDialog from './components/dialog/UnloadWindowConfirmDialog.vue'
import { api } from './scripts/api'
import { StatusWsMessageStatus } from './types/apiTypes'
import { useQueuePendingTaskCountStore } from './stores/queueStore'

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>

View File

@@ -260,6 +260,13 @@ export const useSettingStore = defineStore('setting', {
type: 'boolean',
defaultValue: true
})
app.ui.settings.addSetting({
id: 'Comfy.Window.UnloadConfirmation',
name: 'Show confirmation when closing window',
type: 'boolean',
defaultValue: false
})
},
set<K extends keyof Settings>(key: K, value: Settings[K]) {

View File

@@ -469,7 +469,8 @@ const zSettings = z.record(z.any()).and(
'Comfy.Queue.ImageFit': z.enum(['contain', 'cover']),
'Comfy.Workflow.ModelDownload.AllowedSources': z.array(z.string()),
'Comfy.Workflow.ModelDownload.AllowedSuffixes': z.array(z.string()),
'Comfy.Node.DoubleClickTitleToEdit': z.boolean()
'Comfy.Node.DoubleClickTitleToEdit': z.boolean(),
'Comfy.Window.UnloadConfirmation': z.boolean()
})
.optional()
)