Move exportWorkflow from menu to workflowService (#1399)

This commit is contained in:
Chenlei Hu
2024-11-01 19:44:21 -04:00
committed by GitHub
parent d254559e20
commit d719a4e0fb
3 changed files with 42 additions and 36 deletions

View File

@@ -1,9 +1,6 @@
import type { ComfyApp } from '@/scripts/app'
import { $el } from '../../ui'
import { downloadBlob } from '../../utils'
import { ComfyButtonGroup } from '../components/buttonGroup'
import { showPromptDialog } from '@/services/dialogService'
import { useSettingStore } from '@/stores/settingStore'
import './menu.css'
// Export to make sure following components are shimmed and exported by vite
@@ -33,35 +30,4 @@ export class ComfyAppMenu {
this.viewGroup.element
])
}
async getFilename(defaultName: string): Promise<string | null> {
if (useSettingStore().get('Comfy.PromptFilename')) {
let filename = await showPromptDialog({
title: 'Export Workflow',
message: 'Enter the filename:',
defaultValue: defaultName
})
if (!filename) return null
if (!filename.toLowerCase().endsWith('.json')) {
filename += '.json'
}
return filename
}
return defaultName
}
async exportWorkflow(
filename: string,
promptProperty: 'workflow' | 'output'
): Promise<void> {
if (this.app.workflowManager.activeWorkflow?.path) {
filename = this.app.workflowManager.activeWorkflow.name
}
const p = await this.app.graphToPrompt()
const json = JSON.stringify(p[promptProperty], null, 2)
const blob = new Blob([json], { type: 'application/json' })
const file = await this.getFilename(filename)
if (!file) return
downloadBlob(file, blob)
}
}