mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-22 15:29:44 +00:00
Re-enable keybinding jest test (#2090)
This commit is contained in:
@@ -2,16 +2,19 @@ import { app } from '@/scripts/app'
|
||||
import { api } from '@/scripts/api'
|
||||
import { useCommandStore } from '@/stores/commandStore'
|
||||
import { useExtensionStore } from '@/stores/extensionStore'
|
||||
import { useKeybindingStore } from '@/stores/keybindingStore'
|
||||
import { KeybindingImpl, useKeybindingStore } from '@/stores/keybindingStore'
|
||||
import { useMenuItemStore } from '@/stores/menuItemStore'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
import { useWidgetStore } from '@/stores/widgetStore'
|
||||
import { useBottomPanelStore } from '@/stores/workspace/bottomPanelStore'
|
||||
import type { ComfyExtension } from '@/types/comfy'
|
||||
import { useErrorHandling } from '@/hooks/errorHooks'
|
||||
|
||||
export const useExtensionService = () => {
|
||||
const extensionStore = useExtensionStore()
|
||||
const settingStore = useSettingStore()
|
||||
const keybindingStore = useKeybindingStore()
|
||||
const { wrapWithErrorHandling } = useErrorHandling()
|
||||
|
||||
/**
|
||||
* Loads all extensions from the API into the window in parallel
|
||||
@@ -47,12 +50,17 @@ export const useExtensionService = () => {
|
||||
const registerExtension = (extension: ComfyExtension) => {
|
||||
extensionStore.registerExtension(extension)
|
||||
|
||||
useKeybindingStore().loadExtensionKeybindings(extension)
|
||||
const addKeybinding = wrapWithErrorHandling(
|
||||
keybindingStore.addDefaultKeybinding
|
||||
)
|
||||
const addSetting = wrapWithErrorHandling(settingStore.addSetting)
|
||||
|
||||
extension.keybindings?.forEach((keybinding) => {
|
||||
addKeybinding(new KeybindingImpl(keybinding))
|
||||
})
|
||||
useCommandStore().loadExtensionCommands(extension)
|
||||
useMenuItemStore().loadExtensionMenuCommands(extension)
|
||||
extension.settings?.forEach((setting) => {
|
||||
settingStore.addSetting(setting)
|
||||
})
|
||||
extension.settings?.forEach(addSetting)
|
||||
useBottomPanelStore().registerExtensionBottomPanelTabs(extension)
|
||||
if (extension.getCustomWidgets) {
|
||||
// TODO(huchenlei): We should deprecate the async return value of
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { CORE_KEYBINDINGS } from '@/constants/coreKeybindings'
|
||||
import { useCommandStore } from '@/stores/commandStore'
|
||||
import { KeyComboImpl, useKeybindingStore } from '@/stores/keybindingStore'
|
||||
import {
|
||||
KeybindingImpl,
|
||||
KeyComboImpl,
|
||||
useKeybindingStore
|
||||
} from '@/stores/keybindingStore'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
|
||||
export const useKeybindingService = () => {
|
||||
const keybindingStore = useKeybindingStore()
|
||||
const commandStore = useCommandStore()
|
||||
const settingStore = useSettingStore()
|
||||
|
||||
const keybindHandler = async function (event: KeyboardEvent) {
|
||||
const keyCombo = KeyComboImpl.fromEvent(event)
|
||||
@@ -54,7 +61,41 @@ export const useKeybindingService = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const registerCoreKeybindings = () => {
|
||||
for (const keybinding of CORE_KEYBINDINGS) {
|
||||
keybindingStore.addDefaultKeybinding(new KeybindingImpl(keybinding))
|
||||
}
|
||||
}
|
||||
|
||||
function registerUserKeybindings() {
|
||||
// Unset bindings first as new bindings might conflict with default bindings.
|
||||
const unsetBindings = settingStore.get('Comfy.Keybinding.UnsetBindings')
|
||||
for (const keybinding of unsetBindings) {
|
||||
keybindingStore.unsetKeybinding(new KeybindingImpl(keybinding))
|
||||
}
|
||||
const newBindings = settingStore.get('Comfy.Keybinding.NewBindings')
|
||||
for (const keybinding of newBindings) {
|
||||
keybindingStore.addUserKeybinding(new KeybindingImpl(keybinding))
|
||||
}
|
||||
}
|
||||
|
||||
async function persistUserKeybindings() {
|
||||
// TODO(https://github.com/Comfy-Org/ComfyUI_frontend/issues/1079):
|
||||
// Allow setting multiple values at once in settingStore
|
||||
await settingStore.set(
|
||||
'Comfy.Keybinding.NewBindings',
|
||||
Object.values(keybindingStore.userKeybindings.value)
|
||||
)
|
||||
await settingStore.set(
|
||||
'Comfy.Keybinding.UnsetBindings',
|
||||
Object.values(keybindingStore.userUnsetKeybindings.value)
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
keybindHandler
|
||||
keybindHandler,
|
||||
registerCoreKeybindings,
|
||||
registerUserKeybindings,
|
||||
persistUserKeybindings
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user