Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup pre validation #647

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/install/installationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ export class InstallationManager {
*/
async ensureInstalled(): Promise<ComfyInstallation> {
const installation = ComfyInstallation.fromConfig();
log.verbose(`Install state: ${installation?.state ?? 'not installed'}`);

// Fresh install
if (!installation) return await this.freshInstall();

// Validate installation
const state = await installation.validate();
log.verbose(`Validated install state: ${state}`);
if (state !== 'installed') await this.resumeInstallation(installation);

// Resolve issues and re-run validation
Expand All @@ -52,6 +54,7 @@ export class InstallationManager {
* @param installation The installation to resume
*/
async resumeInstallation(installation: ComfyInstallation) {
log.verbose('Resuming installation.');
// TODO: Resume install at point of interruption
if (installation.state === 'started') {
await this.freshInstall();
Expand Down
14 changes: 6 additions & 8 deletions src/main-process/comfyDesktopApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ import { DesktopConfig, useDesktopConfig } from '../store/desktopConfig';
import { ansiCodes, getModelsDirectory } from '../utils';
import { ProcessCallbacks, VirtualEnvironment } from '../virtualEnvironment';
import { AppWindow } from './appWindow';
import { type ComfyInstallation } from './comfyInstallation';
import type { ComfyInstallation } from './comfyInstallation';
import { ComfyServer } from './comfyServer';

export class ComfyDesktopApp implements HasTelemetry {
public comfyServer: ComfyServer | null = null;
public comfySettings: ComfySettings;
private terminal: Terminal | null = null; // Only created after server starts.
constructor(
public readonly installation: ComfyInstallation,
public comfySettings: ComfySettings,
public installation: ComfyInstallation,
public appWindow: AppWindow,
readonly telemetry: ITelemetry
) {}
) {
this.comfySettings = new ComfySettings(installation.basePath);
}

get basePath() {
return this.installation.basePath;
Expand Down Expand Up @@ -206,10 +208,6 @@ export class ComfyDesktopApp implements HasTelemetry {
}
}

static create(appWindow: AppWindow, installation: ComfyInstallation, telemetry: ITelemetry): ComfyDesktopApp {
return new ComfyDesktopApp(installation, new ComfySettings(installation.basePath), appWindow, telemetry);
}

async uninstall(): Promise<void> {
await rm(ComfyServerConfig.configPath);
await useDesktopConfig().permanentlyDeleteConfigFile();
Expand Down
3 changes: 3 additions & 0 deletions src/main-process/comfyInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ If this problem persists, back up and delete the config file, then restart the a
* Called during app startup, this function ensures that config is in the expected state.
*/
upgradeConfig() {
log.verbose(`Upgrading config to latest format. Current state: [${this.state}]`);
// Migrate config
if (!this.issues.has('invalidBasePath')) {
useDesktopConfig().set('basePath', this.basePath);
} else {
log.warn('Skipping save of basePath.');
}
this.setState('installed');
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { findAvailablePort } from './utils';
dotenv.config();
log.initialize();
log.transports.file.level = (process.env.LOG_LEVEL as LevelOption) ?? 'info';
log.info(`Starting app v${app.getVersion()}`);

const allowDevVars = app.commandLine.hasSwitch('dev-mode');

Expand All @@ -40,6 +41,7 @@ app.on('before-quit', () => {
});

// Sentry needs to be initialized at the top level.
log.verbose('Initializing Sentry');
SentryLogging.init();

// Synchronous app start
Expand Down Expand Up @@ -99,7 +101,7 @@ async function startApp() {
throw new Error(`Fatal: Could not validate installation: [${installation.state}/${installation.issues.size}]`);

// Initialize app
const comfyDesktopApp = ComfyDesktopApp.create(appWindow, installation, telemetry);
const comfyDesktopApp = new ComfyDesktopApp(installation, appWindow, telemetry);
await comfyDesktopApp.initialize();

// At this point, user has gone through the onboarding flow.
Expand Down
2 changes: 1 addition & 1 deletion src/store/desktopSettings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { GpuType, TorchDeviceType } from '../preload';

export type DesktopSettings = {
basePath?: string | null;
basePath?: string;
/**
* The state of the installation.
* - `started`: The installation has started.
Expand Down
Loading