Skip to content

Commit

Permalink
Don't install uv. (#90)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
robinjhuang authored Oct 15, 2024
1 parent 6df052d commit 63d6b4e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 62 deletions.
20 changes: 2 additions & 18 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ if (!gotTheLock) {
log.info('Open dialog');
return dialog.showOpenDialogSync({
...options,
defaultPath: app.getPath('desktop'),
defaultPath: app.getPath('documents'),
});
});
await handleFirstTimeSetup();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -846,6 +829,7 @@ async function handleFirstTimeSetup() {
);
selectedDirectory = path.join(selectedDirectory, 'ComfyUI');
}

createComfyDirectories(selectedDirectory);

const { modelConfigPath } = await determineResourcesPaths();
Expand Down
30 changes: 29 additions & 1 deletion src/renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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<boolean | null>(null);
const [status, setStatus] = useState('Starting...');
const [logs, setLogs] = useState<string[]>([]);

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];
Expand All @@ -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 ....</>;
}
Expand All @@ -54,7 +82,7 @@ const Home: React.FC = () => {

return (
<div style={bodyStyle}>
<ProgressOverlay />
<ProgressOverlay status={status} logs={logs} />
</div>
);
};
Expand Down
49 changes: 6 additions & 43 deletions src/renderer/screens/ProgressOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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<string[]>([]);

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<ProgressOverlayProps> = ({ status, logs }) => {
return (
<div style={outerContainerStyle}>
<div style={containerStyle}>
Expand All @@ -99,6 +62,6 @@ function ProgressOverlay(): React.ReactElement {
</div>
</div>
);
}
};

export default ProgressOverlay;

0 comments on commit 63d6b4e

Please sign in to comment.