7 Commits

Author SHA1 Message Date
space-nuko
c2f284f5ed Restore/load workflow button in prompt details modal 2023-10-31 14:45:19 -05:00
space-nuko
abd31401f0 Merge pull request #148 from haze/hb/vibrateIfPossible
`vibrateIfPossible`: fixes iOS safari uncaught exceptions & etc
2023-08-25 23:43:22 -05:00
haze
2f48f96830 Update CheckboxWidget.svelte 2023-08-25 15:26:15 -04:00
Haze Booth
63d51e9119 Introduce vibrateIfPossible into the utils package. This will check if the browser
has support for vibrating. This fixes a number of bugs for iOS safari & friends.
2023-08-24 12:02:22 -04:00
space-nuko
6f02912d2e Merge pull request #125 from space-nuko/restore-params2
Upgrade Svelte and dependency versions
2023-07-07 09:49:39 -05:00
space-nuko
3b49bac47b Merge pull request #126 from space-nuko/server-args
Add arguments to serve.py
2023-07-07 09:49:27 -05:00
space-nuko
33ed379a98 Add arguments to serve.py 2023-07-07 09:12:28 -05:00
16 changed files with 153 additions and 84 deletions

View File

@@ -2,15 +2,19 @@
import http.server import http.server
import socketserver import socketserver
import argparse
PORT = 8000 parser = argparse.ArgumentParser()
parser.add_argument("-l", "--listen", type=str, default="localhost", help="Listen address for ComfyBox server")
parser.add_argument("-p", "--port", type=int, default=8000, help="Port for ComfyBox server")
args = parser.parse_args()
message = f"""Starting ComfyBox. message = f"""Starting ComfyBox.
Be sure you've started ComfyUI already using this command: Be sure you've started ComfyUI already using this command:
python main.py --enable-cors-header python main.py --enable-cors-header
Serving at http://localhost:{PORT}... Serving at http://{args.listen}:{args.port}...
""" """
# python -m http.server will sometimes send incorrect MIME types. # python -m http.server will sometimes send incorrect MIME types.
@@ -19,33 +23,34 @@ Serving at http://localhost:{PORT}...
# Hopefully this will cover everything. # Hopefully this will cover everything.
class HttpRequestHandler(http.server.SimpleHTTPRequestHandler): class HttpRequestHandler(http.server.SimpleHTTPRequestHandler):
extensions_map = { extensions_map = {
'': 'application/octet-stream', "": "application/octet-stream",
'.manifest': 'text/cache-manifest', ".manifest": "text/cache-manifest",
'.html': 'text/html', ".html": "text/html",
'.png': 'image/png', ".png": "image/png",
'.jpg': 'image/jpg', ".jpg": "image/jpg",
'.jpeg': 'image/jpeg', ".jpeg": "image/jpeg",
'.gif': 'image/gif', ".gif": "image/gif",
'.svg': 'image/svg+xml', ".svg": "image/svg+xml",
'.css': 'text/css', ".css": "text/css",
'.js': 'application/x-javascript', ".js": "application/x-javascript",
'.mjs': 'application/x-javascript', ".mjs": "application/x-javascript",
'.cjs': 'application/x-javascript', ".cjs": "application/x-javascript",
'.wasm': 'application/wasm', ".wasm": "application/wasm",
'.json': 'application/json', ".json": "application/json",
'.xml': 'application/xml', ".xml": "application/xml",
'.xml': 'application/xml', ".xml": "application/xml",
'.pdf': 'application/pdf', ".pdf": "application/pdf",
'.webp': 'image/webp', ".webp": "image/webp",
'.avif': 'image/avif', ".avif": "image/avif",
'.heic': 'image/heic', ".heic": "image/heic",
'.heif': 'image/heif', ".heif": "image/heif",
'.mp3': 'audio/mpeg', ".mp3": "audio/mpeg",
'.mp4': 'video/mp4', ".mp4": "video/mp4",
'.m4v': 'video/mp4' ".m4v": "video/mp4",
} }
httpd = socketserver.TCPServer(("localhost", PORT), HttpRequestHandler)
httpd = socketserver.TCPServer((args.listen, args.port), HttpRequestHandler)
try: try:
print(message) print(message)

View File

@@ -12,7 +12,7 @@
import {cubicIn} from 'svelte/easing'; import {cubicIn} from 'svelte/easing';
import { flip } from 'svelte/animate'; import { flip } from 'svelte/animate';
import { type ContainerLayout, type WidgetLayout, type IDragItem } from "$lib/stores/layoutStates"; import { type ContainerLayout, type WidgetLayout, type IDragItem } from "$lib/stores/layoutStates";
import { startDrag, stopDrag } from "$lib/utils" import { startDrag, stopDrag, vibrateIfPossible } from "$lib/utils"
import { writable, type Writable } from "svelte/store"; import { writable, type Writable } from "svelte/store";
import { isHidden } from "$lib/widgets/utils"; import { isHidden } from "$lib/widgets/utils";
import { handleContainerConsider, handleContainerFinalize } from "./utils"; import { handleContainerConsider, handleContainerFinalize } from "./utils";
@@ -56,7 +56,7 @@
}; };
function handleClick(e: CustomEvent<boolean>) { function handleClick(e: CustomEvent<boolean>) {
navigator.vibrate(20) vibrateIfPossible(20)
$isOpen = e.detail $isOpen = e.detail
} }

View File

@@ -28,7 +28,7 @@ import modalState from "$lib/stores/modalState";
import queueState from "$lib/stores/queueState"; import queueState from "$lib/stores/queueState";
import selectionState from "$lib/stores/selectionState"; import selectionState from "$lib/stores/selectionState";
import uiState from "$lib/stores/uiState"; import uiState from "$lib/stores/uiState";
import workflowState, { ComfyBoxWorkflow, type WorkflowAttributes, type WorkflowInstID } from "$lib/stores/workflowState"; import workflowState, { ComfyBoxWorkflow, OpenWorkflowMode, type WorkflowAttributes, type WorkflowInstID } from "$lib/stores/workflowState";
import { playSound, readFileToText, type SerializedPromptOutput } from "$lib/utils"; import { playSound, readFileToText, type SerializedPromptOutput } from "$lib/utils";
import { basename, capitalize, download, graphToGraphVis, jsonToJsObject, promptToGraphVis, range } from "$lib/utils"; import { basename, capitalize, download, graphToGraphVis, jsonToJsObject, promptToGraphVis, range } from "$lib/utils";
import { tick } from "svelte"; import { tick } from "svelte";
@@ -49,7 +49,7 @@ if (typeof window !== "undefined") {
} }
export type OpenWorkflowOptions = { export type OpenWorkflowOptions = {
setActive?: boolean, mode: OpenWorkflowMode,
refreshCombos?: boolean | Record<string, ComfyNodeDef>, refreshCombos?: boolean | Record<string, ComfyNodeDef>,
warnMissingNodeTypes?: boolean, warnMissingNodeTypes?: boolean,
} }
@@ -234,7 +234,7 @@ export default class ComfyApp {
if (!restored) { if (!restored) {
const options: OpenWorkflowOptions = { const options: OpenWorkflowOptions = {
refreshCombos: defs, refreshCombos: defs,
setActive: false mode: OpenWorkflowMode.Append
} }
await this.initDefaultWorkflow("defaultWorkflow", options); await this.initDefaultWorkflow("defaultWorkflow", options);
await this.initDefaultWorkflow("upscaleByModel", options); await this.initDefaultWorkflow("upscaleByModel", options);
@@ -408,7 +408,7 @@ export default class ComfyApp {
return false; return false;
await Promise.all(workflows.map(w => { await Promise.all(workflows.map(w => {
return this.openWorkflow(w, { refreshCombos: defs, warnMissingNodeTypes: false, setActive: false }).catch(error => { return this.openWorkflow(w, { refreshCombos: defs, warnMissingNodeTypes: false, mode: OpenWorkflowMode.Append }).catch(error => {
console.error("Failed restoring previous workflow", error) console.error("Failed restoring previous workflow", error)
notify(`Failed restoring previous workflow: ${error}`, { type: "error" }) notify(`Failed restoring previous workflow: ${error}`, { type: "error" })
}) })
@@ -778,7 +778,7 @@ export default class ComfyApp {
} }
async openWorkflow(data: SerializedAppState, options: OpenWorkflowOptions = { async openWorkflow(data: SerializedAppState, options: OpenWorkflowOptions = {
setActive: true, mode: OpenWorkflowMode.AppendAndSetActive,
refreshCombos: true, refreshCombos: true,
warnMissingNodeTypes: true warnMissingNodeTypes: true
} }
@@ -793,7 +793,7 @@ export default class ComfyApp {
let workflow: ComfyBoxWorkflow; let workflow: ComfyBoxWorkflow;
try { try {
workflow = workflowState.openWorkflow(this.lCanvas, data, options.setActive); workflow = workflowState.openWorkflow(this.lCanvas, data, options.mode);
} }
catch (error) { catch (error) {
modalState.pushModal({ modalState.pushModal({
@@ -827,7 +827,11 @@ export default class ComfyApp {
return workflow; return workflow;
} }
async openVanillaWorkflow(data: SerializedLGraph, filename: string) { async openVanillaWorkflow(data: SerializedLGraph, filename: string, options: OpenWorkflowOptions = {
mode: OpenWorkflowMode.AppendAndSetActive,
refreshCombos: true,
warnMissingNodeTypes: true
}) {
const title = basename(filename) const title = basename(filename)
const attrs: WorkflowAttributes = { const attrs: WorkflowAttributes = {
@@ -844,7 +848,7 @@ export default class ComfyApp {
const addWorkflow = () => { const addWorkflow = () => {
notify("Converted ComfyUI workflow to ComfyBox format.", { type: "info" }) notify("Converted ComfyUI workflow to ComfyBox format.", { type: "info" })
workflowState.addWorkflow(this.lCanvas, comfyBoxWorkflow) workflowState.addWorkflow(this.lCanvas, comfyBoxWorkflow, options.mode)
this.lCanvas.deserialize(canvas); this.lCanvas.deserialize(canvas);
} }
@@ -886,7 +890,7 @@ export default class ComfyApp {
} }
createNewWorkflow() { createNewWorkflow() {
workflowState.createNewWorkflow(this.lCanvas, undefined, true); workflowState.createNewWorkflow(this.lCanvas, undefined, OpenWorkflowMode.AppendAndSetActive);
selectionState.clear(); selectionState.clear();
} }
@@ -1146,13 +1150,13 @@ export default class ComfyApp {
/** /**
* Loads workflow data from the specified file * Loads workflow data from the specified file
*/ */
async handleFile(file: File) { async handleFile(file: File, openOptions?: OpenWorkflowOptions) {
if (file.type === "image/png") { if (file.type === "image/png") {
const buffer = await file.arrayBuffer(); const buffer = await file.arrayBuffer();
const pngInfo = await parsePNGMetadata(buffer); const pngInfo = await parsePNGMetadata(buffer);
if (pngInfo) { if (pngInfo) {
if (pngInfo.comfyBoxWorkflow) { if (pngInfo.comfyBoxWorkflow) {
await this.openWorkflow(JSON.parse(pngInfo.comfyBoxWorkflow)); await this.openWorkflow(JSON.parse(pngInfo.comfyBoxWorkflow), openOptions);
} else if (pngInfo.workflow) { } else if (pngInfo.workflow) {
const workflow = JSON.parse(pngInfo.workflow); const workflow = JSON.parse(pngInfo.workflow);
await this.openVanillaWorkflow(workflow, file.name); await this.openVanillaWorkflow(workflow, file.name);
@@ -1187,7 +1191,7 @@ export default class ComfyApp {
reader.onload = async () => { reader.onload = async () => {
const result = JSON.parse(reader.result as string) const result = JSON.parse(reader.result as string)
if (isComfyBoxWorkflow(result)) { if (isComfyBoxWorkflow(result)) {
await this.openWorkflow(result); await this.openWorkflow(result, openOptions);
} }
else if (isVanillaWorkflow(result)) { else if (isVanillaWorkflow(result)) {
await this.openVanillaWorkflow(result, file.name); await this.openVanillaWorkflow(result, file.name);

View File

@@ -12,11 +12,12 @@
import type ComfyApp from "./ComfyApp"; import type ComfyApp from "./ComfyApp";
import { getContext, tick } from "svelte"; import { getContext, tick } from "svelte";
import Modal from "./Modal.svelte"; import Modal from "./Modal.svelte";
import { type WorkflowError } from "$lib/stores/workflowState";
import ComfyQueueListDisplay from "./ComfyQueueListDisplay.svelte"; import ComfyQueueListDisplay from "./ComfyQueueListDisplay.svelte";
import ComfyQueueGridDisplay from "./ComfyQueueGridDisplay.svelte"; import ComfyQueueGridDisplay from "./ComfyQueueGridDisplay.svelte";
import { WORKFLOWS_VIEW } from "./ComfyBoxWorkflowsView.svelte"; import { WORKFLOWS_VIEW } from "./ComfyBoxWorkflowsView.svelte";
import uiQueueState, { type QueueUIEntry } from "$lib/stores/uiQueueState"; import uiQueueState, { type QueueUIEntry } from "$lib/stores/uiQueueState";
import type { SerializedPromptInputsAll } from "./ComfyApp";
import { OpenWorkflowMode } from "$lib/stores/workflowState";
export let app: ComfyApp; export let app: ComfyApp;
@@ -109,18 +110,21 @@
let showModal = false; let showModal = false;
let expandAll = false; let expandAll = false;
let selectedPrompt = null; let selectedQueueEntry: QueueUIEntry = null;
let selectedPrompt: SerializedPromptInputsAll = null;
let selectedImages: ComfyImageLocation[] = []; let selectedImages: ComfyImageLocation[] = [];
function showPrompt(entry: QueueUIEntry) { function showPrompt(entry: QueueUIEntry) {
if (entry.error != null) { if (entry.error != null) {
showModal = false; showModal = false;
expandAll = false; expandAll = false;
selectedQueueEntry = null;
selectedPrompt = null; selectedPrompt = null;
selectedImages = []; selectedImages = [];
showError(entry.entry.promptID); showError(entry.entry.promptID);
} }
else { else {
selectedQueueEntry = entry;
selectedPrompt = entry.entry.prompt; selectedPrompt = entry.entry.prompt;
selectedImages = entry.images; selectedImages = entry.images;
showModal = true; showModal = true;
@@ -129,6 +133,7 @@
} }
function closeModal() { function closeModal() {
selectedQueueEntry = null;
selectedPrompt = null selectedPrompt = null
selectedImages = [] selectedImages = []
showModal = false; showModal = false;
@@ -136,6 +141,24 @@
console.warn("CLOSEMODAL") console.warn("CLOSEMODAL")
} }
async function restoreWorkflow(closeDialog: () => void, mode: OpenWorkflowMode) {
if (selectedQueueEntry == null) {
console.error("No active prompt!");
return;
}
let workflow = selectedQueueEntry.entry.extraData.extra_pnginfo.comfyBoxWorkflow;
if (workflow == null) {
console.error("No workflow found in PNG info!");
return;
}
closeDialog();
closeModal();
await app.openWorkflow(structuredClone(workflow), { mode: mode, refreshCombos: true, warnMissingNodeTypes: true });
}
let queued = false let queued = false
$: queued = Boolean($queueState.runningNodeID || $queueState.progress); $: queued = Boolean($queueState.runningNodeID || $queueState.progress);
@@ -160,6 +183,12 @@
<Button variant="secondary" on:click={() => (expandAll = !expandAll)}> <Button variant="secondary" on:click={() => (expandAll = !expandAll)}>
Expand All Expand All
</Button> </Button>
<Button variant="primary" on:click={() => restoreWorkflow(closeDialog, OpenWorkflowMode.ReplaceActive)}>
Restore
</Button>
<Button variant="primary" on:click={() => restoreWorkflow(closeDialog, OpenWorkflowMode.AppendAndSetActive)}>
Load
</Button>
</div> </div>
</Modal> </Modal>

View File

@@ -12,7 +12,7 @@
import {cubicIn} from 'svelte/easing'; import {cubicIn} from 'svelte/easing';
import { flip } from 'svelte/animate'; import { flip } from 'svelte/animate';
import { type ContainerLayout, type WidgetLayout, type IDragItem, type WritableLayoutStateStore } from "$lib/stores/layoutStates"; import { type ContainerLayout, type WidgetLayout, type IDragItem, type WritableLayoutStateStore } from "$lib/stores/layoutStates";
import { startDrag, stopDrag } from "$lib/utils" import { startDrag, stopDrag, vibrateIfPossible } from "$lib/utils"
import type { Writable } from "svelte/store"; import type { Writable } from "svelte/store";
import { isHidden } from "$lib/widgets/utils"; import { isHidden } from "$lib/widgets/utils";
import { handleContainerConsider, handleContainerFinalize } from "./utils"; import { handleContainerConsider, handleContainerFinalize } from "./utils";
@@ -62,7 +62,7 @@
} }
function handleSelect() { function handleSelect() {
navigator.vibrate(20) vibrateIfPossible(20)
} }
function _startDrag(e: MouseEvent | TouchEvent) { function _startDrag(e: MouseEvent | TouchEvent) {

View File

@@ -7,7 +7,6 @@ import ComfyGraph from '$lib/ComfyGraph';
import layoutStates from './layoutStates'; import layoutStates from './layoutStates';
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import type ComfyGraphCanvas from '$lib/ComfyGraphCanvas'; import type ComfyGraphCanvas from '$lib/ComfyGraphCanvas';
import { blankGraph } from '$lib/defaultGraph';
import type { SerializedAppState, SerializedPrompt } from '$lib/components/ComfyApp'; import type { SerializedAppState, SerializedPrompt } from '$lib/components/ComfyApp';
import type ComfyReceiveOutputNode from '$lib/nodes/actions/ComfyReceiveOutputNode'; import type ComfyReceiveOutputNode from '$lib/nodes/actions/ComfyReceiveOutputNode';
import type { ComfyBoxPromptExtraData, PromptID } from '$lib/api'; import type { ComfyBoxPromptExtraData, PromptID } from '$lib/api';
@@ -25,6 +24,12 @@ export type SerializedWorkflowState = {
attrs: WorkflowAttributes attrs: WorkflowAttributes
} }
export enum OpenWorkflowMode {
Append,
AppendAndSetActive,
ReplaceActive,
}
/* /*
* ID for an opened workflow. * ID for an opened workflow.
* *
@@ -265,6 +270,7 @@ export type WorkflowState = {
openedWorkflows: ComfyBoxWorkflow[], openedWorkflows: ComfyBoxWorkflow[],
openedWorkflowsByID: Record<WorkflowInstID, ComfyBoxWorkflow>, openedWorkflowsByID: Record<WorkflowInstID, ComfyBoxWorkflow>,
activeWorkflowID: WorkflowInstID | null, activeWorkflowID: WorkflowInstID | null,
activeWorkflowIndex: number | null,
activeWorkflow: ComfyBoxWorkflow | null, activeWorkflow: ComfyBoxWorkflow | null,
} }
@@ -279,9 +285,9 @@ type WorkflowStateOps = {
getWorkflowByNode: (node: LGraphNode) => ComfyBoxWorkflow | null getWorkflowByNode: (node: LGraphNode) => ComfyBoxWorkflow | null
getWorkflowByNodeID: (id: NodeID) => ComfyBoxWorkflow | null getWorkflowByNodeID: (id: NodeID) => ComfyBoxWorkflow | null
getActiveWorkflow: () => ComfyBoxWorkflow | null getActiveWorkflow: () => ComfyBoxWorkflow | null
createNewWorkflow: (canvas: ComfyGraphCanvas, title?: string, setActive?: boolean) => ComfyBoxWorkflow, createNewWorkflow: (canvas: ComfyGraphCanvas, title?: string, mode?: OpenWorkflowMode) => ComfyBoxWorkflow,
openWorkflow: (canvas: ComfyGraphCanvas, data: SerializedAppState, setActive?: boolean) => ComfyBoxWorkflow, openWorkflow: (canvas: ComfyGraphCanvas, data: SerializedAppState, mode?: OpenWorkflowMode) => ComfyBoxWorkflow,
addWorkflow: (canvas: ComfyGraphCanvas, data: ComfyBoxWorkflow, setActive?: boolean) => void, addWorkflow: (canvas: ComfyGraphCanvas, data: ComfyBoxWorkflow, mode?: OpenWorkflowMode) => void,
closeWorkflow: (canvas: ComfyGraphCanvas, index: number) => void, closeWorkflow: (canvas: ComfyGraphCanvas, index: number) => void,
closeAllWorkflows: (canvas: ComfyGraphCanvas) => void, closeAllWorkflows: (canvas: ComfyGraphCanvas) => void,
setActiveWorkflow: (canvas: ComfyGraphCanvas, index: number | WorkflowInstID) => ComfyBoxWorkflow | null, setActiveWorkflow: (canvas: ComfyGraphCanvas, index: number | WorkflowInstID) => ComfyBoxWorkflow | null,
@@ -297,6 +303,7 @@ const store: Writable<WorkflowState> = writable(
openedWorkflows: [], openedWorkflows: [],
openedWorkflowsByID: {}, openedWorkflowsByID: {},
activeWorkflowID: null, activeWorkflowID: null,
activeWorkflowIndex: null,
activeWorkflow: null activeWorkflow: null
}) })
@@ -328,39 +335,51 @@ function getActiveWorkflow(): ComfyBoxWorkflow | null {
return state.openedWorkflowsByID[state.activeWorkflowID]; return state.openedWorkflowsByID[state.activeWorkflowID];
} }
function createNewWorkflow(canvas: ComfyGraphCanvas, title: string = "New Workflow", setActive: boolean = false): ComfyBoxWorkflow { function createNewWorkflow(canvas: ComfyGraphCanvas, title: string = "New Workflow", mode: OpenWorkflowMode = OpenWorkflowMode.AppendAndSetActive): ComfyBoxWorkflow {
const workflow = new ComfyBoxWorkflow(title); const workflow = new ComfyBoxWorkflow(title);
const layoutState = layoutStates.create(workflow); const layoutState = layoutStates.create(workflow);
layoutState.initDefaultLayout(); layoutState.initDefaultLayout();
const state = get(store); return addWorkflow(canvas, workflow, mode);
state.openedWorkflows.push(workflow);
state.openedWorkflowsByID[workflow.id] = workflow;
if (setActive || state.activeWorkflowID == null)
setActiveWorkflow(canvas, state.openedWorkflows.length - 1)
store.set(state)
return workflow;
} }
function openWorkflow(canvas: ComfyGraphCanvas, data: SerializedAppState, setActive: boolean = true): ComfyBoxWorkflow { function openWorkflow(canvas: ComfyGraphCanvas, data: SerializedAppState, mode: OpenWorkflowMode = OpenWorkflowMode.AppendAndSetActive): ComfyBoxWorkflow {
const [workflow, layoutState] = ComfyBoxWorkflow.create("Workflow") const [workflow, layoutState] = ComfyBoxWorkflow.create("Workflow")
workflow.deserialize(layoutState, { graph: data.workflow, layout: data.layout, attrs: data.attrs }) workflow.deserialize(layoutState, { graph: data.workflow, layout: data.layout, attrs: data.attrs })
addWorkflow(canvas, workflow, setActive); addWorkflow(canvas, workflow, mode);
return workflow; return workflow;
} }
function addWorkflow(canvas: ComfyGraphCanvas, workflow: ComfyBoxWorkflow, setActive: boolean = true) { function addWorkflow(canvas: ComfyGraphCanvas, workflow: ComfyBoxWorkflow, mode: OpenWorkflowMode = OpenWorkflowMode.AppendAndSetActive) {
const state = get(store); const state = get(store);
let resultIndex: number = state.openedWorkflows.length;
if (mode == OpenWorkflowMode.ReplaceActive && state.activeWorkflowIndex != null) {
resultIndex = state.activeWorkflowIndex;
closeWorkflow(canvas, resultIndex);
state.openedWorkflows.splice(resultIndex, 0, workflow);
}
else {
state.openedWorkflows.push(workflow); state.openedWorkflows.push(workflow);
}
state.openedWorkflowsByID[workflow.id] = workflow; state.openedWorkflowsByID[workflow.id] = workflow;
let setActive: boolean;
switch (mode) {
case OpenWorkflowMode.Append:
setActive = false;
break;
case OpenWorkflowMode.AppendAndSetActive:
case OpenWorkflowMode.ReplaceActive:
setActive = true;
break;
}
if (setActive || state.activeWorkflowID == null) if (setActive || state.activeWorkflowID == null)
setActiveWorkflow(canvas, state.openedWorkflows.length - 1) setActiveWorkflow(canvas, resultIndex)
store.set(state) store.set(state)
@@ -397,6 +416,7 @@ function setActiveWorkflow(canvas: ComfyGraphCanvas, index: number | WorkflowIns
if (state.openedWorkflows.length === 0) { if (state.openedWorkflows.length === 0) {
state.activeWorkflowID = null; state.activeWorkflowID = null;
state.activeWorkflowIndex = null;
state.activeWorkflow = null state.activeWorkflow = null
return null; return null;
} }
@@ -416,6 +436,7 @@ function setActiveWorkflow(canvas: ComfyGraphCanvas, index: number | WorkflowIns
state.activeWorkflow.stop("app") state.activeWorkflow.stop("app")
state.activeWorkflowID = workflow.id; state.activeWorkflowID = workflow.id;
state.activeWorkflowIndex = index;
state.activeWorkflow = workflow; state.activeWorkflow = workflow;
workflow.start("app", canvas); workflow.start("app", canvas);

View File

@@ -828,3 +828,9 @@ const MOBILE_USER_AGENTS = ["iPhone", "iPad", "Android", "BlackBerry", "WebOs"].
export function isMobileBrowser(userAgent: string): boolean { export function isMobileBrowser(userAgent: string): boolean {
return MOBILE_USER_AGENTS.some(a => userAgent.match(a)) return MOBILE_USER_AGENTS.some(a => userAgent.match(a))
} }
export function vibrateIfPossible(strength: number | Array<number>) {
if (window.navigator.vibrate) {
window.navigator.vibrate(strength);
}
}

View File

@@ -3,6 +3,7 @@
import { Button } from "@gradio/button"; import { Button } from "@gradio/button";
import { get, type Writable, writable } from "svelte/store"; import { get, type Writable, writable } from "svelte/store";
import { isDisabled } from "./utils" import { isDisabled } from "./utils"
import { vibrateIfPossible } from "$lib/utils";
import type { ComfyButtonNode } from "$lib/nodes/widgets"; import type { ComfyButtonNode } from "$lib/nodes/widgets";
export let widget: WidgetLayout | null = null; export let widget: WidgetLayout | null = null;
@@ -24,7 +25,7 @@
function onClick(e: MouseEvent) { function onClick(e: MouseEvent) {
node.onClick(); node.onClick();
navigator.vibrate(20) vibrateIfPossible(20)
} }
const style = { const style = {

View File

@@ -4,6 +4,7 @@
import { Checkbox } from "@gradio/form"; import { Checkbox } from "@gradio/form";
import { get, type Writable, writable } from "svelte/store"; import { get, type Writable, writable } from "svelte/store";
import { isDisabled } from "./utils" import { isDisabled } from "./utils"
import { vibrateIfPossible } from "$lib/utils";
import type { SelectData } from "@gradio/utils"; import type { SelectData } from "@gradio/utils";
import type { ComfyCheckboxNode } from "$lib/nodes/widgets"; import type { ComfyCheckboxNode } from "$lib/nodes/widgets";
@@ -25,7 +26,7 @@
function onSelect(e: CustomEvent<SelectData>) { function onSelect(e: CustomEvent<SelectData>) {
$nodeValue = e.detail.selected $nodeValue = e.detail.selected
navigator.vibrate(20) vibrateIfPossible(20)
} }
</script> </script>

View File

@@ -8,7 +8,7 @@
import { type WidgetLayout } from "$lib/stores/layoutStates"; import { type WidgetLayout } from "$lib/stores/layoutStates";
import { get, writable, type Writable } from "svelte/store"; import { get, writable, type Writable } from "svelte/store";
import { isDisabled } from "./utils" import { isDisabled } from "./utils"
import { clamp, getSafetensorsMetadata } from '$lib/utils'; import { clamp, getSafetensorsMetadata, vibrateIfPossible } from '$lib/utils';
export let widget: WidgetLayout | null = null; export let widget: WidgetLayout | null = null;
export let isMobile: boolean = false; export let isMobile: boolean = false;
let node: ComfyComboNode | null = null; let node: ComfyComboNode | null = null;
@@ -70,7 +70,7 @@
function onFocus() { function onFocus() {
// console.warn("FOCUS") // console.warn("FOCUS")
if (listOpen) { if (listOpen) {
navigator.vibrate(20) vibrateIfPossible(20)
} }
} }
@@ -86,7 +86,7 @@
function handleSelect(index: number) { function handleSelect(index: number) {
// console.warn("SEL", index) // console.warn("SEL", index)
navigator.vibrate(20) vibrateIfPossible(20)
const item = $valuesForCombo[index] const item = $valuesForCombo[index]
activeIndex = index; activeIndex = index;
$nodeValue = item.value $nodeValue = item.value

View File

@@ -3,7 +3,7 @@
import { type WidgetLayout } from "$lib/stores/layoutStates"; import { type WidgetLayout } from "$lib/stores/layoutStates";
import { Range } from "$lib/components/gradio/form"; import { Range } from "$lib/components/gradio/form";
import { get, type Writable } from "svelte/store"; import { get, type Writable } from "svelte/store";
import { debounce } from "$lib/utils"; import { debounce, vibrateIfPossible } from "$lib/utils";
import interfaceState from "$lib/stores/interfaceState"; import interfaceState from "$lib/stores/interfaceState";
import { isDisabled } from "./utils" import { isDisabled } from "./utils"
export let widget: WidgetLayout | null = null; export let widget: WidgetLayout | null = null;
@@ -96,7 +96,7 @@
lastDisplayValue = option; lastDisplayValue = option;
canVibrate = false; canVibrate = false;
setTimeout(() => { canVibrate = true }, 30) setTimeout(() => { canVibrate = true }, 30)
navigator.vibrate(10) vibrateIfPossible(10)
} }
} }
</script> </script>

View File

@@ -5,7 +5,7 @@
import { get, type Writable, writable } from "svelte/store"; import { get, type Writable, writable } from "svelte/store";
import { isDisabled } from "./utils" import { isDisabled } from "./utils"
import type { SelectData } from "@gradio/utils"; import type { SelectData } from "@gradio/utils";
import { clamp } from "$lib/utils"; import { clamp, vibrateIfPossible } from "$lib/utils";
import type { ComfyRadioNode } from "$lib/nodes/widgets"; import type { ComfyRadioNode } from "$lib/nodes/widgets";
export let widget: WidgetLayout | null = null; export let widget: WidgetLayout | null = null;
@@ -34,7 +34,7 @@
function onSelect(e: CustomEvent<SelectData>) { function onSelect(e: CustomEvent<SelectData>) {
node.setValue(e.detail.value) node.setValue(e.detail.value)
node.index = e.detail.index as number node.index = e.detail.index as number
navigator.vibrate(20) vibrateIfPossible(20)
} }
</script> </script>

View File

@@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import ComfyApp, { type SerializedAppState } from "$lib/components/ComfyApp"; import ComfyApp, { type SerializedAppState } from "$lib/components/ComfyApp";
import workflowState, { ComfyBoxWorkflow } from "$lib/stores/workflowState"; import workflowState, { ComfyBoxWorkflow } from "$lib/stores/workflowState";
import { vibrateIfPossible } from "$lib/utils";
import { Link, Toolbar } from "framework7-svelte" import { Link, Toolbar } from "framework7-svelte"
@@ -11,7 +12,7 @@
$: workflow = $workflowState.activeWorkflow; $: workflow = $workflowState.activeWorkflow;
function queuePrompt() { function queuePrompt() {
navigator.vibrate(20) vibrateIfPossible(20)
app.runDefaultQueueAction() app.runDefaultQueueAction()
} }
</script> </script>

View File

@@ -2,7 +2,7 @@
import ComfyApp, { type SerializedAppState } from "$lib/components/ComfyApp"; import ComfyApp, { type SerializedAppState } from "$lib/components/ComfyApp";
import queueState from "$lib/stores/queueState"; import queueState from "$lib/stores/queueState";
import workflowState, { ComfyBoxWorkflow } from "$lib/stores/workflowState"; import workflowState, { ComfyBoxWorkflow } from "$lib/stores/workflowState";
import { getNodeInfo } from "$lib/utils" import { getNodeInfo, vibrateIfPossible } from "$lib/utils"
import { LayoutTextSidebarReverse, Image, Grid } from "svelte-bootstrap-icons"; import { LayoutTextSidebarReverse, Image, Grid } from "svelte-bootstrap-icons";
import { Link, Toolbar } from "framework7-svelte" import { Link, Toolbar } from "framework7-svelte"
@@ -21,12 +21,12 @@
$: workflow = $workflowState.activeWorkflow; $: workflow = $workflowState.activeWorkflow;
function queuePrompt() { function queuePrompt() {
navigator.vibrate(20) vibrateIfPossible(20)
app.runDefaultQueueAction() app.runDefaultQueueAction()
} }
async function refreshCombos() { async function refreshCombos() {
navigator.vibrate(20) vibrateIfPossible(20)
await app.refreshComboInNodes() await app.refreshComboInNodes()
} }
@@ -34,7 +34,7 @@
if (!fileInput) if (!fileInput)
return; return;
navigator.vibrate(20) vibrateIfPossible(20)
app.querySave() app.querySave()
} }
@@ -42,7 +42,7 @@
if (!fileInput) if (!fileInput)
return; return;
navigator.vibrate(20) vibrateIfPossible(20)
fileInput.value = null; fileInput.value = null;
fileInput.click(); fileInput.click();
} }
@@ -52,7 +52,7 @@
} }
function doSaveLocal(): void { function doSaveLocal(): void {
navigator.vibrate(20) vibrateIfPossible(20)
app.saveStateToLocalStorage(); app.saveStateToLocalStorage();
} }

View File

@@ -34,12 +34,12 @@
} }
async function refreshCombos() { async function refreshCombos() {
navigator.vibrate(20) vibrateIfPossible(20)
await app.refreshComboInNodes() await app.refreshComboInNodes()
} }
function doSaveLocal(): void { function doSaveLocal(): void {
navigator.vibrate(20) vibrateIfPossible(20)
app.saveStateToLocalStorage(); app.saveStateToLocalStorage();
} }

View File

@@ -3,6 +3,7 @@
import workflowState, { ComfyBoxWorkflow, type WorkflowInstID } from "$lib/stores/workflowState"; import workflowState, { ComfyBoxWorkflow, type WorkflowInstID } from "$lib/stores/workflowState";
import { onMount } from "svelte"; import { onMount } from "svelte";
import interfaceState from "$lib/stores/interfaceState"; import interfaceState from "$lib/stores/interfaceState";
import { vibrateIfPossible } from "$lib/utils";
import { f7 } from 'framework7-svelte'; import { f7 } from 'framework7-svelte';
import { XCircle } from 'svelte-bootstrap-icons'; import { XCircle } from 'svelte-bootstrap-icons';
@@ -31,7 +32,7 @@
if (!fileInput) if (!fileInput)
return; return;
navigator.vibrate(20) vibrateIfPossible(20);
fileInput.value = null; fileInput.value = null;
fileInput.click(); fileInput.click();
} }