Skip to content

Commit

Permalink
Add open devtools (ComfyUI) tray action
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Oct 26, 2024
1 parent 968cfe9 commit 1415902
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const IPC_CHANNELS = {
TOGGLE_LOGS: 'toggle-logs',
COMFYUI_READY: 'comfyui-ready',
GET_PRELOAD_SCRIPT: 'get-preload-script',
OPEN_DEVTOOLS: 'open-devtools',
} as const;

export const COMFY_ERROR_MESSAGE =
Expand Down
4 changes: 4 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ElectronAPI {
sendReady: () => void;
restartApp: () => void;
onToggleLogsView: (callback: () => void) => void;
onOpenDevTools: (callback: () => void) => void;
isPackaged: () => Promise<boolean>;
openDialog: (options: Electron.OpenDialogOptions) => Promise<string[] | undefined>;
getComfyUIUrl: () => Promise<string>;
Expand Down Expand Up @@ -60,6 +61,9 @@ const electronAPI: ElectronAPI = {
onToggleLogsView: (callback: () => void) => {
ipcRenderer.on(IPC_CHANNELS.TOGGLE_LOGS, () => callback());
},
onOpenDevTools: (callback: () => void) => {
ipcRenderer.on(IPC_CHANNELS.OPEN_DEVTOOLS, () => callback());
},
onShowSelectDirectory: (callback: () => void) => {
ipcRenderer.on(IPC_CHANNELS.SHOW_SELECT_DIRECTORY, () => callback());
},
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/components/ComfyUIContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import LogViewer from './LogViewer';
import { ElectronAPI } from 'src/preload';
import { ELECTRON_BRIDGE_API } from 'src/constants';
import { WebviewTag } from 'electron';

interface ComfyUIContainerProps {
comfyPort: number;
Expand Down Expand Up @@ -29,13 +30,17 @@ const logContainerStyle: React.CSSProperties = {

const ComfyUIContainer: React.FC<ComfyUIContainerProps> = ({ comfyPort, preloadScript }) => {
const [showStreamingLogs, setShowStreamingLogs] = useState(false);
const webviewRef = useRef<WebviewTag>(null);

useEffect(() => {
const electronAPI: ElectronAPI = (window as any)[ELECTRON_BRIDGE_API];

electronAPI.onToggleLogsView(() => {
setShowStreamingLogs((prevState) => !prevState);
});
electronAPI.onOpenDevTools(() => {
webviewRef.current?.openDevTools();
});
}, []);

return (
Expand All @@ -45,6 +50,7 @@ const ComfyUIContainer: React.FC<ComfyUIContainerProps> = ({ comfyPort, preloadS
src={`http://localhost:${comfyPort}`}
style={iframeStyle}
preload={`file://${preloadScript}`}
ref={webviewRef}
/>
{showStreamingLogs && (
<div style={logContainerStyle}>
Expand Down
7 changes: 6 additions & 1 deletion src/tray.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Tray, Menu, BrowserWindow, app, shell } from 'electron';
import path from 'path';
import { IPC_CHANNELS } from './constants';

export function SetupTray(
mainView: BrowserWindow,
Expand Down Expand Up @@ -83,9 +84,13 @@ export function SetupTray(
click: () => shell.openPath(app.getPath('logs')),
},
{
label: 'Open devtools',
label: 'Open devtools (Electron)',
click: () => mainView.webContents.openDevTools(),
},
{
label: 'Open devtools (ComfyUI)',
click: () => mainView.webContents.send(IPC_CHANNELS.OPEN_DEVTOOLS),
},
{
label: 'Toggle Log Viewer',
click: () => toggleLogs(),
Expand Down

0 comments on commit 1415902

Please sign in to comment.