Reverse init order (#227)

This commit is contained in:
Chenlei Hu
2024-07-25 22:20:38 -04:00
committed by GitHub
parent 9d56bb4e0e
commit dc13ed102b
5 changed files with 36 additions and 44 deletions

View File

@@ -2,8 +2,8 @@
<ProgressSpinner v-if="isLoading" class="spinner"></ProgressSpinner> <ProgressSpinner v-if="isLoading" class="spinner"></ProgressSpinner>
<div v-else> <div v-else>
<NodeSearchboxPopover v-if="nodeSearchEnabled" /> <NodeSearchboxPopover v-if="nodeSearchEnabled" />
<teleport to="#graph-canvas-container"> <teleport to=".graph-canvas-container">
<LiteGraphCanvasSplitterOverlay> <LiteGraphCanvasSplitterOverlay v-if="betaMenuEnabled">
<template #side-bar-panel> <template #side-bar-panel>
<SideToolBar /> <SideToolBar />
</template> </template>
@@ -21,7 +21,6 @@ import QueueSideBarTab from '@/components/sidebar/tabs/QueueSideBarTab.vue'
import ProgressSpinner from 'primevue/progressspinner' import ProgressSpinner from 'primevue/progressspinner'
import { app } from './scripts/app' import { app } from './scripts/app'
import { useSettingStore } from './stores/settingStore' import { useSettingStore } from './stores/settingStore'
import { useNodeDefStore } from './stores/nodeDefStore'
import { ExtensionManagerImpl } from './scripts/extensionManager' import { ExtensionManagerImpl } from './scripts/extensionManager'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
@@ -45,13 +44,15 @@ watch(
}, },
{ immediate: true } { immediate: true }
) )
const betaMenuEnabled = computed(
() => useSettingStore().get('Comfy.UseNewMenu') !== 'Disabled'
)
const { t } = useI18n() const { t } = useI18n()
const init = () => { const init = () => {
useNodeDefStore().addNodeDefs(Object.values(app.nodeDefs))
useSettingStore().addSettings(app.ui.settings) useSettingStore().addSettings(app.ui.settings)
app.vueAppReady = true app.vueAppReady = true
// Late init as extension manager needs to access pinia store. // lazy init as extension manager needs to access pinia store.
app.extensionManager = new ExtensionManagerImpl() app.extensionManager = new ExtensionManagerImpl()
app.extensionManager.registerSidebarTab({ app.extensionManager.registerSidebarTab({
id: 'queue', id: 'queue',

View File

@@ -90,7 +90,7 @@ body {
display: flex; display: flex;
} }
#graph-canvas-container { .graph-canvas-container {
width: 100%; width: 100%;
height: 100%; height: 100%;
order: -3; order: -3;

View File

@@ -38,8 +38,7 @@
import SideBarIcon from './SideBarIcon.vue' import SideBarIcon from './SideBarIcon.vue'
import SideBarThemeToggleIcon from './SideBarThemeToggleIcon.vue' import SideBarThemeToggleIcon from './SideBarThemeToggleIcon.vue'
import SideBarSettingsToggleIcon from './SideBarSettingsToggleIcon.vue' import SideBarSettingsToggleIcon from './SideBarSettingsToggleIcon.vue'
import { computed, onBeforeUnmount, watch } from 'vue' import { computed, onBeforeUnmount } from 'vue'
import { useSettingStore } from '@/stores/settingStore'
import { app } from '@/scripts/app' import { app } from '@/scripts/app'
import { useWorkspaceStore } from '@/stores/workspaceStateStore' import { useWorkspaceStore } from '@/stores/workspaceStateStore'
import { import {
@@ -61,15 +60,6 @@ const onTabClick = (item: SidebarTabExtension) => {
workspaceStateStore.activeSidebarTab === item.id ? null : item.id workspaceStateStore.activeSidebarTab === item.id ? null : item.id
) )
} }
const betaMenuEnabled = computed(
() => useSettingStore().get('Comfy.UseNewMenu') !== 'Disabled'
)
watch(betaMenuEnabled, (newValue) => {
if (!newValue) {
workspaceStateStore.updateActiveSidebarTab(null)
}
})
onBeforeUnmount(() => { onBeforeUnmount(() => {
tabs.value.forEach((tab) => { tabs.value.forEach((tab) => {
if (tab.type === 'custom' && tab.destroy) { if (tab.type === 'custom' && tab.destroy) {

View File

@@ -21,28 +21,27 @@ const ComfyUIPreset = definePreset(Aura, {
const app = createApp(App) const app = createApp(App)
const pinia = createPinia() const pinia = createPinia()
app.directive('tooltip', Tooltip)
app
.use(PrimeVue, {
theme: {
preset: ComfyUIPreset,
options: {
prefix: 'p',
cssLayer: false,
// This is a workaround for the issue with the dark mode selector
// https://github.com/primefaces/primevue/issues/5515
darkModeSelector: '.dark-theme, :root:has(.dark-theme)'
}
}
})
.use(ConfirmationService)
.use(ToastService)
.use(pinia)
.use(i18n)
.mount('#vue-app')
comfyApp.setup().then(() => { comfyApp.setup().then(() => {
window['app'] = comfyApp window['app'] = comfyApp
window['graph'] = comfyApp.graph window['graph'] = comfyApp.graph
app.directive('tooltip', Tooltip)
app
.use(PrimeVue, {
theme: {
preset: ComfyUIPreset,
options: {
prefix: 'p',
cssLayer: false,
// This is a workaround for the issue with the dark mode selector
// https://github.com/primefaces/primevue/issues/5515
darkModeSelector: '.dark-theme, :root:has(.dark-theme)'
}
}
})
.use(ConfirmationService)
.use(ToastService)
.use(pinia)
.use(i18n)
.mount('#vue-app')
}) })

View File

@@ -36,6 +36,7 @@ import { StorageLocation } from '@/types/settingTypes'
import '@comfyorg/litegraph/css/litegraph.css' import '@comfyorg/litegraph/css/litegraph.css'
import '../assets/css/style.css' import '../assets/css/style.css'
import { ExtensionManager } from '@/types/extensionTypes' import { ExtensionManager } from '@/types/extensionTypes'
import { useNodeDefStore } from '@/stores/nodeDefStore'
export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview' export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview'
@@ -117,8 +118,8 @@ export class ComfyApp {
bodyLeft: HTMLElement bodyLeft: HTMLElement
bodyRight: HTMLElement bodyRight: HTMLElement
bodyBottom: HTMLElement bodyBottom: HTMLElement
canvasContainer: HTMLElement
menu: ComfyAppMenu menu: ComfyAppMenu
nodeDefs: Record<string, ComfyNodeDef>
constructor() { constructor() {
this.vueAppReady = false this.vueAppReady = false
@@ -129,6 +130,9 @@ export class ComfyApp {
this.bodyLeft = $el('div.comfyui-body-left', { parent: document.body }) this.bodyLeft = $el('div.comfyui-body-left', { parent: document.body })
this.bodyRight = $el('div.comfyui-body-right', { parent: document.body }) this.bodyRight = $el('div.comfyui-body-right', { parent: document.body })
this.bodyBottom = $el('div.comfyui-body-bottom', { parent: document.body }) this.bodyBottom = $el('div.comfyui-body-bottom', { parent: document.body })
this.canvasContainer = $el('div.graph-canvas-container', {
parent: document.body
})
this.menu = new ComfyAppMenu(this) this.menu = new ComfyAppMenu(this)
/** /**
@@ -1847,17 +1851,13 @@ export class ComfyApp {
await this.#setUser() await this.#setUser()
// Create and mount the LiteGraph in the DOM // Create and mount the LiteGraph in the DOM
const canvasContainer = document.createElement('div')
canvasContainer.id = 'graph-canvas-container'
const mainCanvas = document.createElement('canvas') const mainCanvas = document.createElement('canvas')
mainCanvas.style.touchAction = 'none' mainCanvas.style.touchAction = 'none'
const canvasEl = (this.canvasEl = Object.assign(mainCanvas, { const canvasEl = (this.canvasEl = Object.assign(mainCanvas, {
id: 'graph-canvas' id: 'graph-canvas'
})) }))
canvasEl.tabIndex = 1 canvasEl.tabIndex = 1
canvasContainer.prepend(canvasEl) this.canvasContainer.prepend(canvasEl)
document.body.prepend(canvasContainer)
this.resizeCanvas() this.resizeCanvas()
@@ -1965,7 +1965,9 @@ export class ComfyApp {
async registerNodes() { async registerNodes() {
// Load node definitions from the backend // Load node definitions from the backend
const defs = await api.getNodeDefs() const defs = await api.getNodeDefs()
this.nodeDefs = defs if (this.vueAppReady) {
useNodeDefStore().addNodeDefs(Object.values(defs))
}
await this.registerNodesFromDefs(defs) await this.registerNodesFromDefs(defs)
await this.#invokeExtensionsAsync('registerCustomNodes') await this.#invokeExtensionsAsync('registerCustomNodes')
} }