From 1a5ddad0779e16b68b62d2c84959ab1925b36985 Mon Sep 17 00:00:00 2001 From: Oto Ciulis Date: Wed, 11 Dec 2024 12:26:28 -0800 Subject: [PATCH 1/3] enh: Add Check For Updates button --- src/constants.ts | 1 + src/main-process/comfyDesktopApp.ts | 13 +++++++++++++ src/preload.ts | 3 +++ 3 files changed, 17 insertions(+) diff --git a/src/constants.ts b/src/constants.ts index 7bcfac71..590a5e4f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -4,6 +4,7 @@ export const IPC_CHANNELS = { RENDERER_READY: 'renderer-ready', RESTART_APP: 'restart-app', REINSTALL: 'reinstall', + CHECK_FOR_UPDATES: 'check-for-updates', LOG_MESSAGE: 'log-message', OPEN_DIALOG: 'open-dialog', DOWNLOAD_PROGRESS: 'download-progress', diff --git a/src/main-process/comfyDesktopApp.ts b/src/main-process/comfyDesktopApp.ts index cdc8097f..a650790e 100644 --- a/src/main-process/comfyDesktopApp.ts +++ b/src/main-process/comfyDesktopApp.ts @@ -120,6 +120,19 @@ export class ComfyDesktopApp { log.info('Reinstalling...'); this.reinstall(); }); + ipcMain.handle(IPC_CHANNELS.CHECK_FOR_UPDATES, async () => { + log.info('Checking for updates ...'); + + try { + const result = await todesktop.autoUpdater?.checkForUpdates(); + if (result?.updateInfo) { + log.info('Update found:', result.updateInfo.version); + todesktop.autoUpdater?.restartAndInstall(); + } + } catch (e) { + log.error('Update check failed:', e); + } + }); ipcMain.handle(IPC_CHANNELS.SEND_ERROR_TO_SENTRY, async (_event, { error, extras }): Promise => { try { return Sentry.captureMessage(error, { diff --git a/src/preload.ts b/src/preload.ts index 0b181631..5e391a5b 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -71,6 +71,9 @@ const electronAPI = { reinstall: () => { return ipcRenderer.invoke(IPC_CHANNELS.REINSTALL); }, + checkForUpdates: () => { + return ipcRenderer.invoke(IPC_CHANNELS.CHECK_FOR_UPDATES); + }, openDialog: (options: Electron.OpenDialogOptions) => { return ipcRenderer.invoke(IPC_CHANNELS.OPEN_DIALOG, options); }, From 57199a34aaac7247b455907777a42317f24f2ec2 Mon Sep 17 00:00:00 2001 From: Oto Ciulis Date: Wed, 11 Dec 2024 12:38:18 -0800 Subject: [PATCH 2/3] Adding OS platform check --- src/constants.ts | 1 + src/main-process/comfyDesktopApp.ts | 4 +++- src/preload.ts | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index 590a5e4f..d3a3961a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -32,6 +32,7 @@ export const IPC_CHANNELS = { SHOW_DIRECTORY_PICKER: 'show-directory-picker', INSTALL_COMFYUI: 'install-comfyui', SHOW_CONTEXT_MENU: 'show-context-menu', + GET_OS_PLATFORM: 'get-os-platform', } as const; export enum ProgressStatus { diff --git a/src/main-process/comfyDesktopApp.ts b/src/main-process/comfyDesktopApp.ts index a650790e..b25c8be3 100644 --- a/src/main-process/comfyDesktopApp.ts +++ b/src/main-process/comfyDesktopApp.ts @@ -1,7 +1,7 @@ import { app, dialog, ipcMain, type Point } from 'electron'; import log from 'electron-log/main'; import * as Sentry from '@sentry/electron/main'; -import { graphics } from 'systeminformation'; +import { graphics, osInfo } from 'systeminformation'; import todesktop from '@todesktop/runtime'; import { IPC_CHANNELS, ProgressStatus, ServerArgs } from '../constants'; import { ComfySettings } from '../config/comfySettings'; @@ -9,6 +9,7 @@ import { AppWindow } from './appWindow'; import { ComfyServer } from './comfyServer'; import { ComfyServerConfig } from '../config/comfyServerConfig'; import fs from 'fs'; +import os from 'os'; import { InstallOptions, type ElectronContextMenuOptions } from '../preload'; import path from 'path'; import { getModelsDirectory, validateHardware } from '../utils'; @@ -133,6 +134,7 @@ export class ComfyDesktopApp { log.error('Update check failed:', e); } }); + ipcMain.handle(IPC_CHANNELS.GET_OS_PLATFORM, () => Promise.resolve(os.platform())); ipcMain.handle(IPC_CHANNELS.SEND_ERROR_TO_SENTRY, async (_event, { error, extras }): Promise => { try { return Sentry.captureMessage(error, { diff --git a/src/preload.ts b/src/preload.ts index 5e391a5b..d712af43 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -74,6 +74,9 @@ const electronAPI = { checkForUpdates: () => { return ipcRenderer.invoke(IPC_CHANNELS.CHECK_FOR_UPDATES); }, + getOsPlatform: (): Promise => { + return ipcRenderer.invoke(IPC_CHANNELS.GET_OS_PLATFORM); + }, openDialog: (options: Electron.OpenDialogOptions) => { return ipcRenderer.invoke(IPC_CHANNELS.OPEN_DIALOG, options); }, From af8cef78f7bee605fe11278e52a3ccb64efcdc7c Mon Sep 17 00:00:00 2001 From: Oto Ciulis Date: Wed, 11 Dec 2024 12:45:58 -0800 Subject: [PATCH 3/3] Adding Mac tray icon functionality --- src/main-process/appWindow.ts | 29 ++++++++++++++++++++++++-- src/main-process/comfyDesktopApp.ts | 32 ++++++++++++++++------------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/main-process/appWindow.ts b/src/main-process/appWindow.ts index 5dcb9ff6..fa055556 100644 --- a/src/main-process/appWindow.ts +++ b/src/main-process/appWindow.ts @@ -1,4 +1,16 @@ -import { BrowserWindow, screen, app, shell, ipcMain, Tray, Menu, dialog, MenuItem, type Point } from 'electron'; +import { + BrowserWindow, + screen, + app, + shell, + ipcMain, + Tray, + Menu, + dialog, + MenuItem, + type Point, + ipcRenderer, +} from 'electron'; import path from 'node:path'; import Store from 'electron-store'; import { AppWindowSettings } from '../store'; @@ -7,12 +19,13 @@ import { IPC_CHANNELS, ProgressStatus, ServerArgs } from '../constants'; import { getAppResourcesPath } from '../install/resourcePaths'; import { DesktopConfig } from '../store/desktopConfig'; import type { ElectronContextMenuOptions } from '../preload'; +import { EventEmitter } from 'node:stream'; /** * Creates a single application window that displays the renderer and encapsulates all the logic for sending messages to the renderer. * Closes the application when the window is closed. */ -export class AppWindow { +export class AppWindow extends EventEmitter { private window: BrowserWindow; /** Volatile store containing window config - saves window state between launches. */ private store: Store; @@ -24,6 +37,7 @@ export class AppWindow { private editMenu?: Menu; public constructor() { + super(); const installed = DesktopConfig.store.get('installState') === 'installed'; const primaryDisplay = screen.getPrimaryDisplay(); const { width, height } = installed ? primaryDisplay.workAreaSize : { width: 1024, height: 768 }; @@ -258,6 +272,17 @@ export class AppWindow { } const contextMenu = Menu.buildFromTemplate([ + ...(process.platform === 'darwin' + ? [ + { + label: 'Check for Updates', + click: () => { + this.emit(IPC_CHANNELS.CHECK_FOR_UPDATES); + }, + }, + ] + : []), + { label: 'Show Comfy Window', click: () => { diff --git a/src/main-process/comfyDesktopApp.ts b/src/main-process/comfyDesktopApp.ts index b25c8be3..d1848c74 100644 --- a/src/main-process/comfyDesktopApp.ts +++ b/src/main-process/comfyDesktopApp.ts @@ -29,7 +29,9 @@ export class ComfyDesktopApp { public basePath: string, public comfySettings: ComfySettings, public appWindow: AppWindow - ) {} + ) { + appWindow.addListener(IPC_CHANNELS.CHECK_FOR_UPDATES, this.checkForUpdates); + } get pythonInstallPath() { return app.isPackaged ? this.basePath : path.join(app.getAppPath(), 'assets'); @@ -92,6 +94,20 @@ export class ComfyDesktopApp { } } + async checkForUpdates(): Promise { + log.info('Checking for updates ...'); + + try { + const result = await todesktop.autoUpdater?.checkForUpdates(); + if (result?.updateInfo) { + log.info('Update found:', result.updateInfo.version); + todesktop.autoUpdater?.restartAndInstall(); + } + } catch (e) { + log.error('Update check failed:', e); + } + } + registerIPCHandlers(): void { ipcMain.on(IPC_CHANNELS.SHOW_CONTEXT_MENU, (_event, options?: ElectronContextMenuOptions) => { this.appWindow.showSystemContextMenu(options); @@ -121,19 +137,7 @@ export class ComfyDesktopApp { log.info('Reinstalling...'); this.reinstall(); }); - ipcMain.handle(IPC_CHANNELS.CHECK_FOR_UPDATES, async () => { - log.info('Checking for updates ...'); - - try { - const result = await todesktop.autoUpdater?.checkForUpdates(); - if (result?.updateInfo) { - log.info('Update found:', result.updateInfo.version); - todesktop.autoUpdater?.restartAndInstall(); - } - } catch (e) { - log.error('Update check failed:', e); - } - }); + ipcMain.handle(IPC_CHANNELS.CHECK_FOR_UPDATES, () => this.checkForUpdates()); ipcMain.handle(IPC_CHANNELS.GET_OS_PLATFORM, () => Promise.resolve(os.platform())); ipcMain.handle(IPC_CHANNELS.SEND_ERROR_TO_SENTRY, async (_event, { error, extras }): Promise => { try {