Skip to content

Commit

Permalink
Extract comfyui container as component
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Oct 24, 2024
1 parent 8bdc629 commit 9501029
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 40 deletions.
63 changes: 63 additions & 0 deletions src/renderer/components/ComfyUIContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { useEffect, useState } from 'react';
import LogViewer from './LogViewer';
import { ElectronAPI } from 'src/preload';
import { ELECTRON_BRIDGE_API } from 'src/constants';

interface ComfyUIContainerProps {
comfyPort: number;
preloadScript: string;
showStreamingLogs: boolean;
onCloseLogViewer: () => void;
}

const iframeContainerStyle: React.CSSProperties = {
display: 'flex',
flexDirection: 'column',
height: '100vh',
margin: '0',
padding: '0',
};

const iframeStyle: React.CSSProperties = {
flexGrow: 1,
border: 'none',
width: '100%',
height: '100%',
};

const logContainerStyle: React.CSSProperties = {
height: '300px',
};

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

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

electronAPI.onToggleLogsView(() => {
setShowStreamingLogs((prevState) => !prevState);
});
}, []);

return (
<div style={iframeContainerStyle}>
<webview
id="comfy-container"
src={`http://localhost:${comfyPort}`}
style={iframeStyle}
preload={`file://${preloadScript}`}
/>
{showStreamingLogs && (
<div style={logContainerStyle}>
<LogViewer onClose={() => setShowStreamingLogs(false)} />
</div>
)}
</div>
);
};

export default ComfyUIContainer;
File renamed without changes.
46 changes: 6 additions & 40 deletions src/renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import log from 'electron-log/renderer';
import FirstTimeSetup from './screens/FirstTimeSetup';
import { ElectronAPI } from 'src/preload';
import { ELECTRON_BRIDGE_API } from 'src/constants';
import LogViewer from './screens/LogViewer';
import path from 'path';
import ComfyUIContainer from './components/ComfyUIContainer';

export interface ProgressUpdate {
status: string;
overwrite?: boolean;
Expand All @@ -23,25 +23,6 @@ const bodyStyle: React.CSSProperties = {
backgroundColor: '#1e1e1e',
};

const iframeStyle: React.CSSProperties = {
flexGrow: 1,
border: 'none',
width: '100%',
height: '100%',
};

const logContainerStyle: React.CSSProperties = {
height: '300px',
};

const iframeContainerStyle: React.CSSProperties = {
display: 'flex',
flexDirection: 'column',
height: '100vh',
margin: '0',
padding: '0',
};

// Main entry point for the front end renderer.
// Currently this serves as the overlay to show progress as the comfy backend is coming online.
// after coming online the main.ts will replace the renderer with comfy's internal index.html
Expand All @@ -50,7 +31,6 @@ const Home: React.FC = () => {
const [status, setStatus] = useState('Starting...');
const [logs, setLogs] = useState<string[]>([]);
const [defaultInstallLocation, setDefaultInstallLocation] = useState<string>('');
const [showStreamingLogs, setShowStreamingLogs] = useState(false);
const [comfyReady, setComfyReady] = useState(false);
const [comfyPort, setComfyPort] = useState<number | null>(null);
const [preloadScript, setPreloadScript] = useState<string>('');
Expand Down Expand Up @@ -81,11 +61,6 @@ const Home: React.FC = () => {
setShowSetup(false);
});

electronAPI.onToggleLogsView(() => {
log.info('Toggling logs view');
setShowStreamingLogs((prevState) => !prevState);
});

electronAPI.onComfyUIReady((port: number) => {
log.info('ComfyUI ready');
setComfyPort(port);
Expand Down Expand Up @@ -130,19 +105,10 @@ const Home: React.FC = () => {

if (comfyReady && comfyPort) {
return (
<div style={iframeContainerStyle}>
<webview
id="comfy-container"
src={`http://localhost:${comfyPort}`}
style={iframeStyle}
preload={`file://${preloadScript}`}
/>
{showStreamingLogs && (
<div style={logContainerStyle}>
<LogViewer onClose={() => setShowStreamingLogs(false)} />
</div>
)}
</div>
<ComfyUIContainer
comfyPort={comfyPort}
preloadScript={preloadScript}
/>
);
}

Expand Down

0 comments on commit 9501029

Please sign in to comment.