From eec4fcaf2e47429482de7d935c44982442a9ce3b Mon Sep 17 00:00:00 2001
From: space-nuko <24979496+space-nuko@users.noreply.github.com>
Date: Fri, 28 Apr 2023 15:14:43 -0700
Subject: [PATCH] [mobile] Show graph
---
src/AppMobile.svelte | 119 ++++++++++++++++-----------
src/home.svelte | 10 ---
src/lib/ComfyGraphCanvas.ts | 3 +-
src/lib/GraphSync.ts | 4 +-
src/lib/api.ts | 2 -
src/lib/components/ComfyApp.svelte | 4 +-
src/lib/components/ComfyApp.ts | 35 ++++----
src/lib/stores/queueState.ts | 7 +-
src/lib/stores/widgetState.ts | 2 +-
src/{ => mobile/routes}/about.svelte | 0
src/mobile/routes/graph.svelte | 43 ++++++++++
src/mobile/routes/home.svelte | 90 ++++++++++++++++++++
src/{ => mobile/routes}/login.svelte | 0
vite.config.ts | 6 +-
14 files changed, 236 insertions(+), 89 deletions(-)
delete mode 100644 src/home.svelte
rename src/{ => mobile/routes}/about.svelte (100%)
create mode 100644 src/mobile/routes/graph.svelte
create mode 100644 src/mobile/routes/home.svelte
rename src/{ => mobile/routes}/login.svelte (100%)
diff --git a/src/AppMobile.svelte b/src/AppMobile.svelte
index 06ec893..b7782ae 100644
--- a/src/AppMobile.svelte
+++ b/src/AppMobile.svelte
@@ -1,14 +1,28 @@
-
-
+
+
-
-
+
+
+
diff --git a/src/home.svelte b/src/home.svelte
deleted file mode 100644
index 41f6034..0000000
--- a/src/home.svelte
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
- ...
- About Page
- Login Page
-
-
diff --git a/src/lib/ComfyGraphCanvas.ts b/src/lib/ComfyGraphCanvas.ts
index 7e5be29..82b19ae 100644
--- a/src/lib/ComfyGraphCanvas.ts
+++ b/src/lib/ComfyGraphCanvas.ts
@@ -9,7 +9,6 @@ export default class ComfyGraphCanvas extends LGraphCanvas {
constructor(
app: ComfyApp,
canvas: HTMLCanvasElement | string,
- graph?: LGraph,
options: {
skip_render?: boolean;
skip_events?: boolean;
@@ -17,7 +16,7 @@ export default class ComfyGraphCanvas extends LGraphCanvas {
viewport?: Vector4;
} = {}
) {
- super(canvas, graph, options);
+ super(canvas, app.lGraph, options);
this.app = app;
}
diff --git a/src/lib/GraphSync.ts b/src/lib/GraphSync.ts
index c7c960e..024e83b 100644
--- a/src/lib/GraphSync.ts
+++ b/src/lib/GraphSync.ts
@@ -88,11 +88,11 @@ export default class GraphSync {
this.stores[nodeId].push({ store: wuis.value, unsubscribe: unsub });
}
- console.log("NEWSTORES", this.stores[nodeId])
+ console.debug("NEWSTORES", this.stores[nodeId])
}
private removeStores(nodeId: string) {
- console.log("DELSTORES", this.stores[nodeId])
+ console.debug("DELSTORES", this.stores[nodeId])
for (const ss of this.stores[nodeId]) {
ss.unsubscribe();
}
diff --git a/src/lib/api.ts b/src/lib/api.ts
index c831e0c..b7fd412 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -49,8 +49,6 @@ export default class ComfyAPI extends EventTarget {
private getBackendUrl(): string {
const hostname = this.hostname || location.hostname;
const port = this.port || location.port;
- console.log(hostname)
- console.log(port)
return `${window.location.protocol}//${hostname}:${port}`
}
diff --git a/src/lib/components/ComfyApp.svelte b/src/lib/components/ComfyApp.svelte
index ca48c4e..b4e5887 100644
--- a/src/lib/components/ComfyApp.svelte
+++ b/src/lib/components/ComfyApp.svelte
@@ -120,11 +120,11 @@
});
await app.setup();
- refreshView();
-
(window as any).app = app;
(window as any).appPane = uiPane;
+ refreshView();
+
imageViewer = new ImageViewer(app.rootEl);
let wrappers = containerElem.querySelectorAll(".pane-wrapper")
diff --git a/src/lib/components/ComfyApp.ts b/src/lib/components/ComfyApp.ts
index 7da71ee..8d27968 100644
--- a/src/lib/components/ComfyApp.ts
+++ b/src/lib/components/ComfyApp.ts
@@ -88,7 +88,7 @@ export default class ComfyApp {
this.rootEl = document.getElementById("main") as HTMLDivElement;
this.canvasEl = document.getElementById("graph-canvas") as HTMLCanvasElement;
this.lGraph = new LGraph();
- this.lCanvas = new ComfyGraphCanvas(this, this.canvasEl, this.lGraph);
+ this.lCanvas = new ComfyGraphCanvas(this, this.canvasEl);
this.canvasCtx = this.canvasEl.getContext("2d");
this.graphSync = new GraphSync(this);
@@ -151,37 +151,37 @@ export default class ComfyApp {
}
private graphOnConfigure() {
- console.log("Configured");
+ console.debug("Configured");
this.eventBus.emit("configured", this.lGraph);
}
private graphOnBeforeChange(graph: LGraph, info: any) {
- console.log("BeforeChange", info);
+ console.debug("BeforeChange", info);
this.eventBus.emit("beforeChange", graph, info);
}
private graphOnAfterChange(graph: LGraph, info: any) {
- console.log("AfterChange", info);
+ console.debug("AfterChange", info);
this.eventBus.emit("afterChange", graph, info);
}
private graphOnNodeAdded(node: LGraphNode) {
- console.log("Added", node);
+ console.debug("Added", node);
this.eventBus.emit("nodeAdded", node);
}
private graphOnNodeRemoved(node: LGraphNode) {
- console.log("Removed", node);
+ console.debug("Removed", node);
this.eventBus.emit("nodeRemoved", node);
}
private graphOnNodeConnectionChange(kind: LConnectionKind, node: LGraphNode, slot: INodeSlot, targetNode: LGraphNode, targetSlot: INodeSlot) {
- console.log("ConnectionChange", node);
+ console.debug("ConnectionChange", node);
this.eventBus.emit("nodeConnectionChanged", kind, node, slot, targetNode, targetSlot);
}
private canvasOnClear() {
- console.log("CanvasClear");
+ console.debug("CanvasClear");
this.eventBus.emit("cleared");
}
@@ -306,11 +306,13 @@ export default class ComfyApp {
}
private showDropZone() {
- this.dropZone.style.display = "block";
+ if (this.dropZone)
+ this.dropZone.style.display = "block";
}
private hideDropZone() {
- this.dropZone.style.display = "none";
+ if (this.dropZone)
+ this.dropZone.style.display = "none";
}
private allowDrag(event: DragEvent) {
@@ -334,10 +336,15 @@ export default class ComfyApp {
private addDropHandler() {
this.dropZone = document.getElementById("dropzone");
- window.addEventListener('dragenter', this.allowDrag.bind(this));
- this.dropZone.addEventListener('dragover', this.allowDrag.bind(this));
- this.dropZone.addEventListener('dragleave', this.hideDropZone.bind(this));
- this.dropZone.addEventListener('drop', this.handleDrop.bind(this));
+ if (this.dropZone) {
+ window.addEventListener('dragenter', this.allowDrag.bind(this));
+ this.dropZone.addEventListener('dragover', this.allowDrag.bind(this));
+ this.dropZone.addEventListener('dragleave', this.hideDropZone.bind(this));
+ this.dropZone.addEventListener('drop', this.handleDrop.bind(this));
+ }
+ else {
+ console.warn("No dropzone detected (probably on mobile).")
+ }
}
/**
diff --git a/src/lib/stores/queueState.ts b/src/lib/stores/queueState.ts
index 1b714a0..8f3076f 100644
--- a/src/lib/stores/queueState.ts
+++ b/src/lib/stores/queueState.ts
@@ -7,7 +7,7 @@ export type QueueItem = {
}
type QueueStateOps = {
- statusUpdated: (status: ComfyAPIQueueStatus) => void,
+ statusUpdated: (status: ComfyAPIQueueStatus | null) => void,
executingUpdated: (runningNodeId: string | null) => void,
progressUpdated: (progress: Progress | null) => void
}
@@ -21,9 +21,10 @@ type WritableQueueStateStore = Writable & QueueStateOps;
const store: Writable = writable({ queueRemaining: null, runningNodeId: null, progress: null })
-function statusUpdated(status: ComfyAPIQueueStatus) {
+function statusUpdated(status: ComfyAPIQueueStatus | null) {
store.update((s) => {
- s.queueRemaining = status.exec_info.queue_remaining;
+ if (status !== null)
+ s.queueRemaining = status.exec_info.queue_remaining;
return s
})
}
diff --git a/src/lib/stores/widgetState.ts b/src/lib/stores/widgetState.ts
index a86b9a8..06084b9 100644
--- a/src/lib/stores/widgetState.ts
+++ b/src/lib/stores/widgetState.ts
@@ -62,7 +62,7 @@ function nodeAdded(node: LGraphNode) {
}
}
- console.log("NODEADDED", state)
+ console.debug("NODEADDED", state)
store.set(state);
}
diff --git a/src/about.svelte b/src/mobile/routes/about.svelte
similarity index 100%
rename from src/about.svelte
rename to src/mobile/routes/about.svelte
diff --git a/src/mobile/routes/graph.svelte b/src/mobile/routes/graph.svelte
new file mode 100644
index 0000000..2fbe4d0
--- /dev/null
+++ b/src/mobile/routes/graph.svelte
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/mobile/routes/home.svelte b/src/mobile/routes/home.svelte
new file mode 100644
index 0000000..785db20
--- /dev/null
+++ b/src/mobile/routes/home.svelte
@@ -0,0 +1,90 @@
+
+
+
+
+
+ Yo
+
+ {app} Nodes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/login.svelte b/src/mobile/routes/login.svelte
similarity index 100%
rename from src/login.svelte
rename to src/mobile/routes/login.svelte
diff --git a/vite.config.ts b/vite.config.ts
index 4898666..d43b14c 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -28,9 +28,9 @@ export default defineConfig({
server: {
port: 3000,
- hmr: {
- clientPort: 443,
- },
+ // hmr: {
+ // clientPort: 443,
+ // },
// fs: {
// allow: [
// "src",