From 482c7d9c503cee403308aa14228e94ebb817f7b2 Mon Sep 17 00:00:00 2001 From: Stephen Crowe Date: Sat, 21 Jun 2025 13:21:06 -0500 Subject: [PATCH 1/5] Hide ComfyUI instead of quitting when window is closed --- src/main-process/appWindow.ts | 38 ++++++--- src/main.ts | 9 --- tests/unit/handlers/pathHandler.test.ts | 2 +- tests/unit/main-process/appWindow.test.ts | 95 +++++++++++++++++++++++ tests/unit/setup.ts | 12 +++ 5 files changed, 134 insertions(+), 22 deletions(-) diff --git a/src/main-process/appWindow.ts b/src/main-process/appWindow.ts index a30613588..416b60ee4 100644 --- a/src/main-process/appWindow.ts +++ b/src/main-process/appWindow.ts @@ -30,7 +30,7 @@ import { useDesktopConfig } from '../store/desktopConfig'; /** * 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. + * Hides to system tray when the window is closed, keeping the application running. */ export class AppWindow { private readonly appState: IAppState = useAppState(); @@ -170,10 +170,18 @@ export class AppWindow { public show(): void { this.window.show(); + if (process.platform === 'darwin') { + app.dock.show().catch((error) => { + log.error('Error showing dock', error); + }); + } } public hide(): void { this.window.hide(); + if (process.platform === 'darwin') { + app.dock.hide(); + } } public isMinimized(): boolean { @@ -318,7 +326,18 @@ export class AppWindow { this.window.on('resize', updateBounds); this.window.on('move', updateBounds); - this.window.on('close', () => log.info('App window closed.')); + this.window.on('close', (event) => { + if (this.appState.isQuitting) { + // App is actually quitting - allow the window to close + log.info('App window closing - app is quitting'); + return; + } + + // Just hiding to tray - prevent window close + log.info('App window close requested - hiding to tray instead'); + event.preventDefault(); + this.hide(); + }); this.window.webContents.setWindowOpenHandler(({ url }) => { if (this.#shouldOpenInPopup(url)) { @@ -343,6 +362,11 @@ export class AppWindow { if (this.isMinimized()) this.restore(); this.focus(); }); + + // Handle activate event (macOS - clicking dock icon when no windows visible) + app.on('activate', () => { + this.show(); + }); } private setupIpcEvents() { @@ -418,12 +442,6 @@ export class AppWindow { label: 'Show Comfy Window', click: () => { this.show(); - // Mac Only - if (process.platform === 'darwin') { - app.dock.show().catch((error) => { - log.error('Error showing dock', error); - }); - } }, }, { @@ -436,10 +454,6 @@ export class AppWindow { label: 'Hide', click: () => { this.hide(); - // Mac Only - if (process.platform === 'darwin') { - app.dock.hide(); - } }, }, ]); diff --git a/src/main.ts b/src/main.ts index 8a2deb877..f37d62ead 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,7 +23,6 @@ initializeAppState(); const overrides = new DevOverrides(); // Register the quit handlers regardless of single instance lock and before squirrel startup events. -quitWhenAllWindowsAreClosed(); trackAppQuitEvents(); initializeSentry(); @@ -89,14 +88,6 @@ function initalizeLogging() { log.info(`Starting app v${app.getVersion()}`); } -/** Quit when all windows are closed.*/ -function quitWhenAllWindowsAreClosed() { - app.on('window-all-closed', () => { - log.info('Quitting ComfyUI because window all closed'); - app.quit(); - }); -} - /** Add telemetry for the app quit event. */ function trackAppQuitEvents() { app.on('quit', (event, exitCode) => { diff --git a/tests/unit/handlers/pathHandler.test.ts b/tests/unit/handlers/pathHandler.test.ts index c8d9029a2..a5a96f580 100644 --- a/tests/unit/handlers/pathHandler.test.ts +++ b/tests/unit/handlers/pathHandler.test.ts @@ -87,7 +87,7 @@ const mockFileSystem = ({ exists = true, writable = true, isDirectory = false, c isDirectory: () => isDirectory, } as unknown as fs.Stats); vi.mocked(fs.readdirSync).mockReturnValue( - Array.from({ length: contentLength }, () => ({ name: 'mock-file' }) as fs.Dirent) + Array.from({ length: contentLength }, () => ({ name: 'mock-file' }) as any) ); if (writable) { vi.mocked(fs.accessSync).mockReturnValue(); diff --git a/tests/unit/main-process/appWindow.test.ts b/tests/unit/main-process/appWindow.test.ts index fca917946..670fbe1ee 100644 --- a/tests/unit/main-process/appWindow.test.ts +++ b/tests/unit/main-process/appWindow.test.ts @@ -5,6 +5,14 @@ import { AppWindow } from '@/main-process/appWindow'; import { type PartialMock, electronMock } from '../setup'; +const mockAppState = { + isQuitting: false, +}; + +vi.mock('@/main-process/appState', () => ({ + useAppState: vi.fn(() => mockAppState), +})); + const additionalMocks: PartialMock = { BrowserWindow: vi.fn() as PartialMock, nativeTheme: { @@ -107,3 +115,90 @@ describe('AppWindow.isOnPage', () => { expect(appWindow.isOnPage('welcome')).toBe(true); }); }); + +describe('AppWindow tray behavior', () => { + let mockWindow: PartialMock; + let windowCloseHandler: (event: Electron.Event) => void; + + beforeEach(() => { + vi.clearAllMocks(); + mockAppState.isQuitting = false; + + mockWindow = { + show: vi.fn(), + hide: vi.fn(), + on: vi.fn((event: string, handler: any) => { + if (event === 'close') windowCloseHandler = handler; + }), + once: vi.fn(), + webContents: { getURL: vi.fn(), setWindowOpenHandler: vi.fn() }, + }; + + vi.mocked(BrowserWindow).mockImplementation(() => mockWindow as BrowserWindow); + }); + + it('should hide to tray when window closed and app not quitting', () => { + vi.stubGlobal('process', { ...process, platform: 'win32', resourcesPath: '/mock' }); + new AppWindow(); + const mockEvent = { preventDefault: vi.fn() }; + + windowCloseHandler(mockEvent as any); + + expect(mockEvent.preventDefault).toHaveBeenCalled(); + expect(mockWindow.hide).toHaveBeenCalled(); + }); + + it('should allow window close when app is quitting', () => { + vi.stubGlobal('process', { ...process, platform: 'win32', resourcesPath: '/mock' }); + mockAppState.isQuitting = true; + new AppWindow(); + const mockEvent = { preventDefault: vi.fn() }; + + windowCloseHandler(mockEvent as any); + + expect(mockEvent.preventDefault).not.toHaveBeenCalled(); + expect(mockWindow.hide).not.toHaveBeenCalled(); + }); + + describe('macOS dock behavior', () => { + beforeEach(() => { + vi.stubGlobal('process', { ...process, platform: 'darwin', resourcesPath: '/mock' }); + electronMock.app.dock = { + show: vi.fn().mockResolvedValue(undefined), + hide: vi.fn(), + bounce: vi.fn(), + cancelBounce: vi.fn(), + downloadFinished: vi.fn(), + getBadge: vi.fn(), + setBadge: vi.fn(), + getMenu: vi.fn(), + setMenu: vi.fn(), + setIcon: vi.fn(), + } as any; + }); + + it('should hide dock when hiding window on macOS', () => { + const appWindow = new AppWindow(); + + appWindow.hide(); + + expect(mockWindow.hide).toHaveBeenCalled(); + expect(electronMock.app.dock?.hide).toHaveBeenCalled(); + }); + + it('should show dock when showing window on macOS', () => { + const appWindow = new AppWindow(); + + appWindow.show(); + + expect(mockWindow.show).toHaveBeenCalled(); + expect(electronMock.app.dock?.show).toHaveBeenCalled(); + }); + + it('should register activate handler for dock clicks on macOS', () => { + new AppWindow(); + + expect(electronMock.app.on).toHaveBeenCalledWith('activate', expect.any(Function)); + }); + }); +}); diff --git a/tests/unit/setup.ts b/tests/unit/setup.ts index ecbada47d..61e3d3f63 100644 --- a/tests/unit/setup.ts +++ b/tests/unit/setup.ts @@ -45,6 +45,18 @@ export const electronMock: ElectronMock = { getVersion: vi.fn(() => '1.0.0'), on: vi.fn(), once: vi.fn(), + dock: { + show: vi.fn().mockResolvedValue(undefined), + hide: vi.fn(), + bounce: vi.fn(), + cancelBounce: vi.fn(), + downloadFinished: vi.fn(), + getBadge: vi.fn(), + setBadge: vi.fn(), + getMenu: vi.fn(), + setMenu: vi.fn(), + setIcon: vi.fn(), + } as any, }, dialog: { showErrorBox: vi.fn(), From 90af9c404e01ca72ed734e9a891b86a6811cb649 Mon Sep 17 00:00:00 2001 From: Stephen Crowe Date: Wed, 2 Jul 2025 01:11:15 -0500 Subject: [PATCH 2/5] Put close-to-background behind a new setting --- src/config/comfySettings.ts | 2 + src/main-process/appWindow.ts | 21 +++++-- src/main.ts | 24 ++++++++ tests/unit/config/comfySettings.test.ts | 1 + tests/unit/main-process/appWindow.test.ts | 68 ++++++++++++++++++----- tests/unit/setup.ts | 8 ++- 6 files changed, 103 insertions(+), 21 deletions(-) diff --git a/src/config/comfySettings.ts b/src/config/comfySettings.ts index 8dee65ccd..10df6ac1f 100644 --- a/src/config/comfySettings.ts +++ b/src/config/comfySettings.ts @@ -5,6 +5,7 @@ import path from 'node:path'; export const DEFAULT_SETTINGS: ComfySettingsData = { 'Comfy-Desktop.AutoUpdate': true, 'Comfy-Desktop.SendStatistics': true, + 'Comfy-Desktop.RunInBackgroundOnClose': false, 'Comfy.ColorPalette': 'dark', 'Comfy.UseNewMenu': 'Top', 'Comfy.Workflow.WorkflowTabsPosition': 'Topbar', @@ -18,6 +19,7 @@ export const DEFAULT_SETTINGS: ComfySettingsData = { export interface ComfySettingsData { 'Comfy-Desktop.AutoUpdate': boolean; 'Comfy-Desktop.SendStatistics': boolean; + 'Comfy-Desktop.RunInBackgroundOnClose': boolean; 'Comfy.ColorPalette': 'dark' | 'light'; 'Comfy.UseNewMenu': 'Top' | 'Bottom'; 'Comfy.Workflow.WorkflowTabsPosition': 'Topbar' | 'Sidebar'; diff --git a/src/main-process/appWindow.ts b/src/main-process/appWindow.ts index 416b60ee4..c361aa438 100644 --- a/src/main-process/appWindow.ts +++ b/src/main-process/appWindow.ts @@ -17,6 +17,7 @@ import { debounce } from 'lodash'; import path from 'node:path'; import { URL } from 'node:url'; +import { useComfySettings } from '@/config/comfySettings'; import { ElectronError } from '@/infrastructure/electronError'; import type { Page } from '@/infrastructure/interfaces'; import { type IAppState, useAppState } from '@/main-process/appState'; @@ -30,7 +31,7 @@ import { useDesktopConfig } from '../store/desktopConfig'; /** * Creates a single application window that displays the renderer and encapsulates all the logic for sending messages to the renderer. - * Hides to system tray when the window is closed, keeping the application running. + * Conditionally hides to system tray when the window is closed (based on 'Comfy-Desktop.RunInBackgroundOnClose' setting). */ export class AppWindow { private readonly appState: IAppState = useAppState(); @@ -333,10 +334,20 @@ export class AppWindow { return; } - // Just hiding to tray - prevent window close - log.info('App window close requested - hiding to tray instead'); - event.preventDefault(); - this.hide(); + // Check if run in background setting is enabled + const settings = useComfySettings(); + const runInBackground = settings.get('Comfy-Desktop.RunInBackgroundOnClose'); + + if (runInBackground) { + // Hide to tray - prevent window close + log.info('App window close requested - hiding to tray instead'); + event.preventDefault(); + this.hide(); + } else { + // Setting is disabled - allow normal close behavior (quit app) + log.info('App window closing - run in background disabled'); + // Let the window close normally, which will quit the app + } }); this.window.webContents.setWindowOpenHandler(({ url }) => { diff --git a/src/main.ts b/src/main.ts index f37d62ead..3fe196119 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import { app, session, shell } from 'electron'; import { LevelOption } from 'electron-log'; import log from 'electron-log/main'; +import { useComfySettings } from './config/comfySettings'; import { LogFile } from './constants'; import { DesktopApp } from './desktopApp'; import { removeAnsiCodesTransform, replaceFileLoggingTransform } from './infrastructure/structuredLogging'; @@ -23,6 +24,7 @@ initializeAppState(); const overrides = new DevOverrides(); // Register the quit handlers regardless of single instance lock and before squirrel startup events. +maybeQuitWhenAllWindowsAreClosed(); trackAppQuitEvents(); initializeSentry(); @@ -88,6 +90,28 @@ function initalizeLogging() { log.info(`Starting app v${app.getVersion()}`); } +/** Quit when all windows are closed, unless run in background setting is enabled.*/ +function maybeQuitWhenAllWindowsAreClosed() { + app.on('window-all-closed', () => { + try { + // Check if run in background setting is enabled + const settings = useComfySettings(); + const runInBackground = settings.get('Comfy-Desktop.RunInBackgroundOnClose'); + + if (runInBackground) { + log.info('All windows closed but keeping app running in background'); + return; // Don't quit, keep running in background + } + } catch (error) { + // Settings not loaded yet or other error - fall back to default behavior (quit) + log.warn('Could not check RunInBackgroundOnClose setting, defaulting to quit:', error); + } + + log.info('Quitting ComfyUI because all windows closed'); + app.quit(); + }); +} + /** Add telemetry for the app quit event. */ function trackAppQuitEvents() { app.on('quit', (event, exitCode) => { diff --git a/tests/unit/config/comfySettings.test.ts b/tests/unit/config/comfySettings.test.ts index 4b7c9cadb..8c84aaa06 100644 --- a/tests/unit/config/comfySettings.test.ts +++ b/tests/unit/config/comfySettings.test.ts @@ -82,6 +82,7 @@ describe('ComfySettings', () => { const mockSettings: ComfySettingsData = { 'Comfy-Desktop.AutoUpdate': false, 'Comfy-Desktop.SendStatistics': false, + 'Comfy-Desktop.RunInBackgroundOnClose': true, 'Comfy.ColorPalette': 'dark', 'Comfy.UseNewMenu': 'Top', 'Comfy.Workflow.WorkflowTabsPosition': 'Topbar', diff --git a/tests/unit/main-process/appWindow.test.ts b/tests/unit/main-process/appWindow.test.ts index 670fbe1ee..16ffae708 100644 --- a/tests/unit/main-process/appWindow.test.ts +++ b/tests/unit/main-process/appWindow.test.ts @@ -1,6 +1,7 @@ import { BrowserWindow, type Tray } from 'electron'; import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { useComfySettings } from '@/config/comfySettings'; import { AppWindow } from '@/main-process/appWindow'; import { type PartialMock, electronMock } from '../setup'; @@ -137,27 +138,64 @@ describe('AppWindow tray behavior', () => { vi.mocked(BrowserWindow).mockImplementation(() => mockWindow as BrowserWindow); }); - it('should hide to tray when window closed and app not quitting', () => { - vi.stubGlobal('process', { ...process, platform: 'win32', resourcesPath: '/mock' }); - new AppWindow(); - const mockEvent = { preventDefault: vi.fn() }; + describe('when RunInBackgroundOnClose is enabled', () => { + beforeEach(() => { + const settings = useComfySettings(); + settings.set('Comfy-Desktop.RunInBackgroundOnClose', true); + }); + + it('should hide to tray when window closed and app not quitting', () => { + vi.stubGlobal('process', { ...process, platform: 'win32', resourcesPath: '/mock' }); + new AppWindow(); + const mockEvent = { preventDefault: vi.fn() }; - windowCloseHandler(mockEvent as any); + windowCloseHandler(mockEvent as any); - expect(mockEvent.preventDefault).toHaveBeenCalled(); - expect(mockWindow.hide).toHaveBeenCalled(); + expect(mockEvent.preventDefault).toHaveBeenCalled(); + expect(mockWindow.hide).toHaveBeenCalled(); + }); + + it('should still allow window close when app is quitting', () => { + vi.stubGlobal('process', { ...process, platform: 'win32', resourcesPath: '/mock' }); + mockAppState.isQuitting = true; + new AppWindow(); + const mockEvent = { preventDefault: vi.fn() }; + + windowCloseHandler(mockEvent as any); + + expect(mockEvent.preventDefault).not.toHaveBeenCalled(); + expect(mockWindow.hide).not.toHaveBeenCalled(); + }); }); - it('should allow window close when app is quitting', () => { - vi.stubGlobal('process', { ...process, platform: 'win32', resourcesPath: '/mock' }); - mockAppState.isQuitting = true; - new AppWindow(); - const mockEvent = { preventDefault: vi.fn() }; + describe('when RunInBackgroundOnClose is disabled (default)', () => { + beforeEach(() => { + const settings = useComfySettings(); + settings.set('Comfy-Desktop.RunInBackgroundOnClose', false); + }); + + it('should allow window to close normally', () => { + vi.stubGlobal('process', { ...process, platform: 'win32', resourcesPath: '/mock' }); + new AppWindow(); + const mockEvent = { preventDefault: vi.fn() }; + + windowCloseHandler(mockEvent as any); - windowCloseHandler(mockEvent as any); + expect(mockEvent.preventDefault).not.toHaveBeenCalled(); + expect(mockWindow.hide).not.toHaveBeenCalled(); + }); + + it('should allow window close when app is quitting', () => { + vi.stubGlobal('process', { ...process, platform: 'win32', resourcesPath: '/mock' }); + mockAppState.isQuitting = true; + new AppWindow(); + const mockEvent = { preventDefault: vi.fn() }; - expect(mockEvent.preventDefault).not.toHaveBeenCalled(); - expect(mockWindow.hide).not.toHaveBeenCalled(); + windowCloseHandler(mockEvent as any); + + expect(mockEvent.preventDefault).not.toHaveBeenCalled(); + expect(mockWindow.hide).not.toHaveBeenCalled(); + }); }); describe('macOS dock behavior', () => { diff --git a/tests/unit/setup.ts b/tests/unit/setup.ts index 61e3d3f63..e4d564237 100644 --- a/tests/unit/setup.ts +++ b/tests/unit/setup.ts @@ -1,7 +1,8 @@ import type { FileTransport, MainLogger, MainTransports } from 'electron-log'; import log from 'electron-log/main'; -import { vi } from 'vitest'; +import { beforeEach, vi } from 'vitest'; +import { ComfySettings } from '@/config/comfySettings'; import type { IAppState } from '@/main-process/appState'; import type { ITelemetry } from '@/services/telemetry'; @@ -107,3 +108,8 @@ vi.mock('@/services/telemetry', async () => { promptMetricsConsent: vi.fn().mockResolvedValue(true), }; }); + +// Initialize ComfySettings for tests +beforeEach(async () => { + await ComfySettings.load('/test/path'); +}); From b09cf6f1d78d8bf15c8ee55f57ccbffddb548cfa Mon Sep 17 00:00:00 2001 From: Stephen Crowe <6042774+crowecawcaw@users.noreply.github.com> Date: Sun, 13 Jul 2025 10:56:59 -0500 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com> --- src/main-process/appWindow.ts | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main-process/appWindow.ts b/src/main-process/appWindow.ts index c361aa438..7510b6ed2 100644 --- a/src/main-process/appWindow.ts +++ b/src/main-process/appWindow.ts @@ -31,7 +31,7 @@ import { useDesktopConfig } from '../store/desktopConfig'; /** * Creates a single application window that displays the renderer and encapsulates all the logic for sending messages to the renderer. - * Conditionally hides to system tray when the window is closed (based on 'Comfy-Desktop.RunInBackgroundOnClose' setting). + * Closes the application or hides to system tray when the window is closed (based on 'Comfy-Desktop.RunInBackgroundOnClose' setting). */ export class AppWindow { private readonly appState: IAppState = useAppState(); diff --git a/src/main.ts b/src/main.ts index 3fe196119..07496b410 100644 --- a/src/main.ts +++ b/src/main.ts @@ -99,7 +99,7 @@ function maybeQuitWhenAllWindowsAreClosed() { const runInBackground = settings.get('Comfy-Desktop.RunInBackgroundOnClose'); if (runInBackground) { - log.info('All windows closed but keeping app running in background'); + log.verbose('All windows closed but keeping app running in background'); return; // Don't quit, keep running in background } } catch (error) { From cd0cae3fd190145447bc8d82d2585d2363bcd2ff Mon Sep 17 00:00:00 2001 From: Stephen Crowe <6042774+crowecawcaw@users.noreply.github.com> Date: Sun, 13 Jul 2025 10:57:43 -0500 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: filtered <176114999+webfiltered@users.noreply.github.com> --- src/config/comfySettings.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/config/comfySettings.ts b/src/config/comfySettings.ts index 10df6ac1f..8dee65ccd 100644 --- a/src/config/comfySettings.ts +++ b/src/config/comfySettings.ts @@ -5,7 +5,6 @@ import path from 'node:path'; export const DEFAULT_SETTINGS: ComfySettingsData = { 'Comfy-Desktop.AutoUpdate': true, 'Comfy-Desktop.SendStatistics': true, - 'Comfy-Desktop.RunInBackgroundOnClose': false, 'Comfy.ColorPalette': 'dark', 'Comfy.UseNewMenu': 'Top', 'Comfy.Workflow.WorkflowTabsPosition': 'Topbar', @@ -19,7 +18,6 @@ export const DEFAULT_SETTINGS: ComfySettingsData = { export interface ComfySettingsData { 'Comfy-Desktop.AutoUpdate': boolean; 'Comfy-Desktop.SendStatistics': boolean; - 'Comfy-Desktop.RunInBackgroundOnClose': boolean; 'Comfy.ColorPalette': 'dark' | 'light'; 'Comfy.UseNewMenu': 'Top' | 'Bottom'; 'Comfy.Workflow.WorkflowTabsPosition': 'Topbar' | 'Sidebar'; From 99ecd766dfb7fbb41732176a66e845b54759f96e Mon Sep 17 00:00:00 2001 From: Stephen Crowe Date: Sun, 13 Jul 2025 18:18:20 -0500 Subject: [PATCH 5/5] Clean up unit tests --- tests/unit/handlers/pathHandler.test.ts | 2 +- tests/unit/main-process/appWindow.test.ts | 8 +++++--- tests/unit/setup.ts | 20 +------------------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/tests/unit/handlers/pathHandler.test.ts b/tests/unit/handlers/pathHandler.test.ts index 3f5a5dcc6..e6c865f0e 100644 --- a/tests/unit/handlers/pathHandler.test.ts +++ b/tests/unit/handlers/pathHandler.test.ts @@ -87,7 +87,7 @@ const mockFileSystem = ({ exists = true, writable = true, isDirectory = false, c isDirectory: () => isDirectory, } as unknown as fs.Stats); vi.mocked(fs.readdirSync).mockReturnValue( - Array.from({ length: contentLength }, () => ({ name: 'mock-file' }) as any) + Array.from({ length: contentLength }, () => ({ name: 'mock-file' }) as fs.Dirent) ); if (writable) { vi.mocked(fs.accessSync).mockReturnValue(); diff --git a/tests/unit/main-process/appWindow.test.ts b/tests/unit/main-process/appWindow.test.ts index 16ffae708..c7472a61a 100644 --- a/tests/unit/main-process/appWindow.test.ts +++ b/tests/unit/main-process/appWindow.test.ts @@ -1,7 +1,7 @@ import { BrowserWindow, type Tray } from 'electron'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { useComfySettings } from '@/config/comfySettings'; +import { ComfySettings, useComfySettings } from '@/config/comfySettings'; import { AppWindow } from '@/main-process/appWindow'; import { type PartialMock, electronMock } from '../setup'; @@ -139,7 +139,8 @@ describe('AppWindow tray behavior', () => { }); describe('when RunInBackgroundOnClose is enabled', () => { - beforeEach(() => { + beforeEach(async () => { + await ComfySettings.load('/test/path'); const settings = useComfySettings(); settings.set('Comfy-Desktop.RunInBackgroundOnClose', true); }); @@ -169,7 +170,8 @@ describe('AppWindow tray behavior', () => { }); describe('when RunInBackgroundOnClose is disabled (default)', () => { - beforeEach(() => { + beforeEach(async () => { + await ComfySettings.load('/test/path'); const settings = useComfySettings(); settings.set('Comfy-Desktop.RunInBackgroundOnClose', false); }); diff --git a/tests/unit/setup.ts b/tests/unit/setup.ts index e4d564237..ecbada47d 100644 --- a/tests/unit/setup.ts +++ b/tests/unit/setup.ts @@ -1,8 +1,7 @@ import type { FileTransport, MainLogger, MainTransports } from 'electron-log'; import log from 'electron-log/main'; -import { beforeEach, vi } from 'vitest'; +import { vi } from 'vitest'; -import { ComfySettings } from '@/config/comfySettings'; import type { IAppState } from '@/main-process/appState'; import type { ITelemetry } from '@/services/telemetry'; @@ -46,18 +45,6 @@ export const electronMock: ElectronMock = { getVersion: vi.fn(() => '1.0.0'), on: vi.fn(), once: vi.fn(), - dock: { - show: vi.fn().mockResolvedValue(undefined), - hide: vi.fn(), - bounce: vi.fn(), - cancelBounce: vi.fn(), - downloadFinished: vi.fn(), - getBadge: vi.fn(), - setBadge: vi.fn(), - getMenu: vi.fn(), - setMenu: vi.fn(), - setIcon: vi.fn(), - } as any, }, dialog: { showErrorBox: vi.fn(), @@ -108,8 +95,3 @@ vi.mock('@/services/telemetry', async () => { promptMetricsConsent: vi.fn().mockResolvedValue(true), }; }); - -// Initialize ComfySettings for tests -beforeEach(async () => { - await ComfySettings.load('/test/path'); -});