Skip to content

Commit

Permalink
Register quit events before squirrel startup events. (#84)
Browse files Browse the repository at this point in the history
* Register quit events before squirrel startup events.

* Prettier.
  • Loading branch information
robinjhuang authored Oct 15, 2024
1 parent b704d1f commit 86e7e31
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 43 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5"
"trailingComma": "es5",
"endOfLine": "auto"
}
74 changes: 32 additions & 42 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,43 @@ const messageQueue: Array<any> = []; // Stores mesaages before renderer is ready

import { StoreType } from './store';
log.initialize();

// Register the quit handlers regardless of single instance lock and before squirrel startup events.
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
log.info('Window all closed');
if (process.platform !== 'darwin') {
log.info('Quitting ComfyUI because window all closed');
app.quit();
}
});

app.on('before-quit', async () => {
try {
log.info('Before-quit: Killing Python server');
await killPythonServer();
} catch (error) {
// Server did NOT exit properly
log.error('Python server did not exit properly');
log.error(error);
}
app.exit();
});

app.on('quit', () => {
log.info('Quitting ComfyUI');
app.exit();
});

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
// Run this as early in the main process as possible.
if (require('electron-squirrel-startup')) {
log.info('App already being set up by squirrel. Exiting...');
app.quit();
} else {
log.info('Normal startup');
}

const gotTheLock = app.requestSingleInstanceLock();
Expand Down Expand Up @@ -170,45 +202,6 @@ if (!gotTheLock) {
restartApp();
});
});

app.on('before-quit', () => {
if (progressInterval) {
clearInterval(progressInterval);
}
});

app.on('before-quit', () => {
if (progressInterval) {
clearInterval(progressInterval);
}
});

app.on('before-quit', async () => {
try {
await killPythonServer();
} catch (error) {
// Server did NOT exit properly
log.error('Python server did not exit properly');
log.error(error);
}
app.exit();
});

app.on('quit', () => {
log.info('Quitting ComfyUI');
app.exit();
});

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
log.info('Window all closed');
if (process.platform !== 'darwin') {
log.info('Quitting ComfyUI because window all closed');
app.quit();
}
});
}

function loadComfyIntoMainWindow() {
Expand Down Expand Up @@ -447,9 +440,6 @@ const launchPythonServer = async (
});
};

/** Interval to send progress updates to the renderer. */
let progressInterval: NodeJS.Timeout | null = null;

function sendProgressUpdate(status: string): void {
if (mainWindow) {
log.info('Sending progress update to renderer ' + status);
Expand Down

0 comments on commit 86e7e31

Please sign in to comment.