From 63d6b4e69cd0d4af3efa232f1dc7bdf7872d78d7 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Tue, 15 Oct 2024 15:52:24 -0700 Subject: [PATCH] Don't install uv. (#90) * Remove uv installation. * Accumulate logs in renderer Home component. * Check if install location is a directory or not. * Prettier. * Default open dialog in Documents. * Remove directory check. --- src/main.ts | 20 +--------- src/renderer/index.tsx | 30 ++++++++++++++- src/renderer/screens/ProgressOverlay.tsx | 49 +++--------------------- 3 files changed, 37 insertions(+), 62 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4a0f22eb..459b6e90 100644 --- a/src/main.ts +++ b/src/main.ts @@ -168,7 +168,7 @@ if (!gotTheLock) { log.info('Open dialog'); return dialog.showOpenDialogSync({ ...options, - defaultPath: app.getPath('desktop'), + defaultPath: app.getPath('documents'), }); }); await handleFirstTimeSetup(); @@ -659,19 +659,6 @@ async function setupPythonEnvironment(appResourcesPath: string, pythonResourcesP rehydrateCmd = ['-m', 'uv', 'pip', 'install', '-r', reqPath, '--index-strategy', 'unsafe-best-match']; } - //TODO(robinhuang): remove this once uv is included in the python bundle. - const { exitCode: uvExitCode } = await spawnPythonAsync( - pythonInterpreterPath, - ['-m', 'pip', 'install', '--upgrade', 'uv'], - pythonRootPath, - { stdx: true } - ); - - if (uvExitCode !== 0) { - log.error('Failed to install uv'); - throw new Error('Failed to install uv'); - } - const { exitCode } = await spawnPythonAsync(pythonInterpreterPath, rehydrateCmd, pythonRootPath, { stdx: true }); if (exitCode === 0) { @@ -701,10 +688,6 @@ type DirectoryStructure = (string | [string, string[]])[]; // Create directories needed by ComfyUI in the user's data directory. function createComfyDirectories(localComfyDirectory: string): void { - if (!localComfyDirectory.endsWith('ComfyUI')) { - localComfyDirectory = path.join(localComfyDirectory, 'ComfyUI'); - } - log.info(`Creating ComfyUI directories in ${localComfyDirectory}`); const directories: DirectoryStructure = [ @@ -846,6 +829,7 @@ async function handleFirstTimeSetup() { ); selectedDirectory = path.join(selectedDirectory, 'ComfyUI'); } + createComfyDirectories(selectedDirectory); const { modelConfigPath } = await determineResourcesPaths(); diff --git a/src/renderer/index.tsx b/src/renderer/index.tsx index 7b8bd0f2..86eefa24 100644 --- a/src/renderer/index.tsx +++ b/src/renderer/index.tsx @@ -5,6 +5,11 @@ import FirstTimeSetup from './screens/FirstTimeSetup'; import { ElectronAPI } from 'src/preload'; import { ELECTRON_BRIDGE_API } from 'src/constants'; +export interface ProgressUpdate { + status: string; + overwrite?: boolean; +} + const bodyStyle: React.CSSProperties = { fontFamily: 'Arial, sans-serif', display: 'flex', @@ -22,6 +27,18 @@ const bodyStyle: React.CSSProperties = { // after coming online the main.ts will replace the renderer with comfy's internal index.html const Home: React.FC = () => { const [showSetup, setShowSetup] = useState(null); + const [status, setStatus] = useState('Starting...'); + const [logs, setLogs] = useState([]); + + const updateProgress = useCallback(({ status: newStatus }: ProgressUpdate) => { + log.info(`Setting new status: ${newStatus}`); + setStatus(newStatus); + setLogs([]); // Clear logs when status changes + }, []); + + const addLogMessage = useCallback((message: string) => { + setLogs((prevLogs) => [...prevLogs, message]); + }, []); useEffect(() => { const electronAPI: ElectronAPI = (window as any)[ELECTRON_BRIDGE_API]; @@ -40,6 +57,17 @@ const Home: React.FC = () => { }); }, []); + useEffect(() => { + const electronAPI: ElectronAPI = (window as any)[ELECTRON_BRIDGE_API]; + + electronAPI.onProgressUpdate(updateProgress); + + electronAPI.onLogMessage((message: string) => { + log.info(`Received log message: ${message}`); + addLogMessage(message); + }); + }, [updateProgress, addLogMessage]); + if (showSetup === null) { return <> Loading ....; } @@ -54,7 +82,7 @@ const Home: React.FC = () => { return (
- +
); }; diff --git a/src/renderer/screens/ProgressOverlay.tsx b/src/renderer/screens/ProgressOverlay.tsx index 5c2eaff0..180e1ad0 100644 --- a/src/renderer/screens/ProgressOverlay.tsx +++ b/src/renderer/screens/ProgressOverlay.tsx @@ -12,11 +12,6 @@ const loadingTextStyle: React.CSSProperties = { fontWeight: 'bold', }; -export interface ProgressUpdate { - status: string; - overwrite?: boolean; -} - const outerContainerStyle: React.CSSProperties = { width: '100%', height: '100vh', @@ -49,44 +44,12 @@ const logContainerStyle: React.CSSProperties = { boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)', }; -function ProgressOverlay(): React.ReactElement { - const [status, setStatus] = useState('Starting...'); - const [logs, setLogs] = useState([]); - - const updateProgress = useCallback(({ status: newStatus }: ProgressUpdate) => { - log.info(`Setting new status: ${newStatus}`); - setStatus(newStatus); - setLogs([]); // Clear logs when status changes - }, []); - - const addLogMessage = useCallback((message: string) => { - setLogs((prevLogs) => [...prevLogs, message]); - }, []); - - useEffect(() => { - if (ELECTRON_BRIDGE_API in window) { - const electronApi: ElectronAPI = (window as any)[ELECTRON_BRIDGE_API]; - log.info(`${ELECTRON_BRIDGE_API} found, setting up listeners`); - - electronApi.onProgressUpdate(updateProgress); - - electronApi.onLogMessage((message: string) => { - log.info(`Received log message: ${message}`); - addLogMessage(message); - }); - } else { - log.error(`${ELECTRON_BRIDGE_API} not found in window object`); - } - }, [updateProgress, addLogMessage]); - - // Send ready event to main process - useEffect(() => { - if (ELECTRON_BRIDGE_API in window) { - log.info(`Sending ready event from renderer`); - (window as any).electronAPI.sendReady(); - } - }, []); +interface ProgressOverlayProps { + status: string; + logs: string[]; +} +const ProgressOverlay: React.FC = ({ status, logs }) => { return (
@@ -99,6 +62,6 @@ function ProgressOverlay(): React.ReactElement {
); -} +}; export default ProgressOverlay;