Files
ComfyUI_frontend/src/scripts/ui/menu/index.ts
Chenlei Hu 77aaa38a92 [Extension API] Custom commands and keybindings (#1075)
* 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
2024-10-02 21:38:04 -04:00

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)
}
}