From 58a222748cfa6a7a88bf1a5f3c47f1f301e602a3 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:42:51 +0000 Subject: [PATCH 1/9] Terminal support using node-pty --- builder-debug.config.ts | 1 + package.json | 1 + src/constants.ts | 4 +++ src/main.ts | 15 +++++++++ src/preload.ts | 34 ++++++++++++++++++++ src/terminal.ts | 69 +++++++++++++++++++++++++++++++++++++++++ yarn.lock | 13 +++++++- 7 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/terminal.ts diff --git a/builder-debug.config.ts b/builder-debug.config.ts index c3295ab2..4a044c41 100644 --- a/builder-debug.config.ts +++ b/builder-debug.config.ts @@ -22,6 +22,7 @@ const debugConfig: Configuration = { icon: './assets/UI/Comfy_Logo_x256.png', target: 'appimage', }, + asarUnpack: ['**/node_modules/node-pty/**/*'], }; export default debugConfig; diff --git a/package.json b/package.json index 718a06c2..65a8ae25 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "jest": "^29.7.0", "linkify-react": "^4.1.3", "linkifyjs": "^4.1.3", + "node-pty": "^1.0.0", "react": "^18.3.1", "react-dom": "^18.3.1", "systeminformation": "^5.23.5", diff --git a/src/constants.ts b/src/constants.ts index ccdddce7..b648bed6 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -24,6 +24,10 @@ export const IPC_CHANNELS = { OPEN_LOGS_PATH: 'open-logs-path', OPEN_DEV_TOOLS: 'open-dev-tools', OPEN_FORUM: 'open-forum', + TERMINAL_WRITE: "execute-terminal-command", + TERMINAL_RESIZE: "resize-terminal", + TERMINAL_RESTORE: "restore-terminal", + TERMINAL_ON_OUTPUT: 'terminal-output', } as const; export enum ProgressStatus { diff --git a/src/main.ts b/src/main.ts index 20dc4130..5c6e0028 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,6 +19,7 @@ import dotenv from 'dotenv'; import { buildMenu } from './menu/menu'; import { ComfyConfigManager } from './config/comfyConfigManager'; import { AppWindow } from './main-process/appWindow'; +import Terminal from './terminal'; dotenv.config(); @@ -195,6 +196,8 @@ if (!gotTheLock) { throw err; }); + Terminal.init(appWindow, path.join(appResourcesPath, 'ComfyUI')); + if (!useExternalServer) { sendProgressUpdate(ProgressStatus.PYTHON_SETUP); const pythonEnvironment = new PythonEnvironment(pythonInstallPath, appResourcesPath, spawnPythonAsync); @@ -249,6 +252,18 @@ if (!gotTheLock) { } }); }); + + ipcMain.handle(IPC_CHANNELS.TERMINAL_WRITE, (_event, command: string) => { + Terminal.write(command); + }); + + ipcMain.handle(IPC_CHANNELS.TERMINAL_RESIZE, (_event, cols: number, rows: number) => { + Terminal.resize(cols, rows); + }); + + ipcMain.handle(IPC_CHANNELS.TERMINAL_RESTORE, (_event) => { + return Terminal.restore(); + }); } function loadComfyIntoMainWindow() { diff --git a/src/preload.ts b/src/preload.ts index b900f0c2..6f76d88c 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -141,6 +141,40 @@ const electronAPI = { extras, }); }, + Terminal: { + /** + * Writes the data to the terminal + * @param data The command to execute + */ + write: (data: string): Promise => { + return ipcRenderer.invoke(IPC_CHANNELS.TERMINAL_WRITE, data); + }, + /** + * Resizes the terminal + * @param data The command to execute + */ + resize: (cols: number, rows: number): Promise => { + return ipcRenderer.invoke(IPC_CHANNELS.TERMINAL_RESIZE, cols, rows); + }, + /** + * Gets the data required to restore the terminal + * @param data The command to execute + */ + restore: (): Promise<{ buffer: string[]; pos: { x: number; y: number } }> => { + return ipcRenderer.invoke(IPC_CHANNELS.TERMINAL_RESTORE); + }, + /** + * Callback for terminal output messages + * @param callback The output handler + */ + onOutput: (callback: (message: string) => void) => { + const handler = (_event: Electron.IpcRendererEvent, value: string) => { + callback(value); + }; + ipcRenderer.on(IPC_CHANNELS.TERMINAL_ON_OUTPUT, handler); + return () => ipcRenderer.off(IPC_CHANNELS.TERMINAL_ON_OUTPUT, handler); + }, + }, } as const; export type ElectronAPI = typeof electronAPI; diff --git a/src/terminal.ts b/src/terminal.ts new file mode 100644 index 00000000..14a639e9 --- /dev/null +++ b/src/terminal.ts @@ -0,0 +1,69 @@ +import * as os from 'node:os'; +import * as pty from 'node-pty'; +import { AppWindow } from './main-process/appWindow'; +import { IPC_CHANNELS } from './constants'; + +class Terminal { + #pty: pty.IPty | undefined; + #window: AppWindow | undefined; + #cwd: string | undefined; + + readonly sessionBuffer: string[] = []; + readonly size = { cols: 80, rows: 30 }; + + get pty() { + this.#pty ??= this.#createPty(); + return this.#pty; + } + + get window() { + if (!this.#window) throw new Error('AppWindow not initialized.'); + return this.#window; + } + + init(window: AppWindow, cwd: string) { + this.#window = window; + this.#cwd = cwd; + } + + write(data: string) { + this.pty.write(data); + } + + resize(cols: number, rows: number) { + this.pty.resize(cols, rows); + this.size.cols = cols; + this.size.rows = rows; + } + + restore() { + return { + buffer: this.sessionBuffer, + size: this.size, + }; + } + + #createPty() { + const window = this.window; + // TODO: does this want to be a setting? + const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash'; + const instance = pty.spawn(shell, [], { + handleFlowControl: false, + conptyInheritCursor: false, + name: 'comfyui-terminal', + cols: this.size.cols, + rows: this.size.rows, + cwd: this.#cwd, + }); + + instance.onData((data) => { + this.sessionBuffer.push(data); + window.send(IPC_CHANNELS.TERMINAL_ON_OUTPUT, data); + if (this.sessionBuffer.length > 1000) this.sessionBuffer.shift(); + }); + + return instance; + } +} + +export default new Terminal(); diff --git a/yarn.lock b/yarn.lock index bc38ace4..e9de87ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -500,6 +500,7 @@ __metadata: linkify-react: "npm:^4.1.3" linkifyjs: "npm:^4.1.3" lint-staged: "npm:^15.2.10" + node-pty: "npm:^1.0.0" prettier: "npm:^3.3.3" react: "npm:^18.3.1" react-dom: "npm:^18.3.1" @@ -9815,7 +9816,7 @@ __metadata: languageName: node linkType: hard -"nan@npm:^2.14.0": +"nan@npm:^2.14.0, nan@npm:^2.17.0": version: 2.22.0 resolution: "nan@npm:2.22.0" dependencies: @@ -9959,6 +9960,16 @@ __metadata: languageName: node linkType: hard +"node-pty@npm:^1.0.0": + version: 1.0.0 + resolution: "node-pty@npm:1.0.0" + dependencies: + nan: "npm:^2.17.0" + node-gyp: "npm:latest" + checksum: 10c0/c308686826eb2f7616735f4c71e6e41ff630346b14319972dbdf9711640bc6975ce21eab66a47b7ce9a88c70308fe81bfd9840127388d5fa26c52afbad255871 + languageName: node + linkType: hard + "node-releases@npm:^2.0.18": version: 2.0.18 resolution: "node-releases@npm:2.0.18" From c4dd6abb0f464b1600add584078e1f9b27124319 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Wed, 13 Nov 2024 17:50:08 +0000 Subject: [PATCH 2/9] Add note about rebuild --- README.md | 18 ++++++++++++++++++ src/main.ts | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 96d6d84e..c92e67fa 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,24 @@ You can also build the package and/or distributables using the `make` command: yarn make ``` +If you get an error similar to: +``` +The module '/electron/node_modules/node-pty/build/Release/pty.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 115. This version of Node.js requires NODE_MODULE_VERSION 125. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`). +``` +You will need to rebuild the node-pty using [electron-rebuild](https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules), for example: +``` +npx electron-rebuild +``` +or if that fails +``` +yarn install -D electron-rebuild +rm -rf node_modules +rm yarn.lock +yarn install +electron-rebuild +``` + + # Release We use Todesktop to build and codesign our releases. To make a new release: diff --git a/src/main.ts b/src/main.ts index dac7fc2d..756cfd25 100644 --- a/src/main.ts +++ b/src/main.ts @@ -248,7 +248,7 @@ if (!gotTheLock) { } function loadComfyIntoMainWindow() { - appWindow.loadURL(`http://${host}:${port}`); + appWindow.loadURL(`http://localhost:${5174}`); } function restartApp({ customMessage, delay }: { customMessage?: string; delay?: number } = {}): void { function relaunchApplication(delay?: number) { @@ -365,8 +365,8 @@ const launchPythonServer = async ( '--output-directory', outputDirectoryPath, ...(process.env.COMFYUI_CPU_ONLY === 'true' ? ['--cpu'] : []), - '--front-end-root', - path.join(appResourcesPath, 'ComfyUI', 'web_custom_versions', 'desktop_app'), + // '--front-end-root', + // path.join(appResourcesPath, 'ComfyUI', 'web_custom_versions', 'desktop_app'), '--extra-model-paths-config', modelConfigPath, '--port', From 15fccea9c892562d93b7228f1e16457ce7661f27 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Wed, 13 Nov 2024 17:55:31 +0000 Subject: [PATCH 3/9] Format --- src/constants.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index f1f0556f..e1d56571 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -25,9 +25,9 @@ export const IPC_CHANNELS = { OPEN_LOGS_PATH: 'open-logs-path', OPEN_DEV_TOOLS: 'open-dev-tools', OPEN_FORUM: 'open-forum', - TERMINAL_WRITE: "execute-terminal-command", - TERMINAL_RESIZE: "resize-terminal", - TERMINAL_RESTORE: "restore-terminal", + TERMINAL_WRITE: 'execute-terminal-command', + TERMINAL_RESIZE: 'resize-terminal', + TERMINAL_RESTORE: 'restore-terminal', TERMINAL_ON_OUTPUT: 'terminal-output', IS_FIRST_TIME_SETUP: 'is-first-time-setup', } as const; From c67e0c29b03aa72fe51b70385b929a99c01289b0 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Sat, 16 Nov 2024 11:37:08 +0000 Subject: [PATCH 4/9] revert --- src/main.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 756cfd25..dac7fc2d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -248,7 +248,7 @@ if (!gotTheLock) { } function loadComfyIntoMainWindow() { - appWindow.loadURL(`http://localhost:${5174}`); + appWindow.loadURL(`http://${host}:${port}`); } function restartApp({ customMessage, delay }: { customMessage?: string; delay?: number } = {}): void { function relaunchApplication(delay?: number) { @@ -365,8 +365,8 @@ const launchPythonServer = async ( '--output-directory', outputDirectoryPath, ...(process.env.COMFYUI_CPU_ONLY === 'true' ? ['--cpu'] : []), - // '--front-end-root', - // path.join(appResourcesPath, 'ComfyUI', 'web_custom_versions', 'desktop_app'), + '--front-end-root', + path.join(appResourcesPath, 'ComfyUI', 'web_custom_versions', 'desktop_app'), '--extra-model-paths-config', modelConfigPath, '--port', From ec21b533b67f0e88580e03e8df9c1fe6a3f45869 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Sat, 16 Nov 2024 14:26:10 +0000 Subject: [PATCH 5/9] refactor terminal instance --- src/main.ts | 11 ++++++----- src/terminal.ts | 6 ++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main.ts b/src/main.ts index e301a60e..4be1e9a6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,7 +17,7 @@ import dotenv from 'dotenv'; import { buildMenu } from './menu/menu'; import { ComfyConfigManager } from './config/comfyConfigManager'; import { AppWindow } from './main-process/appWindow'; -import Terminal from './terminal'; +import { Terminal } from './terminal'; import { getAppResourcesPath, getBasePath, getPythonInstallPath } from './install/resourcePaths'; import { PathHandlers } from './handlers/pathHandlers'; import { AppInfoHandlers } from './handlers/appInfoHandlers'; @@ -41,6 +41,7 @@ const useExternalServer = process.env.USE_EXTERNAL_SERVER === 'true'; let appWindow: AppWindow; let downloadManager: DownloadManager; +let terminal: Terminal; log.initialize(); @@ -177,7 +178,7 @@ if (!gotTheLock) { const urlPath = firstTimeSetup ? 'welcome' : 'server-start'; await appWindow.loadRenderer(urlPath); - Terminal.init(appWindow, path.join(await getAppResourcesPath(), 'ComfyUI')); + terminal = new Terminal(appWindow, path.join(await getAppResourcesPath(), 'ComfyUI')); if (!firstTimeSetup) { await serverStart(); @@ -220,15 +221,15 @@ if (!gotTheLock) { }); ipcMain.handle(IPC_CHANNELS.TERMINAL_WRITE, (_event, command: string) => { - Terminal.write(command); + terminal.write(command); }); ipcMain.handle(IPC_CHANNELS.TERMINAL_RESIZE, (_event, cols: number, rows: number) => { - Terminal.resize(cols, rows); + terminal.resize(cols, rows); }); ipcMain.handle(IPC_CHANNELS.TERMINAL_RESTORE, (_event) => { - return Terminal.restore(); + return terminal.restore(); }); } diff --git a/src/terminal.ts b/src/terminal.ts index 14a639e9..80887fe0 100644 --- a/src/terminal.ts +++ b/src/terminal.ts @@ -3,7 +3,7 @@ import * as pty from 'node-pty'; import { AppWindow } from './main-process/appWindow'; import { IPC_CHANNELS } from './constants'; -class Terminal { +export class Terminal { #pty: pty.IPty | undefined; #window: AppWindow | undefined; #cwd: string | undefined; @@ -21,7 +21,7 @@ class Terminal { return this.#window; } - init(window: AppWindow, cwd: string) { + constructor(window: AppWindow, cwd: string) { this.#window = window; this.#cwd = cwd; } @@ -65,5 +65,3 @@ class Terminal { return instance; } } - -export default new Terminal(); From bd80f9a83a692ee55827653fe538095df871dcf0 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Sat, 16 Nov 2024 14:26:36 +0000 Subject: [PATCH 6/9] Format --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dff42c25..733f3af0 100644 --- a/README.md +++ b/README.md @@ -151,20 +151,25 @@ yarn make ``` If you get an error similar to: + ``` The module '/electron/node_modules/node-pty/build/Release/pty.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 115. This version of Node.js requires NODE_MODULE_VERSION 125. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`). ``` + You will need to rebuild the node-pty using [electron-rebuild](https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules), for example: + ``` npx electron-rebuild ``` + or if that fails + ``` yarn install -D electron-rebuild rm -rf node_modules rm yarn.lock yarn install -electron-rebuild +electron-rebuild ``` ### Debugger From 8f41ca34bf073068fece2676cb083f194a260a57 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Mon, 18 Nov 2024 13:38:42 -0800 Subject: [PATCH 7/9] Update frontend version to be compatible. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2a3bd73c..56c73a68 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "main": ".vite/build/main.js", "packageManager": "yarn@4.5.0", "config": { - "frontendVersion": "1.4.0", + "frontendVersion": "1.4.2", "comfyVersion": "0.2.7", "managerCommit": "e629215c100c89a9a9d33fc03be3248069ff67ef", "uvVersion": "0.5.1" From 57e100c999a80e6957d427d8c59fd6484900c418 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Mon, 18 Nov 2024 14:45:50 -0800 Subject: [PATCH 8/9] Adding @electron/rebuild. --- README.md | 2 +- package.json | 1 + yarn.lock | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 733f3af0..23c781bb 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ npx electron-rebuild or if that fails ``` -yarn install -D electron-rebuild +yarn install -D @electron/rebuild rm -rf node_modules rm yarn.lock yarn install diff --git a/package.json b/package.json index 56c73a68..e54a6f53 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "devDependencies": { "@electron/fuses": "^1.8.0", "@electron/notarize": "^2.4.0", + "@electron/rebuild": "^3.7.1", "@electron/windows-sign": "^1.1.3", "@playwright/test": "^1.47.2", "@sentry/wizard": "^3.30.0", diff --git a/yarn.lock b/yarn.lock index 54cf1e8e..cb7f9f60 100644 --- a/yarn.lock +++ b/yarn.lock @@ -470,6 +470,7 @@ __metadata: dependencies: "@electron/fuses": "npm:^1.8.0" "@electron/notarize": "npm:^2.4.0" + "@electron/rebuild": "npm:^3.7.1" "@electron/windows-sign": "npm:^1.1.3" "@playwright/test": "npm:^1.47.2" "@sentry/electron": "npm:^5.4.0" @@ -577,6 +578,26 @@ __metadata: languageName: node linkType: hard +"@electron/node-gyp@git+https://github.com/electron/node-gyp.git#06b29aafb7708acef8b3669835c8a7857ebc92d2": + version: 10.2.0-electron.1 + resolution: "@electron/node-gyp@https://github.com/electron/node-gyp.git#commit=06b29aafb7708acef8b3669835c8a7857ebc92d2" + dependencies: + env-paths: "npm:^2.2.0" + exponential-backoff: "npm:^3.1.1" + glob: "npm:^8.1.0" + graceful-fs: "npm:^4.2.6" + make-fetch-happen: "npm:^10.2.1" + nopt: "npm:^6.0.0" + proc-log: "npm:^2.0.1" + semver: "npm:^7.3.5" + tar: "npm:^6.2.1" + which: "npm:^2.0.2" + bin: + node-gyp: ./bin/node-gyp.js + checksum: 10c0/e8c97bb5347bf0871312860010b70379069359bf05a6beb9e4d898d0831f9f8447f35b887a86d5241989e804813cf72054327928da38714a6102f791e802c8d9 + languageName: node + linkType: hard + "@electron/notarize@npm:2.5.0, @electron/notarize@npm:^2.4.0": version: 2.5.0 resolution: "@electron/notarize@npm:2.5.0" @@ -629,6 +650,31 @@ __metadata: languageName: node linkType: hard +"@electron/rebuild@npm:^3.7.1": + version: 3.7.1 + resolution: "@electron/rebuild@npm:3.7.1" + dependencies: + "@electron/node-gyp": "git+https://github.com/electron/node-gyp.git#06b29aafb7708acef8b3669835c8a7857ebc92d2" + "@malept/cross-spawn-promise": "npm:^2.0.0" + chalk: "npm:^4.0.0" + debug: "npm:^4.1.1" + detect-libc: "npm:^2.0.1" + fs-extra: "npm:^10.0.0" + got: "npm:^11.7.0" + node-abi: "npm:^3.45.0" + node-api-version: "npm:^0.2.0" + node-gyp: "npm:latest" + ora: "npm:^5.1.0" + read-binary-file-arch: "npm:^1.0.6" + semver: "npm:^7.3.5" + tar: "npm:^6.0.5" + yargs: "npm:^17.0.1" + bin: + electron-rebuild: lib/cli.js + checksum: 10c0/ef498ec1eb6d2870f4331dd53d84132a4fb7d2ef6a0058854731d3261fc0af3e2c8549c1c268801b7c2c9e93519b22d67b2a4fe7ed0136214100980801e2a372 + languageName: node + linkType: hard + "@electron/universal@npm:2.0.1": version: 2.0.1 resolution: "@electron/universal@npm:2.0.1" @@ -9365,7 +9411,7 @@ __metadata: languageName: node linkType: hard -"make-fetch-happen@npm:^10.0.3": +"make-fetch-happen@npm:^10.0.3, make-fetch-happen@npm:^10.2.1": version: 10.2.1 resolution: "make-fetch-happen@npm:10.2.1" dependencies: @@ -10738,6 +10784,13 @@ __metadata: languageName: node linkType: hard +"proc-log@npm:^2.0.1": + version: 2.0.1 + resolution: "proc-log@npm:2.0.1" + checksum: 10c0/701c501429775ce34cec28ef6a1c976537274b42917212fb8a5975ebcecb0a85612907fd7f99ff28ff4c2112bb84a0f4322fc9b9e1e52a8562fcbb1d5b3ce608 + languageName: node + linkType: hard + "proc-log@npm:^4.1.0, proc-log@npm:^4.2.0": version: 4.2.0 resolution: "proc-log@npm:4.2.0" From ab322881008059db2ce06d6a98370dcf30b33108 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Mon, 18 Nov 2024 16:37:05 -0800 Subject: [PATCH 9/9] Reorganize Terminal into ComfyDesktopApp class. --- src/main-process/comfyDesktopApp.ts | 19 ++++++++++++++++++- src/main.ts | 16 +--------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main-process/comfyDesktopApp.ts b/src/main-process/comfyDesktopApp.ts index e5619b58..e6c93042 100644 --- a/src/main-process/comfyDesktopApp.ts +++ b/src/main-process/comfyDesktopApp.ts @@ -15,15 +15,20 @@ import path from 'path'; import { getModelsDirectory } from '../utils'; import { DownloadManager } from '../models/DownloadManager'; import { VirtualEnvironment } from '../virtualEnvironment'; +import { Terminal } from '../terminal'; +import { getAppResourcesPath } from '../install/resourcePaths'; export class ComfyDesktopApp { public comfyServer: ComfyServer | null = null; + private terminal: Terminal; constructor( public basePath: string, public comfySettings: ComfySettings, public appWindow: AppWindow - ) {} + ) { + this.terminal = new Terminal(this.appWindow, getAppResourcesPath()); + } get pythonInstallPath() { return app.isPackaged ? this.basePath : path.join(app.getAppPath(), 'assets'); @@ -104,6 +109,18 @@ export class ComfyDesktopApp { return null; } }); + + ipcMain.handle(IPC_CHANNELS.TERMINAL_WRITE, (_event, command: string) => { + this.terminal.write(command); + }); + + ipcMain.handle(IPC_CHANNELS.TERMINAL_RESIZE, (_event, cols: number, rows: number) => { + this.terminal.resize(cols, rows); + }); + + ipcMain.handle(IPC_CHANNELS.TERMINAL_RESTORE, (_event) => { + return this.terminal.restore(); + }); } /** diff --git a/src/main.ts b/src/main.ts index a9e2b216..f44838f9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,6 @@ import * as Sentry from '@sentry/electron/main'; import { findAvailablePort } from './utils'; import dotenv from 'dotenv'; import { AppWindow } from './main-process/appWindow'; -import { Terminal } from './terminal'; import { PathHandlers } from './handlers/pathHandlers'; import { AppInfoHandlers } from './handlers/appInfoHandlers'; import { ComfyDesktopApp } from './main-process/comfyDesktopApp'; @@ -66,7 +65,7 @@ if (!gotTheLock) { log.debug('App ready'); const appWindow = new AppWindow(); - + // Register basic handlers that are necessary during app's installation. new PathHandlers().registerHandlers(); new AppInfoHandlers().registerHandlers(); @@ -76,19 +75,6 @@ if (!gotTheLock) { ...options, }); }); - terminal = new Terminal(appWindow, path.join(await getAppResourcesPath(), 'ComfyUI')); - ipcMain.handle(IPC_CHANNELS.TERMINAL_WRITE, (_event, command: string) => { - terminal.write(command); - }); - - ipcMain.handle(IPC_CHANNELS.TERMINAL_RESIZE, (_event, cols: number, rows: number) => { - terminal.resize(cols, rows); - }); - - ipcMain.handle(IPC_CHANNELS.TERMINAL_RESTORE, (_event) => { - return terminal.restore(); - }); - try { const comfyDesktopApp = await ComfyDesktopApp.create(appWindow); await comfyDesktopApp.initialize();