Skip to content

Commit

Permalink
System Tray with basic functions, app no longer quits on close must u…
Browse files Browse the repository at this point in the history
…se tray
  • Loading branch information
KenCorma committed Sep 6, 2024
1 parent 211cecc commit adca492
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build/windows/app/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ runs:
DEBUG: electron-forge:*
PUBLISH: ${{ inputs.sign-and-publish }}
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
run: npm run ${{inputs.sign-and-publish == true && 'publish' || 'make'}}
run: npm run ${{inputs.sign-and-publish == true && 'publish' || 'make'}} -- --targets=@electron-forge/maker-zip
- name: Print SignLogs
if: ${{inputs.sign-and-publish == true && always()}}
continue-on-error: true
Expand Down
Binary file added assets/UI/Comfy_Logo_x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/UI/Comfy_Logo_x32_BW.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 39 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { app, BrowserWindow } from 'electron';
import path from 'path';
import net from 'net';
import { spawn, ChildProcess } from 'child_process';
import { SetupTray } from './tray';

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
import('electron-squirrel-startup').then(ess => {
Expand Down Expand Up @@ -35,6 +36,12 @@ const createWindow = () => {
// Load the UI from the Python server's URL
mainWindow.loadURL('http://localhost:8188/');

SetupTray(mainWindow);

mainWindow.on('close' , (e) => {
e.preventDefault();
mainWindow.hide();
})
// Open the DevTools.
mainWindow.webContents.openDevTools();
};
Expand Down Expand Up @@ -133,22 +140,46 @@ app.on('ready', async () => {
});

const killPythonServer = () => {
if (pythonProcess) {
pythonProcess.kill();
pythonProcess = null;
}
console.log('Python server:', pythonProcess);
return new Promise<void>(async(resolve, reject) => {
if (pythonProcess) {
try {
pythonProcess.kill();
setTimeout(() => {
resolve();
}, 5000);
while (pythonProcess.exitCode == null)
{}
resolve();
}
catch(error)
{
console.error(error);
reject(error);
}
}
else
{
resolve();
}
})
};

app.on('will-quit', () => {
killPythonServer();
});
app.on('before-quit', async () => {
await killPythonServer();
app.exit();
})

app.on('quit', () => {
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', () => {
if (process.platform !== 'darwin') {
app.quit();
//app.quit();
}
});

Expand Down
38 changes: 38 additions & 0 deletions src/tray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Tray, Menu, BrowserWindow, app } from "electron";
import path from 'path';

export function SetupTray(mainView: BrowserWindow): Tray {

const trayImage = path.join(process.resourcesPath, 'UI', 'Comfy_Logo_x32.png');
let tray = new Tray(trayImage);

tray.setTitle('ComfyUI');
tray.setToolTip('ComfyUI - Server is running');

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

tray.setContextMenu(contextMenu);

return tray;
}

0 comments on commit adca492

Please sign in to comment.