-
Notifications
You must be signed in to change notification settings - Fork 162
Hide ComfyUI instead of quitting when window is closed #1206
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
482c7d9
ddc55a6
ca17463
90af9c4
b09cf6f
cd0cae3
99ecd76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,7 +24,7 @@ initializeAppState(); | |
| const overrides = new DevOverrides(); | ||
|
|
||
| // Register the quit handlers regardless of single instance lock and before squirrel startup events. | ||
| quitWhenAllWindowsAreClosed(); | ||
| maybeQuitWhenAllWindowsAreClosed(); | ||
| trackAppQuitEvents(); | ||
| initializeSentry(); | ||
|
|
||
|
|
@@ -89,10 +90,24 @@ function initalizeLogging() { | |
| log.info(`Starting app v${app.getVersion()}`); | ||
| } | ||
|
|
||
| /** Quit when all windows are closed.*/ | ||
| function quitWhenAllWindowsAreClosed() { | ||
| /** Quit when all windows are closed, unless run in background setting is enabled.*/ | ||
| function maybeQuitWhenAllWindowsAreClosed() { | ||
| app.on('window-all-closed', () => { | ||
| log.info('Quitting ComfyUI because window all closed'); | ||
| try { | ||
| // Check if run in background setting is enabled | ||
| const settings = useComfySettings(); | ||
| const runInBackground = settings.get('Comfy-Desktop.RunInBackgroundOnClose'); | ||
|
Comment on lines
+98
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the setting is updated in frontend the state should be sent to the desktop process and kept synchronised (e.g. Dynamically calling settings every time performs a round-trip IPC call to a single-threaded browser process.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a new IPC handler with logic on both sides seems a bit over-engineered to me. Even if we read the setting every time, seems like it'd be fast enough for an infrequent even. Other code seems to be using a similar approach. If we did want to IPC in here, it might make sense to make a generic settings syncing mechanism that would transfer the whole set of settings from the frontend whenever it's updated, then the desktop app can just read the local settings copy. That's a bit out of scope of this PR though. Let me know your thoughts. If you still prefer IPC syncing, I can add it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, thanks for taking the time to respond. I've been out of action for a bit. For this one, it's more about how the app should work, and preventing weird error states/lockups by just using proper separation of concerns. Using code running in a browser process (which isn't always available) as the runtime memory storage for the parent process' state is just too circular and brittle. p.s. If you can point me at the other code, I'll add it to the issues list.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking closer at this, So to make this work correctly, I'm thinking I'll add a new IPC handler for Does this sound right to you? It would not touch AppState and would continue to use |
||
|
|
||
| if (runInBackground) { | ||
| log.info('All windows closed but keeping app running in background'); | ||
crowecawcaw marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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(); | ||
| }); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.