mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
* Add keybinding schema * nit * Keybinding store * nit * wip * Bind condition on ComfyCommand * Add settings * nit * Revamp keybinding store * Add tests * Add load keybinding * load extension keybindings * Load extension commands * Handle keybindings * test * Keybinding playwright test * Update README * nit * Remove log * Remove system stats fromt logging.ts
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import type { ComfyApp } from '@/scripts/app'
|
|
import { $el } from '../../ui'
|
|
import { downloadBlob } from '../../utils'
|
|
import { ComfyButtonGroup } from '../components/buttonGroup'
|
|
import './menu.css'
|
|
|
|
// Export to make sure following components are shimmed and exported by vite
|
|
export { ComfyButton } from '../components/button'
|
|
export { ComfySplitButton } from '../components/splitButton'
|
|
export { ComfyPopup } from '../components/popup'
|
|
|
|
export class ComfyAppMenu {
|
|
app: ComfyApp
|
|
actionsGroup: ComfyButtonGroup
|
|
settingsGroup: ComfyButtonGroup
|
|
viewGroup: ComfyButtonGroup
|
|
element: HTMLElement
|
|
|
|
constructor(app: ComfyApp) {
|
|
this.app = app
|
|
|
|
// Keep the group as there are custom scripts attaching extra
|
|
// elements to it.
|
|
this.actionsGroup = new ComfyButtonGroup()
|
|
this.settingsGroup = new ComfyButtonGroup()
|
|
this.viewGroup = new ComfyButtonGroup()
|
|
|
|
this.element = $el('div.flex.gap-2.mx-2', [
|
|
this.actionsGroup.element,
|
|
this.settingsGroup.element,
|
|
this.viewGroup.element
|
|
])
|
|
}
|
|
|
|
getFilename(defaultName: string) {
|
|
if (this.app.ui.settings.getSettingValue('Comfy.PromptFilename', true)) {
|
|
defaultName = prompt('Save workflow as:', defaultName)
|
|
if (!defaultName) return
|
|
if (!defaultName.toLowerCase().endsWith('.json')) {
|
|
defaultName += '.json'
|
|
}
|
|
}
|
|
return defaultName
|
|
}
|
|
|
|
async exportWorkflow(
|
|
filename: string,
|
|
promptProperty: 'workflow' | 'output'
|
|
) {
|
|
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 = this.getFilename(filename)
|
|
if (!file) return
|
|
downloadBlob(file, blob)
|
|
}
|
|
}
|