"vscode:/vscode.git/clone" did not exist on "9bdc254456a2385c580622606d42e7b759f59231"
ui.js 17.2 KB
Newer Older
1
2
import { api } from "./api.js";
import { ComfyDialog as _ComfyDialog } from "./ui/dialog.js";
pythongosssss's avatar
pythongosssss committed
3
import { toggleSwitch } from "./ui/toggleSwitch.js";
4
5
6
import { ComfySettingsDialog } from "./ui/settings.js";

export const ComfyDialog = _ComfyDialog;
pythongosssss's avatar
pythongosssss committed
7

pythongosssss's avatar
pythongosssss committed
8
/**
9
10
11
12
13
14
15
16
 * @template { string | (keyof HTMLElementTagNameMap) } K
 * @typedef { K extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[K] : HTMLElement } ElementType 
 */

/**
 * @template { string | (keyof HTMLElementTagNameMap) } K 
 * @param { K } tag HTML Element Tag and optional classes e.g. div.class1.class2
 * @param { string | Element | Element[] | ({
pythongosssss's avatar
pythongosssss committed
17
 * 	 parent?: Element,
18
 *   $?: (el: ElementType<K>) => void, 
pythongosssss's avatar
pythongosssss committed
19
 *   dataset?: DOMStringMap,
20
 *   style?: Partial<CSSStyleDeclaration>,
pythongosssss's avatar
pythongosssss committed
21
 * 	 for?: string
22
23
24
 * } & Omit<Partial<ElementType<K>>, "style">) | undefined } [propsOrChildren]
 * @param { string | Element | Element[] | undefined } [children]
 * @returns { ElementType<K> }
pythongosssss's avatar
pythongosssss committed
25
 */
Jairo Correa's avatar
Jairo Correa committed
26
export function $el(tag, propsOrChildren, children) {
pythongosssss's avatar
pythongosssss committed
27
28
	const split = tag.split(".");
	const element = document.createElement(split.shift());
reaper47's avatar
reaper47 committed
29
30
31
32
	if (split.length > 0) {
		element.classList.add(...split);
	}

pythongosssss's avatar
pythongosssss committed
33
	if (propsOrChildren) {
pythongosssss's avatar
pythongosssss committed
34
35
36
37
38
		if (typeof propsOrChildren === "string") {
			propsOrChildren = { textContent: propsOrChildren };
		} else if (propsOrChildren instanceof Element) {
			propsOrChildren = [propsOrChildren];
		}
pythongosssss's avatar
pythongosssss committed
39
40
41
		if (Array.isArray(propsOrChildren)) {
			element.append(...propsOrChildren);
		} else {
reaper47's avatar
reaper47 committed
42
			const {parent, $: cb, dataset, style} = propsOrChildren;
pythongosssss's avatar
pythongosssss committed
43
44
			delete propsOrChildren.parent;
			delete propsOrChildren.$;
45
46
			delete propsOrChildren.dataset;
			delete propsOrChildren.style;
pythongosssss's avatar
pythongosssss committed
47

reaper47's avatar
reaper47 committed
48
49
50
51
			if (Object.hasOwn(propsOrChildren, "for")) {
				element.setAttribute("for", propsOrChildren.for)
			}

52
53
54
55
56
57
			if (style) {
				Object.assign(element.style, style);
			}

			if (dataset) {
				Object.assign(element.dataset, dataset);
pythongosssss's avatar
pythongosssss committed
58
59
			}

pythongosssss's avatar
pythongosssss committed
60
61
			Object.assign(element, propsOrChildren);
			if (children) {
62
				element.append(...(children instanceof Array ? children.filter(Boolean) : [children]));
pythongosssss's avatar
pythongosssss committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
			}

			if (parent) {
				parent.append(element);
			}

			if (cb) {
				cb(element);
			}
		}
	}
	return element;
}

77
function dragElement(dragEl, settings) {
78
79
80
81
82
83
	var posDiffX = 0,
		posDiffY = 0,
		posStartX = 0,
		posStartY = 0,
		newPosX = 0,
		newPosY = 0;
84
	if (dragEl.getElementsByClassName("drag-handle")[0]) {
Jairo Correa's avatar
Jairo Correa committed
85
		// if present, the handle is where you move the DIV from:
86
		dragEl.getElementsByClassName("drag-handle")[0].onmousedown = dragMouseDown;
Jairo Correa's avatar
Jairo Correa committed
87
88
89
90
91
	} else {
		// otherwise, move the DIV from anywhere inside the DIV:
		dragEl.onmousedown = dragMouseDown;
	}

pythongosssss's avatar
pythongosssss committed
92
93
94
95
96
	// When the element resizes (e.g. view queue) ensure it is still in the windows bounds
	const resizeObserver = new ResizeObserver(() => {
		ensureInBounds();
	}).observe(dragEl);

97
	function ensureInBounds() {
98
		try {
pythongosssss's avatar
pythongosssss committed
99
100
			newPosX = Math.min(document.body.clientWidth - dragEl.clientWidth, Math.max(0, dragEl.offsetLeft));
			newPosY = Math.min(document.body.clientHeight - dragEl.clientHeight, Math.max(0, dragEl.offsetTop));
101

pythongosssss's avatar
pythongosssss committed
102
103
			positionElement();
		}
104
105
106
		catch(exception){
			// robust
		}
pythongosssss's avatar
pythongosssss committed
107
	}
108
109

	function positionElement() {
110
111
		if(dragEl.style.display === "none") return;

112
113
114
115
116
117
118
119
120
121
122
		const halfWidth = document.body.clientWidth / 2;
		const anchorRight = newPosX + dragEl.clientWidth / 2 > halfWidth;

		// set the element's new position:
		if (anchorRight) {
			dragEl.style.left = "unset";
			dragEl.style.right = document.body.clientWidth - newPosX - dragEl.clientWidth + "px";
		} else {
			dragEl.style.left = newPosX + "px";
			dragEl.style.right = "unset";
		}
123

pythongosssss's avatar
pythongosssss committed
124
125
		dragEl.style.top = newPosY + "px";
		dragEl.style.bottom = "unset";
126
127
128
129
130

		if (savePos) {
			localStorage.setItem(
				"Comfy.MenuPosition",
				JSON.stringify({
pythongosssss's avatar
pythongosssss committed
131
132
					x: dragEl.offsetLeft,
					y: dragEl.offsetTop,
133
134
135
136
137
138
139
140
141
				})
			);
		}
	}

	function restorePos() {
		let pos = localStorage.getItem("Comfy.MenuPosition");
		if (pos) {
			pos = JSON.parse(pos);
pythongosssss's avatar
pythongosssss committed
142
143
144
			newPosX = pos.x;
			newPosY = pos.y;
			positionElement();
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
			ensureInBounds();
		}
	}

	let savePos = undefined;
	settings.addSetting({
		id: "Comfy.MenuPosition",
		name: "Save menu position",
		type: "boolean",
		defaultValue: savePos,
		onChange(value) {
			if (savePos === undefined && value) {
				restorePos();
			}
			savePos = value;
		},
	});
reaper47's avatar
reaper47 committed
162

Jairo Correa's avatar
Jairo Correa committed
163
164
165
166
	function dragMouseDown(e) {
		e = e || window.event;
		e.preventDefault();
		// get the mouse cursor position at startup:
167
168
		posStartX = e.clientX;
		posStartY = e.clientY;
Jairo Correa's avatar
Jairo Correa committed
169
170
171
172
173
174
175
176
		document.onmouseup = closeDragElement;
		// call a function whenever the cursor moves:
		document.onmousemove = elementDrag;
	}

	function elementDrag(e) {
		e = e || window.event;
		e.preventDefault();
177
178
179

		dragEl.classList.add("comfy-menu-manual-pos");

Jairo Correa's avatar
Jairo Correa committed
180
		// calculate the new cursor position:
181
182
183
184
		posDiffX = e.clientX - posStartX;
		posDiffY = e.clientY - posStartY;
		posStartX = e.clientX;
		posStartY = e.clientY;
185
186
187
188
189

		newPosX = Math.min(document.body.clientWidth - dragEl.clientWidth, Math.max(0, dragEl.offsetLeft + posDiffX));
		newPosY = Math.min(document.body.clientHeight - dragEl.clientHeight, Math.max(0, dragEl.offsetTop + posDiffY));

		positionElement();
Jairo Correa's avatar
Jairo Correa committed
190
191
	}

192
	window.addEventListener("resize", () => {
193
		ensureInBounds();
194
195
	});

Jairo Correa's avatar
Jairo Correa committed
196
197
198
199
200
	function closeDragElement() {
		// stop moving when mouse button is released:
		document.onmouseup = null;
		document.onmousemove = null;
	}
201
202

	return restorePos;
Jairo Correa's avatar
Jairo Correa committed
203
204
}

pythongosssss's avatar
pythongosssss committed
205
class ComfyList {
pythongosssss's avatar
pythongosssss committed
206
207
	#type;
	#text;
208
	#reverse;
pythongosssss's avatar
pythongosssss committed
209

210
	constructor(text, type, reverse) {
pythongosssss's avatar
pythongosssss committed
211
212
		this.#text = text;
		this.#type = type || text.toLowerCase();
213
		this.#reverse = reverse || false;
pythongosssss's avatar
pythongosssss committed
214
		this.element = $el("div.comfy-list");
pythongosssss's avatar
pythongosssss committed
215
216
217
218
219
220
221
222
		this.element.style.display = "none";
	}

	get visible() {
		return this.element.style.display !== "none";
	}

	async load() {
pythongosssss's avatar
pythongosssss committed
223
224
225
226
227
228
229
		const items = await api.getItems(this.#type);
		this.element.replaceChildren(
			...Object.keys(items).flatMap((section) => [
				$el("h4", {
					textContent: section,
				}),
				$el("div.comfy-list-items", [
230
					...(this.#reverse ? items[section].reverse() : items[section]).map((item) => {
pythongosssss's avatar
pythongosssss committed
231
232
233
234
235
						// Allow items to specify a custom remove action (e.g. for interrupt current prompt)
						const removeAction = item.remove || {
							name: "Delete",
							cb: () => api.deleteItem(this.#type, item.prompt[1]),
						};
reaper47's avatar
reaper47 committed
236
						return $el("div", {textContent: item.prompt[0] + ": "}, [
pythongosssss's avatar
pythongosssss committed
237
238
							$el("button", {
								textContent: "Load",
pythongosssss's avatar
pythongosssss committed
239
								onclick: async () => {
240
									await app.loadGraphData(item.prompt[3].extra_pnginfo.workflow, true, false);
pythongosssss's avatar
pythongosssss committed
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
									if (item.outputs) {
										app.nodeOutputs = item.outputs;
									}
								},
							}),
							$el("button", {
								textContent: removeAction.name,
								onclick: async () => {
									await removeAction.cb();
									await this.update();
								},
							}),
						]);
					}),
				]),
			]),
			$el("div.comfy-list-actions", [
				$el("button", {
					textContent: "Clear " + this.#text,
					onclick: async () => {
						await api.clearItems(this.#type);
						await this.load();
					},
				}),
reaper47's avatar
reaper47 committed
265
				$el("button", {textContent: "Refresh", onclick: () => this.load()}),
pythongosssss's avatar
pythongosssss committed
266
267
			])
		);
pythongosssss's avatar
pythongosssss committed
268
269
270
271
272
273
274
275
276
277
	}

	async update() {
		if (this.visible) {
			await this.load();
		}
	}

	async show() {
		this.element.style.display = "block";
pythongosssss's avatar
pythongosssss committed
278
279
		this.button.textContent = "Close";

pythongosssss's avatar
pythongosssss committed
280
281
282
283
284
		await this.load();
	}

	hide() {
		this.element.style.display = "none";
comfyanonymous's avatar
comfyanonymous committed
285
		this.button.textContent = "View " + this.#text;
pythongosssss's avatar
pythongosssss committed
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
	}

	toggle() {
		if (this.visible) {
			this.hide();
			return false;
		} else {
			this.show();
			return true;
		}
	}
}

export class ComfyUI {
	constructor(app) {
		this.app = app;
		this.dialog = new ComfyDialog();
303
		this.settings = new ComfySettingsDialog(app);
pythongosssss's avatar
pythongosssss committed
304

m957ymj75urz's avatar
m957ymj75urz committed
305
		this.batchCount = 1;
comfyanonymous's avatar
comfyanonymous committed
306
		this.lastQueueSize = 0;
pythongosssss's avatar
pythongosssss committed
307
		this.queue = new ComfyList("Queue");
308
		this.history = new ComfyList("History", "history", true);
pythongosssss's avatar
pythongosssss committed
309

pythongosssss's avatar
pythongosssss committed
310
311
312
313
		api.addEventListener("status", () => {
			this.queue.update();
			this.history.update();
		});
pythongosssss's avatar
pythongosssss committed
314

315
316
317
318
319
320
		const confirmClear = this.settings.addSetting({
			id: "Comfy.ConfirmClear",
			name: "Require confirmation when clearing workflow",
			type: "boolean",
			defaultValue: true,
		});
321

322
323
324
325
326
327
328
		const promptFilename = this.settings.addSetting({
			id: "Comfy.PromptFilename",
			name: "Prompt for filename when saving workflow",
			type: "boolean",
			defaultValue: true,
		});

329
330
331
		/**
		 * file format for preview
		 *
332
		 * format;quality
333
334
		 *
		 * ex)
335
		 * webp;50 -> webp, quality 50
336
337
338
339
340
341
		 * jpeg;80 -> rgb, jpeg, quality 80
		 *
		 * @type {string}
		 */
		const previewImage = this.settings.addSetting({
			id: "Comfy.PreviewFormat",
reaper47's avatar
reaper47 committed
342
343
			name: "When displaying a preview in the image widget, convert it to a lightweight image, e.g. webp, jpeg, webp;50, etc.",
			type: "text",
344
345
346
			defaultValue: "",
		});

347
348
349
350
351
352
353
		this.settings.addSetting({
			id: "Comfy.DisableSliders",
			name: "Disable sliders.",
			type: "boolean",
			defaultValue: false,
		});

354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
		this.settings.addSetting({
			id: "Comfy.DisableFloatRounding",
			name: "Disable rounding floats (requires page reload).",
			type: "boolean",
			defaultValue: false,
		});

		this.settings.addSetting({
			id: "Comfy.FloatRoundingPrecision",
			name: "Decimal places [0 = auto] (requires page reload).",
			type: "slider",
			attrs: {
				min: 0,
				max: 6,
				step: 1,
			},
			defaultValue: 0,
		});

pythongosssss's avatar
pythongosssss committed
373
		const fileInput = $el("input", {
374
			id: "comfy-file-input",
pythongosssss's avatar
pythongosssss committed
375
			type: "file",
376
			accept: ".json,image/png,.latent,.safetensors,image/webp,audio/flac",
reaper47's avatar
reaper47 committed
377
			style: {display: "none"},
pythongosssss's avatar
pythongosssss committed
378
379
380
381
			parent: document.body,
			onchange: () => {
				app.handleFile(fileInput.files[0]);
			},
pythongosssss's avatar
pythongosssss committed
382
		});
pythongosssss's avatar
pythongosssss committed
383

384
385
		this.loadFile = () => fileInput.click();

pythongosssss's avatar
pythongosssss committed
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
		const autoQueueModeEl = toggleSwitch(
			"autoQueueMode",
			[
				{ text: "instant", tooltip: "A new prompt will be queued as soon as the queue reaches 0" },
				{ text: "change", tooltip: "A new prompt will be queued when the queue is at 0 and the graph is/has changed" },
			],
			{
				onChange: (value) => {
					this.autoQueueMode = value.item.value;
				},
			}
		);
		autoQueueModeEl.style.display = "none";

		api.addEventListener("graphChanged", () => {
401
			if (this.autoQueueMode === "change" && this.autoQueueEnabled === true) {
pythongosssss's avatar
pythongosssss committed
402
403
404
405
406
407
408
409
410
				if (this.lastQueueSize === 0) {
					this.graphHasChanged = false;
					app.queuePrompt(0, this.batchCount);
				} else {
					this.graphHasChanged = true;
				}
			}
		});

pythongosssss's avatar
pythongosssss committed
411
412
413
414
415
416
417
418
419
420
421
422
423
424
		this.menuHamburger = $el(
			"div.comfy-menu-hamburger",
			{
				parent: document.body,
				onclick: () => {
					this.menuContainer.style.display = "block";
					this.menuHamburger.style.display = "none";
				},
			},
			[$el("div"), $el("div"), $el("div")]
		);

		this.menuContainer = $el("div.comfy-menu", { parent: document.body }, [
			$el("div.drag-handle.comfy-menu-header", {
reaper47's avatar
reaper47 committed
425
426
427
428
429
430
				style: {
					overflow: "hidden",
					position: "relative",
					width: "100%",
					cursor: "default"
				}
pythongosssss's avatar
pythongosssss committed
431
			}, 	[
Jairo Correa's avatar
Jairo Correa committed
432
				$el("span.drag-handle"),
pythongosssss's avatar
pythongosssss committed
433
434
435
436
437
438
439
440
441
442
443
444
445
446
				$el("span.comfy-menu-queue-size", { $: (q) => (this.queueSize = q) }),
				$el("div.comfy-menu-actions", [
					$el("button.comfy-settings-btn", {
						textContent: "⚙️",
						onclick: () => this.settings.show(),
					}),
					$el("button.comfy-close-menu-btn", {
						textContent: "\u00d7",
						onclick: () => {
							this.menuContainer.style.display = "none";
							this.menuHamburger.style.display = "flex";
						},
					}),
				]),
pythongosssss's avatar
pythongosssss committed
447
			]),
448
			$el("button.comfy-queue-btn", {
449
				id: "queue-button",
450
451
452
				textContent: "Queue Prompt",
				onclick: () => app.queuePrompt(0, this.batchCount),
			}),
m957ymj75urz's avatar
m957ymj75urz committed
453
			$el("div", {}, [
reaper47's avatar
reaper47 committed
454
				$el("label", {innerHTML: "Extra options"}, [
455
456
457
458
459
460
					$el("input", {
						type: "checkbox",
						onchange: (i) => {
							document.getElementById("extraOptions").style.display = i.srcElement.checked ? "block" : "none";
							this.batchCount = i.srcElement.checked ? document.getElementById("batchCountInputRange").value : 1;
							document.getElementById("autoQueueCheckbox").checked = false;
pythongosssss's avatar
pythongosssss committed
461
							this.autoQueueEnabled = false;
462
463
464
						},
					}),
				]),
m957ymj75urz's avatar
m957ymj75urz committed
465
			]),
reaper47's avatar
reaper47 committed
466
			$el("div", {id: "extraOptions", style: {width: "100%", display: "none"}}, [
467
468
469
				$el("div",[

					$el("label", {innerHTML: "Batch count"}),
470
471
472
473
474
					$el("input", {
						id: "batchCountInputNumber",
						type: "number",
						value: this.batchCount,
						min: "1",
reaper47's avatar
reaper47 committed
475
						style: {width: "35%", "margin-left": "0.4em"},
476
						oninput: (i) => {
m957ymj75urz's avatar
m957ymj75urz committed
477
							this.batchCount = i.target.value;
478
479
							document.getElementById("batchCountInputRange").value = this.batchCount;
						},
m957ymj75urz's avatar
m957ymj75urz committed
480
					}),
481
482
483
484
485
486
					$el("input", {
						id: "batchCountInputRange",
						type: "range",
						min: "1",
						max: "100",
						value: this.batchCount,
m957ymj75urz's avatar
m957ymj75urz committed
487
488
						oninput: (i) => {
							this.batchCount = i.srcElement.value;
489
490
							document.getElementById("batchCountInputNumber").value = i.srcElement.value;
						},
491
492
493
494
495
496
					}),		
				]),
				$el("div",[
					$el("label",{
						for:"autoQueueCheckbox",
						innerHTML: "Auto Queue"
497
498
499
500
501
					}),
					$el("input", {
						id: "autoQueueCheckbox",
						type: "checkbox",
						checked: false,
502
						title: "Automatically queue prompt when the queue size hits 0",
pythongosssss's avatar
pythongosssss committed
503
504
505
506
						onchange: (e) => {
							this.autoQueueEnabled = e.target.checked;
							autoQueueModeEl.style.display = this.autoQueueEnabled ? "" : "none";
						}
m957ymj75urz's avatar
m957ymj75urz committed
507
					}),
pythongosssss's avatar
pythongosssss committed
508
					autoQueueModeEl
509
				])
m957ymj75urz's avatar
m957ymj75urz committed
510
			]),
pythongosssss's avatar
pythongosssss committed
511
			$el("div.comfy-menu-btns", [
reaper47's avatar
reaper47 committed
512
513
514
515
516
				$el("button", {
					id: "queue-front-button",
					textContent: "Queue Front",
					onclick: () => app.queuePrompt(-1, this.batchCount)
				}),
pythongosssss's avatar
pythongosssss committed
517
518
				$el("button", {
					$: (b) => (this.queue.button = b),
519
					id: "comfy-view-queue-button",
pythongosssss's avatar
pythongosssss committed
520
521
522
523
524
525
526
527
					textContent: "View Queue",
					onclick: () => {
						this.history.hide();
						this.queue.toggle();
					},
				}),
				$el("button", {
					$: (b) => (this.history.button = b),
528
					id: "comfy-view-history-button",
pythongosssss's avatar
pythongosssss committed
529
530
531
532
533
534
535
536
537
538
					textContent: "View History",
					onclick: () => {
						this.queue.hide();
						this.history.toggle();
					},
				}),
			]),
			this.queue.element,
			this.history.element,
			$el("button", {
539
				id: "comfy-save-button",
pythongosssss's avatar
pythongosssss committed
540
541
				textContent: "Save",
				onclick: () => {
542
543
544
545
546
547
548
549
					let filename = "workflow.json";
					if (promptFilename.value) {
						filename = prompt("Save workflow as:", filename);
						if (!filename) return;
						if (!filename.toLowerCase().endsWith(".json")) {
							filename += ".json";
						}
					}
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
					app.graphToPrompt().then(p=>{
						const json = JSON.stringify(p.workflow, null, 2); // convert the data to a JSON string
						const blob = new Blob([json], {type: "application/json"});
						const url = URL.createObjectURL(blob);
						const a = $el("a", {
							href: url,
							download: filename,
							style: {display: "none"},
							parent: document.body,
						});
						a.click();
						setTimeout(function () {
							a.remove();
							window.URL.revokeObjectURL(url);
						}, 0);
pythongosssss's avatar
pythongosssss committed
565
566
567
					});
				},
			}),
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
			$el("button", {
				id: "comfy-dev-save-api-button",
				textContent: "Save (API Format)",
				style: {width: "100%", display: "none"},
				onclick: () => {
					let filename = "workflow_api.json";
					if (promptFilename.value) {
						filename = prompt("Save workflow (API) as:", filename);
						if (!filename) return;
						if (!filename.toLowerCase().endsWith(".json")) {
							filename += ".json";
						}
					}
					app.graphToPrompt().then(p=>{
						const json = JSON.stringify(p.output, null, 2); // convert the data to a JSON string
						const blob = new Blob([json], {type: "application/json"});
						const url = URL.createObjectURL(blob);
						const a = $el("a", {
							href: url,
							download: filename,
							style: {display: "none"},
							parent: document.body,
						});
						a.click();
						setTimeout(function () {
							a.remove();
							window.URL.revokeObjectURL(url);
						}, 0);
					});
				},
			}),
reaper47's avatar
reaper47 committed
599
600
601
602
603
604
605
606
607
608
609
610
			$el("button", {id: "comfy-load-button", textContent: "Load", onclick: () => fileInput.click()}),
			$el("button", {
				id: "comfy-refresh-button",
				textContent: "Refresh",
				onclick: () => app.refreshComboInNodes()
			}),
			$el("button", {id: "comfy-clipspace-button", textContent: "Clipspace", onclick: () => app.openClipspace()}),
			$el("button", {
				id: "comfy-clear-button", textContent: "Clear", onclick: () => {
					if (!confirmClear.value || confirm("Clear workflow?")) {
						app.clean();
						app.graph.clear();
611
						app.resetView();
reaper47's avatar
reaper47 committed
612
					}
613
				}
reaper47's avatar
reaper47 committed
614
615
			}),
			$el("button", {
pythongosssss's avatar
pythongosssss committed
616
				id: "comfy-load-default-button", textContent: "Load Default", onclick: async () => {
reaper47's avatar
reaper47 committed
617
					if (!confirmClear.value || confirm("Load default workflow?")) {
618
						app.resetView();
pythongosssss's avatar
pythongosssss committed
619
						await app.loadGraphData()
reaper47's avatar
reaper47 committed
620
					}
621
				}
reaper47's avatar
reaper47 committed
622
			}),
623
624
625
626
627
			$el("button", {
				id: "comfy-reset-view-button", textContent: "Reset View", onclick: async () => {
					app.resetView();
				}
			}),
pythongosssss's avatar
pythongosssss committed
628
		]);
pythongosssss's avatar
pythongosssss committed
629

630
631
632
633
634
		const devMode = this.settings.addSetting({
			id: "Comfy.DevMode",
			name: "Enable Dev mode Options",
			type: "boolean",
			defaultValue: false,
635
			onChange: function(value) { document.getElementById("comfy-dev-save-api-button").style.display = value ? "flex" : "none"},
636
637
		});

638
		this.restoreMenuPosition = dragElement(this.menuContainer, this.settings);
Jairo Correa's avatar
Jairo Correa committed
639

reaper47's avatar
reaper47 committed
640
		this.setStatus({exec_info: {queue_remaining: "X"}});
pythongosssss's avatar
pythongosssss committed
641
642
643
644
	}

	setStatus(status) {
		this.queueSize.textContent = "Queue size: " + (status ? status.exec_info.queue_remaining : "ERR");
comfyanonymous's avatar
comfyanonymous committed
645
		if (status) {
646
647
648
			if (
				this.lastQueueSize != 0 &&
				status.exec_info.queue_remaining == 0 &&
pythongosssss's avatar
pythongosssss committed
649
650
651
				this.autoQueueEnabled &&
				(this.autoQueueMode === "instant" || this.graphHasChanged) &&
				!app.lastExecutionError
652
			) {
comfyanonymous's avatar
comfyanonymous committed
653
				app.queuePrompt(0, this.batchCount);
pythongosssss's avatar
pythongosssss committed
654
655
				status.exec_info.queue_remaining += this.batchCount;
				this.graphHasChanged = false;
comfyanonymous's avatar
comfyanonymous committed
656
			}
657
			this.lastQueueSize = status.exec_info.queue_remaining;
comfyanonymous's avatar
comfyanonymous committed
658
		}
pythongosssss's avatar
pythongosssss committed
659
660
	}
}