From 1dfda56b1eb5943ef9da805cd6a29a9e2978da28 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Tue, 24 Dec 2024 03:56:58 +1100 Subject: [PATCH 1/2] Lint code --- src/services/cmCli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/cmCli.ts b/src/services/cmCli.ts index c31b5a5c..a93d2fa7 100644 --- a/src/services/cmCli.ts +++ b/src/services/cmCli.ts @@ -1,5 +1,5 @@ import log from 'electron-log/main'; -import path from 'path'; +import path from 'node:path'; import { getAppResourcesPath } from '../install/resourcePaths'; import { ProcessCallbacks, VirtualEnvironment } from '../virtualEnvironment'; import { fileSync } from 'tmp'; From bb268ea93529d6f45b15baf72e45307302a9f9df Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Tue, 24 Dec 2024 04:51:14 +1100 Subject: [PATCH 2/2] [Refactor] Simplify code --- src/main-process/comfyDesktopApp.ts | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main-process/comfyDesktopApp.ts b/src/main-process/comfyDesktopApp.ts index 75a2149d..37616a90 100644 --- a/src/main-process/comfyDesktopApp.ts +++ b/src/main-process/comfyDesktopApp.ts @@ -207,6 +207,7 @@ export class ComfyDesktopApp { this.initializeTerminal(virtualEnvironment); if (customNodeMigrationError) { + // TODO: Replace with IPC callback to handle i18n (SoC). new Notification({ title: 'Failed to migrate custom nodes', body: customNodeMigrationError, @@ -214,24 +215,23 @@ export class ComfyDesktopApp { } } + /** @returns `undefined` if successful, or an error `string` on failure. */ async migrateCustomNodes(config: DesktopConfig, virtualEnvironment: VirtualEnvironment, callbacks: ProcessCallbacks) { - const customNodeMigrationPath = config.get('migrateCustomNodesFrom'); - let customNodeMigrationError: string | null = null; - if (customNodeMigrationPath) { - log.info('Migrating custom nodes from: ', customNodeMigrationPath); - try { - const cmCli = new CmCli(virtualEnvironment); - await cmCli.restoreCustomNodes(customNodeMigrationPath, callbacks); - } catch (error) { - log.error('Error migrating custom nodes', error); - customNodeMigrationError = - error instanceof Error ? error.message : typeof error === 'string' ? error : 'Error migrating custom nodes.'; - } finally { - // Always remove the flag so the user doesnt get stuck here - config.delete('migrateCustomNodesFrom'); - } + const fromPath = config.get('migrateCustomNodesFrom'); + if (!fromPath) return; + + log.info('Migrating custom nodes from:', fromPath); + try { + const cmCli = new CmCli(virtualEnvironment); + await cmCli.restoreCustomNodes(fromPath, callbacks); + } catch (error) { + log.error('Error migrating custom nodes:', error); + // TODO: Replace with IPC callback to handle i18n (SoC). + return error?.toString?.() ?? 'Error migrating custom nodes.'; + } finally { + // Always remove the flag so the user doesnt get stuck here + config.delete('migrateCustomNodesFrom'); } - return customNodeMigrationError; } static create(appWindow: AppWindow, basePath: string): ComfyDesktopApp {