Skip to content
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

Move opening directories actions to the tray. #66

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from 'node:path';
import { SetupTray } from './tray';
import { IPC_CHANNELS, SENTRY_URL_ENDPOINT } from './constants';
import dotenv from 'dotenv';
import { app, BrowserWindow, webContents, screen, ipcMain, Menu, shell, MenuItem } from 'electron';
import { app, BrowserWindow, webContents, screen, ipcMain, Menu, MenuItem } from 'electron';
import tar from 'tar';
import log from 'electron-log/main';
import * as Sentry from '@sentry/electron/main';
Expand Down Expand Up @@ -68,33 +68,6 @@ const messageQueue: Array<any> = []; // Stores mesaages before renderer is ready
function buildMenu(userResourcesPath: string): Menu {
const isMac = process.platform === 'darwin';

const goMenu = Menu.buildFromTemplate([
{
label: 'Models',
click: () => shell.openPath(path.join(userResourcesPath, 'models')),
},
{
label: 'Outputs',
click: () => shell.openPath(path.join(userResourcesPath, 'output')),
},
{
label: 'Inputs',
click: () => shell.openPath(path.join(userResourcesPath, 'input')),
},
{
label: 'Custom Nodes',
click: () => shell.openPath(path.join(userResourcesPath, 'custom_nodes')),
},
{
label: 'Logs',
click: () => shell.openPath(app.getPath('logs')),
},
{
label: 'Restart',
click: () => restartApp(),
},
]);

const menu = new Menu();

if (isMac) {
Expand Down Expand Up @@ -125,8 +98,6 @@ function buildMenu(userResourcesPath: string): Menu {
);
}

menu.append(new MenuItem({ label: 'Go', submenu: goMenu }));

return menu;
}

Expand Down Expand Up @@ -165,7 +136,7 @@ export const createWindow = async (userResourcesPath: string): Promise<BrowserWi

// Set up the System Tray Icon for all platforms
// Returns a tray so you can set a global var to access.
SetupTray(mainWindow);
SetupTray(mainWindow, userResourcesPath);

// Overrides the behavior of closing the window to allow for
// the python server to continue to run in the background
Expand Down
32 changes: 29 additions & 3 deletions src/tray.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Tray, Menu, BrowserWindow, app } from 'electron';
import { Tray, Menu, BrowserWindow, app, shell } from 'electron';
import path from 'path';

export function SetupTray(mainView: BrowserWindow): Tray {
export function SetupTray(mainView: BrowserWindow, userResourcesPath: string): Tray {
// 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(
Expand All @@ -11,7 +11,7 @@ export function SetupTray(mainView: BrowserWindow): Tray {
);
let tray = new Tray(trayImage);

tray.setToolTip('ComfyUI - Server is running');
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
Expand Down Expand Up @@ -46,6 +46,32 @@ export function SetupTray(mainView: BrowserWindow): Tray {
}
},
},
{ type: 'separator' },
{
label: 'Open Folder',
submenu: [
{
label: 'Models',
click: () => shell.openPath(path.join(userResourcesPath, 'models')),
},
{
label: 'Outputs',
click: () => shell.openPath(path.join(userResourcesPath, 'output')),
},
{
label: 'Inputs',
click: () => shell.openPath(path.join(userResourcesPath, 'input')),
},
{
label: 'Custom Nodes',
click: () => shell.openPath(path.join(userResourcesPath, 'custom_nodes')),
},
{
label: 'Logs',
click: () => shell.openPath(app.getPath('logs')),
},
],
},
]);

tray.setContextMenu(contextMenu);
Expand Down
Loading