Skip to content

Commit

Permalink
Move setupTray to appWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Nov 17, 2024
1 parent 1f4f393 commit 3764495
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 60 deletions.
56 changes: 55 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 } from 'electron';
import { BrowserWindow, screen, app, shell, ipcMain, Tray, Menu } from 'electron';
import path from 'node:path';
import Store from 'electron-store';
import { StoreType } from '../store';
Expand Down Expand Up @@ -45,6 +45,7 @@ export class AppWindow {

this.setupWindowEvents();
this.sendQueuedEventsOnReady();
this.setupTray();
}

public isReady(): boolean {
Expand Down Expand Up @@ -152,4 +153,57 @@ export class AppWindow {
}
});
}

setupTray() {
// Set icon for the tray
// I think there is a way to packaged the icon in so you don't need to reference resourcesPath
const trayImage = path.join(
app.isPackaged ? process.resourcesPath : './assets',
'UI',
process.platform === 'darwin' ? 'Comfy_Logo_x16_BW.png' : 'Comfy_Logo_x32.png'
);
let tray = new Tray(trayImage);

tray.setToolTip('ComfyUI');

// For Mac you can have a separate icon when you press.
// The current design language for Mac Eco System is White or Black icon then when you click it is in color
if (process.platform === 'darwin') {
tray.setPressedImage(path.join(app.isPackaged ? process.resourcesPath : './assets', 'UI', 'Comfy_Logo_x16.png'));
}

const contextMenu = Menu.buildFromTemplate([
{
label: 'Show Comfy Window',
click: () => {
this.show();
// Mac Only
if (process.platform === 'darwin') {
app.dock.show();
}
},
},
{
label: 'Quit Comfy',
click: () => {
app.quit();
},
},
{
label: 'Hide',
click: () => {
this.hide();
// Mac Only
if (process.platform === 'darwin') {
app.dock.hide();
}
},
},
]);

tray.setContextMenu(contextMenu);

// If we want to make it more dynamic return tray so we can access it later
return tray;
}
}
2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChildProcess } from 'node:child_process';
import fs from 'fs';
import axios from 'axios';
import path from 'node:path';
import { setupTray } from './tray';
import { IPC_CHANNELS, SENTRY_URL_ENDPOINT, ProgressStatus } from './constants';
import { app, dialog, ipcMain } from 'electron';
import log from 'electron-log/main';
Expand Down Expand Up @@ -149,7 +148,6 @@ if (!gotTheLock) {

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

Expand Down
57 changes: 0 additions & 57 deletions src/tray.ts

This file was deleted.

0 comments on commit 3764495

Please sign in to comment.