diff --git a/src/constants.ts b/src/constants.ts index 820d9473..86197635 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -9,8 +9,6 @@ export const IPC_CHANNELS = { OPEN_DIALOG: 'open-dialog', FIRST_TIME_SETUP_COMPLETE: 'first-time-setup-complete', DEFAULT_INSTALL_LOCATION: 'default-install-location', - GET_COMFYUI_URL: 'get-comfyui-url', - COMFYUI_READY: 'comfyui-ready', GET_PRELOAD_SCRIPT: 'get-preload-script', OPEN_DEVTOOLS: 'open-devtools', OPEN_LOGS_FOLDER: 'open-logs-folder', diff --git a/src/main.ts b/src/main.ts index 6bfd8ef3..2837403c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,7 +11,7 @@ import { IPCChannel, SENTRY_URL_ENDPOINT, } from './constants'; -import { app, BrowserWindow, dialog, screen, ipcMain, Menu, MenuItem, globalShortcut, shell } from 'electron'; +import { app, BrowserWindow, dialog, screen, ipcMain, Menu, MenuItem, shell } from 'electron'; import log from 'electron-log/main'; import * as Sentry from '@sentry/electron/main'; import Store from 'electron-store'; @@ -20,7 +20,6 @@ import { graphics } from 'systeminformation'; import { createModelConfigFiles, readBasePathFromConfig } from './config/extra_model_config'; import { WebSocketServer } from 'ws'; import { StoreType } from './store'; -import { createReadStream, watchFile } from 'node:fs'; import todesktop from '@todesktop/runtime'; import { PythonEnvironment } from './pythonEnvironment'; import { DownloadManager } from './models/DownloadManager'; @@ -69,9 +68,6 @@ app.on('before-quit', async () => { log.error(error); } - closeWebSocketServer(); - globalShortcut.unregisterAll(); - app.exit(); }); @@ -112,8 +108,6 @@ if (!gotTheLock) { graphics() .then((graphicsInfo) => { - log.info('GPU Info: ', graphicsInfo); - const gpuInfo = graphicsInfo.controllers.map((gpu, index) => ({ [`gpu_${index}`]: { vendor: gpu.vendor, @@ -125,7 +119,6 @@ if (!gotTheLock) { // Combine all GPU info into a single object const allGpuInfo = Object.assign({}, ...gpuInfo); - log.info('GPU Info: ', allGpuInfo); // Set Sentry context with all GPU information Sentry.setContext('gpus', allGpuInfo); }) @@ -155,7 +148,7 @@ if (!gotTheLock) { log.error('ERROR: Main window not found!'); return; } - startWebSocketServer(); + mainWindow.on('close', () => { mainWindow = null; app.quit(); @@ -228,10 +221,6 @@ if (!gotTheLock) { } } ); - - ipcMain.handle(IPC_CHANNELS.GET_COMFYUI_URL, () => { - return `http://${host}:${port}`; - }); }); } @@ -240,7 +229,7 @@ function loadComfyIntoMainWindow() { log.error('Trying to load ComfyUI into main window but it is not ready yet.'); return; } - mainWindow.webContents.send(IPC_CHANNELS.COMFYUI_READY, port); + mainWindow.loadURL(`http://${host}:${port}`); } async function loadRendererIntoMainWindow(): Promise { @@ -252,7 +241,7 @@ async function loadRendererIntoMainWindow(): Promise { log.info('Loading Vite Dev Server'); await mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL); log.info('Opened Vite Dev Server'); - //mainWindow.webContents.openDevTools(); + mainWindow.webContents.openDevTools(); } else { mainWindow.loadFile(path.join(__dirname, `../renderer/index.html`)); } @@ -895,48 +884,6 @@ function getDefaultUserResourcesPath(): string { return process.platform === 'win32' ? path.join(app.getPath('home'), 'comfyui-electron') : app.getPath('userData'); } -/** - * For log watching. - */ -function startWebSocketServer() { - wss = new WebSocketServer({ port: 7999 }); - - wss.on('connection', (ws) => { - const logPath = path.join(app.getPath('logs'), 'comfyui.log'); - - // Send the initial content - const initialStream = createReadStream(logPath, { encoding: 'utf-8' }); - initialStream.on('data', (chunk) => { - ws.send(chunk); - }); - - let lastSize = 0; - const watcher = watchFile(logPath, { interval: 1000 }, (curr, prev) => { - if (curr.size > lastSize) { - const stream = createReadStream(logPath, { - start: lastSize, - encoding: 'utf-8', - }); - stream.on('data', (chunk) => { - ws.send(chunk); - }); - lastSize = curr.size; - } - }); - - ws.on('close', () => { - watcher.unref(); - }); - }); -} - -function closeWebSocketServer() { - if (wss) { - wss.close(); - wss = null; - } -} - /** * Rotate old log files by adding a timestamp to the end of the file. * @param logDir The directory to rotate the logs in. diff --git a/src/preload.ts b/src/preload.ts index e2edae6b..3d2a13fe 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -20,14 +20,11 @@ export interface ElectronAPI { onLogMessage: (callback: (message: string) => void) => void; onFirstTimeSetupComplete: (callback: () => void) => void; onDefaultInstallLocation: (callback: (location: string) => void) => void; - onComfyUIReady: (callback: (port: number) => void) => void; sendReady: () => void; restartApp: (customMessage?: string, delay?: number) => void; onOpenDevTools: (callback: () => void) => void; isPackaged: () => Promise; openDialog: (options: Electron.OpenDialogOptions) => Promise; - getComfyUIUrl: () => Promise; - getPreloadScript: () => Promise; /** * Open the logs folder in the system's default file explorer. */ @@ -63,9 +60,6 @@ const electronAPI: ElectronAPI = { callback(value); }); }, - onComfyUIReady: (callback: (port: number) => void) => { - ipcRenderer.on(IPC_CHANNELS.COMFYUI_READY, (_event, port: number) => callback(port)); - }, sendReady: () => { console.log('Sending ready event to main process'); ipcRenderer.send(IPC_CHANNELS.RENDERER_READY); @@ -86,12 +80,6 @@ const electronAPI: ElectronAPI = { selectSetupDirectory: (directory: string) => { ipcRenderer.send(IPC_CHANNELS.SELECTED_DIRECTORY, directory); }, - getComfyUIUrl: (): Promise => { - return ipcRenderer.invoke(IPC_CHANNELS.GET_COMFYUI_URL); - }, - getPreloadScript: (): Promise => { - return ipcRenderer.invoke(IPC_CHANNELS.GET_PRELOAD_SCRIPT); - }, openDialog: (options: Electron.OpenDialogOptions) => { return ipcRenderer.invoke(IPC_CHANNELS.OPEN_DIALOG, options); }, diff --git a/src/pythonEnvironment.ts b/src/pythonEnvironment.ts index 3b33e263..4c7483ac 100644 --- a/src/pythonEnvironment.ts +++ b/src/pythonEnvironment.ts @@ -60,6 +60,7 @@ export class PythonEnvironment { } async isInstalled(): Promise { + log.info(`Checking if Python is installed at ${this.pythonInterpreterPath} and ${this.pythonRecordPath}`); return (await pathAccessible(this.pythonInterpreterPath)) && (await pathAccessible(this.pythonRecordPath)); } diff --git a/src/renderer/components/ComfyUIContainer.tsx b/src/renderer/components/ComfyUIContainer.tsx deleted file mode 100644 index 78ebf87b..00000000 --- a/src/renderer/components/ComfyUIContainer.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import React, { useEffect, useRef } from 'react'; -import { ElectronAPI } from 'src/preload'; -import { ELECTRON_BRIDGE_API } from 'src/constants'; -import { WebviewTag } from 'electron'; - -interface ComfyUIContainerProps { - comfyPort: number; - preloadScript: string; -} - -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 = ({ comfyPort, preloadScript }) => { - const webviewRef = useRef(null); - - useEffect(() => { - const electronAPI: ElectronAPI = (window as any)[ELECTRON_BRIDGE_API]; - - electronAPI.onOpenDevTools(() => { - webviewRef.current?.openDevTools(); - }); - }, []); - - return ( -
- -
- ); -}; - -export default ComfyUIContainer; diff --git a/src/renderer/index.tsx b/src/renderer/index.tsx index 1a14e5b8..ebe7f087 100644 --- a/src/renderer/index.tsx +++ b/src/renderer/index.tsx @@ -4,7 +4,6 @@ import log from 'electron-log/renderer'; import FirstTimeSetup from './screens/FirstTimeSetup'; import { ElectronAPI } from 'src/preload'; import { ELECTRON_BRIDGE_API } from 'src/constants'; -import ComfyUIContainer from './components/ComfyUIContainer'; export interface ProgressUpdate { status: string; @@ -31,9 +30,6 @@ const Home: React.FC = () => { const [status, setStatus] = useState('Starting...'); const [logs, setLogs] = useState([]); const [defaultInstallLocation, setDefaultInstallLocation] = useState(''); - const [comfyReady, setComfyReady] = useState(false); - const [comfyPort, setComfyPort] = useState(null); - const [preloadScript, setPreloadScript] = useState(''); const updateProgress = useCallback(({ status: newStatus }: ProgressUpdate) => { log.info(`Setting new status: ${newStatus}`); @@ -60,16 +56,6 @@ const Home: React.FC = () => { log.info('First time setup complete'); setShowSetup(false); }); - - electronAPI.onComfyUIReady((port: number) => { - log.info('ComfyUI ready'); - setComfyPort(port); - setComfyReady(true); - }); - - electronAPI.getPreloadScript().then((script) => { - setPreloadScript(script); - }); }, []); useEffect(() => { @@ -81,7 +67,7 @@ const Home: React.FC = () => { log.info(`Received log message: ${message}`); addLogMessage(message); }); - }, [updateProgress, addLogMessage, setComfyPort]); + }, [updateProgress, addLogMessage]); useEffect(() => { const electronAPI: ElectronAPI = (window as any)[ELECTRON_BRIDGE_API]; @@ -103,10 +89,6 @@ const Home: React.FC = () => { ); } - if (comfyReady && comfyPort) { - return ; - } - return (