From adca492120b1e8d2601f3560cad5fbd8250dab55 Mon Sep 17 00:00:00 2001 From: Kendal Cormany Date: Thu, 5 Sep 2024 23:30:42 -0700 Subject: [PATCH] System Tray with basic functions, app no longer quits on close must use tray --- .github/actions/build/windows/app/action.yml | 2 +- assets/UI/Comfy_Logo_x32.png | Bin 0 -> 2904 bytes assets/UI/Comfy_Logo_x32_BW.png | Bin 0 -> 2117 bytes src/main.ts | 47 +++++++++++++++---- src/tray.ts | 38 +++++++++++++++ 5 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 assets/UI/Comfy_Logo_x32.png create mode 100644 assets/UI/Comfy_Logo_x32_BW.png create mode 100644 src/tray.ts diff --git a/.github/actions/build/windows/app/action.yml b/.github/actions/build/windows/app/action.yml index 1cbcf915..fc003a56 100644 --- a/.github/actions/build/windows/app/action.yml +++ b/.github/actions/build/windows/app/action.yml @@ -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 diff --git a/assets/UI/Comfy_Logo_x32.png b/assets/UI/Comfy_Logo_x32.png new file mode 100644 index 0000000000000000000000000000000000000000..a535a4dab3ae82f919e049a1bd4f07b6081dbb39 GIT binary patch literal 2904 zcmV-e3#asnP)sm&p5E9c#nbuODW+sYvpi9}LMf6*#xtxZSO%-sLm zSlM>h|F8Yu>w2!4Yp(g;`~IH8{oDe^jRizP^3l_rAY(#A^Nf3>>_8)Yu7UdX2Dn*5Apa)of#u)IKv??t8C9zNGk`Ea>Xh zwt$l-UwCfXRNxpK9BSj@GKxM){x4i&YSoiiIz{PQ+t+4fot0NS{t4e*`~kg;CV?4b z231o#==dzhl;c_Os`(jV9Wo@oYD0WY4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yPpb2@S2L~BDj1#)sGG&EFHD@5B+RS%mQfBrp-x}R7heDX*K7$aN&a04`)M%4mBM(cI=oanT&)^Aa&~0 zF*FDQXPY-~HUvNk=m`jRjQZ+9G5R&-pGU|`1d~$`a5>J-PW!+qHO-1 zfrj9mY?&9dH*L!A*wzxvfdla>p??qnPSI|?Y?zusO3LBi_XP9w=~G_-IXO89%X@nm z&u9Z#Qhx*p874tcfN#jUmOaI#{TrsRzoG;T9S**I`__!pMhqc;L-adYqAMVXfKd)j*3i{EhUk^ftM3wAWy_ZRTr<5%*0cz+ivwzjH2V|KS+JP^ z4jw#cLGvBP$&CJ|&6pwW+qd^kMiK-Kf&vBgm#5tjVM?fnv$L_QV?G(*I3^K(KYaMG+`oU{NQxYzsAz!RqPbJd^9>_~v55Bk z_l#H|r(VEDJ7O5fU@*c0)DV*_fEw7TJ9SP=OS8+0-T@62WSX-$1x3Dtm`eJeb${je z?gJ{f;p+5-({?z54}%5`G9wsgR$!dLg~GvP`kMU&l%Jn(laM-h?b_8)bHoiB5L3(G z)-uEwbR|pF%^nWJXjF?aFI1`T2pk~yX)^e_C3>u`E5+Z77KP060$(-QTR*oX@ zWr6oXty3m#LVd{qCx{P*L4`WVI@?BSvc^aQ8(f}2X-;{WN~d6bM( z^>V_$U?#Ib347rJhWVSUFwPa6n-BkpJbU&`&YU@81Z2Re$hlPyzEh5U@zKtClw3s= z`aW&jw!NiV;Gyb5+t)OO`B|sH { @@ -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(); }; @@ -133,22 +140,46 @@ app.on('ready', async () => { }); const killPythonServer = () => { - if (pythonProcess) { - pythonProcess.kill(); - pythonProcess = null; - } + console.log('Python server:', pythonProcess); + return new Promise(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(); } }); diff --git a/src/tray.ts b/src/tray.ts new file mode 100644 index 00000000..ac89f912 --- /dev/null +++ b/src/tray.ts @@ -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; +} \ No newline at end of file