Skip to content

Commit

Permalink
Move buildMenu to appWindow (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Nov 17, 2024
1 parent 4688aa1 commit 8d599cb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 43 deletions.
34 changes: 33 additions & 1 deletion src/main-process/appWindow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserWindow, screen, app, shell, ipcMain, Tray, Menu } from 'electron';
import { BrowserWindow, screen, app, shell, ipcMain, Tray, Menu, dialog, MenuItem } from 'electron';
import path from 'node:path';
import Store from 'electron-store';
import { StoreType } from '../store';
Expand Down Expand Up @@ -46,6 +46,7 @@ export class AppWindow {
this.setupWindowEvents();
this.sendQueuedEventsOnReady();
this.setupTray();
this.buildMenu();
}

public isReady(): boolean {
Expand Down Expand Up @@ -206,4 +207,35 @@ export class AppWindow {
// If we want to make it more dynamic return tray so we can access it later
return tray;
}

buildMenu() {
const menu = Menu.getApplicationMenu();
if (menu) {
const aboutMenuItem = {
label: 'About ComfyUI',
click: () => {
dialog.showMessageBox({
title: 'About',
message: `ComfyUI v${app.getVersion()}`,
detail: 'Created by Comfy Org\nCopyright © 2024',
buttons: ['OK'],
});
},
};
const helpMenuItem = menu.items.find((item) => item.role === 'help');
if (helpMenuItem && helpMenuItem.submenu) {
helpMenuItem.submenu.append(new MenuItem(aboutMenuItem));
Menu.setApplicationMenu(menu);
} else {
// If there's no Help menu, add one
menu.append(
new MenuItem({
label: 'Help',
submenu: [aboutMenuItem],
})
);
Menu.setApplicationMenu(menu);
}
}
}
}
11 changes: 1 addition & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { DownloadManager } from './models/DownloadManager';
import { findAvailablePort, getModelsDirectory, rotateLogFiles } from './utils';
import { ComfySettings } from './config/comfySettings';
import dotenv from 'dotenv';
import { buildMenu } from './menu/menu';
import { ComfyConfigManager } from './config/comfyConfigManager';
import { AppWindow } from './main-process/appWindow';
import { getAppResourcesPath, getBasePath, getPythonInstallPath } from './install/resourcePaths';
Expand Down Expand Up @@ -147,7 +146,7 @@ if (!gotTheLock) {
log.info('App ready');

try {
createWindow();
appWindow = new AppWindow();
new PathHandlers().registerHandlers();
new AppInfoHandlers().registerHandlers();

Expand Down Expand Up @@ -259,14 +258,6 @@ function restartApp({ customMessage, delay }: { customMessage?: string; delay?:
});
}

/**
* Creates the main application window.
*/
export const createWindow = (): void => {
appWindow = new AppWindow();
buildMenu();
};

const isComfyServerReady = async (host: string, port: number): Promise<boolean> => {
const url = `http://${host}:${port}/queue`;

Expand Down
32 changes: 0 additions & 32 deletions src/menu/menu.ts

This file was deleted.

0 comments on commit 8d599cb

Please sign in to comment.