diff --git a/src/main.ts b/src/main.ts index aa976f45..3a34412f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -179,6 +179,15 @@ if (!gotTheLock) { }); await handleFirstTimeSetup(); const { appResourcesPath, pythonInstallPath, modelConfigPath, basePath } = await determineResourcesPaths(); + + port = await findAvailablePort(8000, 9999).catch((err) => { + log.error(`ERROR: Failed to find available port: ${err}`); + throw err; + }); + + sendProgressUpdate('Setting up Python Environment...'); + const pythonEnvironment = new PythonEnvironment(pythonInstallPath, appResourcesPath, spawnPythonAsync); + await pythonEnvironment.setup(); SetupTray( mainWindow, basePath, @@ -190,17 +199,9 @@ if (!gotTheLock) { }, () => { mainWindow.webContents.send(IPC_CHANNELS.TOGGLE_LOGS); - } + }, + pythonEnvironment.pythonInterpreterPath ); - port = await findAvailablePort(8000, 9999).catch((err) => { - log.error(`ERROR: Failed to find available port: ${err}`); - throw err; - }); - - sendProgressUpdate('Setting up Python Environment...'); - const pythonEnvironment = new PythonEnvironment(pythonInstallPath, appResourcesPath, spawnPythonAsync); - await pythonEnvironment.setup(); - sendProgressUpdate('Starting Comfy Server...'); await launchPythonServer(pythonEnvironment.pythonInterpreterPath, appResourcesPath, modelConfigPath, basePath); } catch (error) { diff --git a/src/tray.ts b/src/tray.ts index 5db1c04a..ff36228a 100644 --- a/src/tray.ts +++ b/src/tray.ts @@ -1,13 +1,17 @@ import { Tray, Menu, BrowserWindow, app, shell } from 'electron'; import path from 'path'; import { IPC_CHANNELS } from './constants'; +import { exec } from 'child_process'; +import log from 'electron-log/main'; +import { PythonEnvironment } from './pythonEnvironment'; export function SetupTray( mainView: BrowserWindow, basePath: string, modelConfigPath: string, reinstall: () => void, - toggleLogs: () => void + toggleLogs: () => void, + pythonEnvironment: PythonEnvironment ): Tray { // Set icon for the tray // I think there is a way to packaged the icon in so you don't need to reference resourcesPath @@ -95,6 +99,26 @@ export function SetupTray( label: 'Toggle Log Viewer', click: () => toggleLogs(), }, + { + label: 'Install Python Packages (Open Terminal)', + click: () => { + // Open a Terminal locally and + const pythonDir = path.dirname(pythonEnvironment.pythonInterpreterPath); + const pythonExe = path.basename(pythonEnvironment.pythonInterpreterPath); + const command = + process.platform === 'win32' + ? `start powershell.exe -noexit -command "cd '${pythonDir}'; .\\${pythonExe} -m pip list"` + : `osascript -e 'tell application "Terminal" + do script "cd \\"${pythonDir}\\" && ./${pythonExe} -m pip list" + activate + end tell'`; + exec(command, (error, stdout, stderr) => { + if (error) { + log.error(`Error executing command: ${error}`); + } + }); + }, + }, ]); tray.setContextMenu(contextMenu);