Compare commits

...

1 Commits

Author SHA1 Message Date
Benjamin Lu
70b0653864 Handle close confirmation from desktop 2026-02-04 00:29:38 -08:00

View File

@@ -3,6 +3,7 @@ import log from 'loglevel'
import { useExternalLink } from '@/composables/useExternalLink'
import { PYTHON_MIRROR } from '@/constants/uvMirrors'
import { t } from '@/i18n'
import { useSettingStore } from '@/platform/settings/settingStore'
import { useToastStore } from '@/platform/updates/common/toastStore'
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
import { app } from '@/scripts/app'
@@ -12,10 +13,17 @@ import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil'
;(async () => {
if (!isElectron()) return
const electronAPI = getElectronAPI()
type ElectronCloseApi = ReturnType<typeof getElectronAPI> & {
onCloseRequested: (callback: () => void) => () => void
respondToCloseRequest: (allow: boolean) => Promise<boolean>
}
const electronAPI = getElectronAPI() as ElectronCloseApi
const desktopAppVersion = await electronAPI.getElectronVersion()
const workflowStore = useWorkflowStore()
const settingStore = useSettingStore()
const toastStore = useToastStore()
const dialogService = useDialogService()
const { staticUrls, buildDocsUrl } = useExternalLink()
const onChangeRestartApp = (newValue: string, oldValue: string) => {
@@ -25,6 +33,38 @@ import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil'
}
}
const handleCloseRequest = async () => {
try {
await settingStore.load()
const confirmOnClose = settingStore.get('Comfy.Window.UnloadConfirmation')
if (!confirmOnClose) {
await electronAPI.respondToCloseRequest(true)
return
}
if (workflowStore.modifiedWorkflows.length === 0) {
await electronAPI.respondToCloseRequest(true)
return
}
const confirmed = await dialogService.confirm({
message: t('desktopMenu.confirmQuit'),
title: t('desktopMenu.quit'),
type: 'default'
})
await electronAPI.respondToCloseRequest(confirmed === true)
} catch (error) {
log.error('Failed to handle close request.', error)
await electronAPI.respondToCloseRequest(true)
}
}
electronAPI.onCloseRequested(() => {
void handleCloseRequest()
})
app.registerExtension({
name: 'Comfy.ElectronAdapter',
settings: [
@@ -245,18 +285,7 @@ import { electronAPI as getElectronAPI, isElectron } from '@/utils/envUtil'
id: 'Comfy-Desktop.Quit',
label: 'Quit',
icon: 'pi pi-sign-out',
async function() {
// Confirm if unsaved workflows are open
if (workflowStore.modifiedWorkflows.length > 0) {
const confirmed = await useDialogService().confirm({
message: t('desktopMenu.confirmQuit'),
title: t('desktopMenu.quit'),
type: 'default'
})
if (!confirmed) return
}
function() {
electronAPI.quit()
}
}