Skip to content

Commit

Permalink
Merge branch 'main' into enh/upload-sourcemaps-to-sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
otociulis committed Dec 1, 2024
2 parents 9ef78cd + 17f6be2 commit 99aad42
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 6 deletions.
13 changes: 12 additions & 1 deletion .github/actions/build/windows/todesktop/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
TODESKTOP_ACCESS_TOKEN:
description: 'ToDesktop Access Token'
required: true
STAGING:
description: 'Build Staging'
default: 'false'
required: false
runs:
using: composite
steps:
Expand Down Expand Up @@ -42,4 +46,11 @@ runs:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
TODESKTOP_EMAIL: ${{ inputs.TODESKTOP_EMAIL}}
TODESKTOP_ACCESS_TOKEN: ${{inputs.TODESKTOP_ACCESS_TOKEN}}
run: yarn run publish
run: |
if [ "${{ inputs.STAGING }}" = "true" ]; then
echo "🚧 Building STAGING version..."
yarn run publish:staging
else
echo "🚀 Building PRODUCTION version..."
yarn run publish
fi
3 changes: 2 additions & 1 deletion .github/workflows/publish_all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
types: [closed]

jobs:
build-stage-to-todesktop:
build-todesktop:
if: |
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true &&
Expand All @@ -21,3 +21,4 @@ jobs:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
TODESKTOP_ACCESS_TOKEN: ${{secrets.TODESKTOP_ACCESS_TOKEN}}
TODESKTOP_EMAIL: ${{secrets.TODESKTOP_EMAIL}}
STAGING: 'false'
20 changes: 20 additions & 0 deletions .github/workflows/publish_staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish Staging Application

on:
workflow_dispatch:

jobs:
build-staging-todesktop:
if: |
github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Github checkout
uses: actions/checkout@v4
- name: Build
uses: ./.github/actions/build/windows/todesktop
with:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
TODESKTOP_ACCESS_TOKEN: ${{secrets.TODESKTOP_ACCESS_TOKEN}}
TODESKTOP_EMAIL: ${{secrets.TODESKTOP_EMAIL}}
STAGING: true
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"productName": "ComfyUI",
"repository": "github:comfy-org/electron",
"copyright": "Copyright © 2024 Comfy Org",
"version": "0.3.20-test",
"version": "0.3.23-test",
"homepage": "https://comfy.org",
"description": "The best modular GUI to run AI diffusion models.",
"main": ".vite/build/main.js",
"packageManager": "[email protected]",
"config": {
"frontendVersion": "1.5.0",
"comfyVersion": "0.3.2",
"managerCommit": "ada683c6bafcb983c8366e4310b7f95f66bd6362",
"managerCommit": "1ca349523787b943f6d03201d4aed1cb0bcbbafe",
"uvVersion": "0.5.4"
},
"scripts": {
Expand All @@ -37,6 +37,7 @@
"package": "yarn run vite:compile && todesktop build --code-sign=false --async",
"prepare": "husky",
"publish": "yarn run vite:compile && todesktop build --async",
"publish:staging": "yarn run vite:compile && todesktop build --config=./todesktop.staging.json --async",
"reset-install": "node scripts/resetInstall.js",
"sign": "node debug/sign.js",
"start": "node ./scripts/launchdev.js",
Expand Down
1 change: 1 addition & 0 deletions src/config/comfyServerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class ComfyServerConfig {
private static readonly commonPaths = {
...this.getBaseModelPathsFromRepoPath(''),
custom_nodes: 'custom_nodes/',
download_model_base: 'models',
};
private static readonly configTemplates: Record<string, ModelPaths> = {
win32: {
Expand Down
13 changes: 12 additions & 1 deletion src/main-process/comfyDesktopApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { DownloadManager } from '../models/DownloadManager';
import { VirtualEnvironment } from '../virtualEnvironment';
import { InstallWizard } from '../install/installWizard';
import { Terminal } from '../terminal';

import { restoreCustomNodes } from '../services/backup';
import Store from 'electron-store';
export class ComfyDesktopApp {
public comfyServer: ComfyServer | null = null;
private terminal: Terminal | null = null; // Only created after server starts.
Expand Down Expand Up @@ -180,6 +181,16 @@ export class ComfyDesktopApp {
this.appWindow.send(IPC_CHANNELS.LOG_MESSAGE, data);
},
});
const store = new Store();
if (!store.get('Comfy-Desktop.RestoredCustomNodes', false)) {
try {
await restoreCustomNodes(virtualEnvironment, this.appWindow);
store.set('Comfy-Desktop.RestoredCustomNodes', true);
} catch (error) {
log.error('Failed to restore custom nodes:', error);
store.set('Comfy-Desktop.RestoredCustomNodes', false);
}
}

this.appWindow.sendServerStartProgress(ProgressStatus.STARTING_SERVER);
this.comfyServer = new ComfyServer(this.basePath, serverArgs, virtualEnvironment, this.appWindow);
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IPC_CHANNELS, DEFAULT_SERVER_ARGS, ProgressStatus, SENTRY_URL_ENDPOINT } from './constants';
import { IPC_CHANNELS, DEFAULT_SERVER_ARGS, ProgressStatus } from './constants';
import { app, dialog, ipcMain } from 'electron';
import log from 'electron-log/main';
import { findAvailablePort } from './utils';
Expand Down
103 changes: 103 additions & 0 deletions src/services/backup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import * as path from 'path';
import * as fs from 'fs';
import * as glob from 'glob';
import { app } from 'electron';
import { VirtualEnvironment } from '../virtualEnvironment';
import { getAppResourcesPath } from '../install/resourcePaths';
import log from 'electron-log/main';
import { AppWindow } from '../main-process/appWindow';
import { IPC_CHANNELS } from '../constants';

function parseLogFile(logPath: string): Set<string> {
console.log('Parsing log file:', logPath);
const customNodes = new Set<string>();
const content = fs.readFileSync(logPath, 'utf-8');

const lines = content.split('\n');
for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();
// Match the exact format from Python's "{:6.1f} seconds"
const timeMatch = line.match(/\s*\d+\.\d+\s+seconds/);
if (timeMatch) {
log.info(line);
// Second pattern: extract custom node name from path
const customNodeMatch = line.match(/custom_nodes[/\\]([^/\\]+)/);
if (customNodeMatch) {
log.info('Node match found:', customNodeMatch[1]);
const nodeName = customNodeMatch[1];
if (nodeName !== 'ComfyUI-Manager' && nodeName !== 'websocket_image_save.py') {
customNodes.add(nodeName);
}
}
}
}

return customNodes;
}

function getSortedLogFiles(): string[] {
try {
const logsDir = app.getPath('logs');
const logFiles = glob.sync(path.join(logsDir, 'comfyui*.log'));

// Sort files by modification time, newest first
return logFiles.sort((a, b) => {
return fs.statSync(b).mtime.getTime() - fs.statSync(a).mtime.getTime();
});
} catch (error) {
console.error('Failed to get logs directory:', error);
return [];
}
}

async function installCustomNodes(
nodes: string[],
virtualEnvironment: VirtualEnvironment,
appWindow: AppWindow
): Promise<void> {
if (nodes.length === 0) {
return;
}
const cmCliPath = path.join(getAppResourcesPath(), 'ComfyUI', 'custom_nodes', 'ComfyUI-Manager', 'cm-cli.py');
appWindow.send(IPC_CHANNELS.LOG_MESSAGE, `Reinstalling ${nodes.length} custom nodes...\n`);
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
appWindow.send(IPC_CHANNELS.LOG_MESSAGE, `Installing custom node (${i + 1}/${nodes.length}): ${node}\n`);
const cmd = [
cmCliPath,
'install',
node,
'--install-path',
path.join(virtualEnvironment.venvRootPath, 'custom_nodes'),
'--no-deps',
];
const { exitCode } = await virtualEnvironment.runPythonCommandAsync(cmd, {
onStdout: (data) => {
log.info(data.toString());
},
onStderr: (data) => {
log.error(data.toString());
},
});
if (exitCode !== 0) {
log.error(`Failed to install custom nodes: ${exitCode}`);
}
log.info(`Successfully installed custom node: ${node}`);
}
}

export async function restoreCustomNodes(virtualEnvironment: VirtualEnvironment, appWindow: AppWindow): Promise<void> {
const logFiles = getSortedLogFiles();
if (logFiles.length === 0) {
return;
}

const customNodes = new Set<string>();
for (const logFile of logFiles) {
const nodes = parseLogFile(logFile);
nodes.forEach((node) => customNodes.add(node));
}

log.info('Found custom nodes:', customNodes);
await installCustomNodes(Array.from(customNodes), virtualEnvironment, appWindow);
}
10 changes: 10 additions & 0 deletions todesktop.staging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./todesktop.json",
"id": "241130tqe9q3y",
"appId": "comfyuidesktop.staging.app",
"icon": "./assets/UI/Comfy_Logo_x128.png",
"packageJson": {
"name": "comfyui-desktop-staging",
"productName": "ComfyUI (Staging)"
}
}

0 comments on commit 99aad42

Please sign in to comment.