Skip to content

Commit 58906fa

Browse files
authored
[CodeHealth] Remove remaining uses of global app var (#3868)
1 parent a17fb04 commit 58906fa

File tree

7 files changed

+19
-10
lines changed

7 files changed

+19
-10
lines changed

src/components/graph/GraphCanvas.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,8 @@ onMounted(async () => {
292292
canvasStore.canvas.render_canvas_border = false
293293
workspaceStore.spinner = false
294294
295-
// @ts-expect-error fixme ts strict error
296-
window['app'] = comfyApp
297-
// @ts-expect-error fixme ts strict error
298-
window['graph'] = comfyApp.graph
295+
window.app = comfyApp
296+
window.graph = comfyApp.graph
299297
300298
comfyAppReady.value = true
301299

src/components/graph/SelectionOverlay.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ watch(
7979
if (draggingItems === false) {
8080
setTimeout(() => {
8181
visible.value = true
82-
positionSelectionOverlay(canvasStore.canvas as LGraphCanvas)
82+
positionSelectionOverlay(canvasStore.getCanvas())
8383
}, 100)
8484
} else {
8585
// Selection change update to visible state is delayed by a frame. Here

src/composables/widgets/useImagePreviewWidget.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
import type { InputSpec } from '@/schemas/nodeDef/nodeDefSchemaV2'
99
import { calculateImageGrid } from '@/scripts/ui/imagePreview'
1010
import { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
11+
import { useCanvasStore } from '@/stores/graphStore'
1112
import { useSettingStore } from '@/stores/settingStore'
1213
import { is_all_same_aspect_ratio } from '@/utils/imageUtil'
1314

@@ -16,7 +17,7 @@ const renderPreview = (
1617
node: LGraphNode,
1718
shiftY: number
1819
) => {
19-
const canvas = app.canvas
20+
const canvas = useCanvasStore().getCanvas()
2021
const mouse = canvas.graph_mouse
2122

2223
if (!canvas.pointer_is_down && node.pointerDown) {

src/extensions/core/previewAny.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Preview Any - original implement from
33
https://github.com/rgthree/rgthree-comfy/blob/main/py/display_any.py
44
upstream requested in https://github.com/Kosinkadink/rfcs/blob/main/rfcs/0000-corenodes.md#preview-nodes
55
*/
6+
import { app } from '@/scripts/app'
67
import { DOMWidget } from '@/scripts/domWidget'
78
import { ComfyWidgets } from '@/scripts/widgets'
89
import { useExtensionService } from '@/services/extensionService'

src/stores/executionStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
NodeId
1818
} from '@/schemas/comfyWorkflowSchema'
1919
import { api } from '@/scripts/api'
20+
import { app } from '@/scripts/app'
2021

2122
import { ComfyWorkflow } from './workflowStore'
2223

src/stores/graphStore.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { LGraphCanvas, LGraphGroup, LGraphNode } from '@comfyorg/litegraph'
22
import type { Positionable } from '@comfyorg/litegraph/dist/interfaces'
33
import { defineStore } from 'pinia'
4-
import { markRaw, ref, shallowRef } from 'vue'
4+
import { type Raw, markRaw, ref, shallowRef } from 'vue'
55

66
export const useTitleEditorStore = defineStore('titleEditor', () => {
77
const titleEditorTarget = shallowRef<LGraphNode | LGraphGroup | null>(null)
@@ -15,13 +15,13 @@ export const useCanvasStore = defineStore('canvas', () => {
1515
/**
1616
* The LGraphCanvas instance.
1717
*
18-
* The root LGraphCanvas object is shallow reactive.
18+
* The root LGraphCanvas object is a shallow ref.
1919
*/
2020
const canvas = shallowRef<LGraphCanvas | null>(null)
2121
/**
2222
* The selected items on the canvas. All stored items are raw.
2323
*/
24-
const selectedItems = ref<Positionable[]>([])
24+
const selectedItems = ref<Raw<Positionable>[]>([])
2525
const updateSelectedItems = () => {
2626
const items = Array.from(canvas.value?.selectedItems ?? [])
2727
selectedItems.value = items.map((item) => markRaw(item))

src/types/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { LGraph } from '@comfyorg/litegraph'
2+
13
import type {
24
DeviceStats,
35
EmbeddingsResponse,
@@ -54,5 +56,11 @@ export type {
5456
}
5557

5658
declare global {
57-
const app: ComfyApp
59+
interface Window {
60+
/** For use by extensions and in the browser console. Where possible, import `app` from '@/scripts/app' instead. */
61+
app?: ComfyApp
62+
63+
/** For use by extensions and in the browser console. Where possible, import `app` and access via `app.graph` instead. */
64+
graph?: LGraph
65+
}
5866
}

0 commit comments

Comments
 (0)