diff --git a/electron/index.cjs b/electron/index.cjs index fa0dd65..aa01c31 100644 --- a/electron/index.cjs +++ b/electron/index.cjs @@ -1,6 +1,6 @@ const path = require('path'); -const { app, BrowserWindow } = require('electron'); +const { app, BrowserWindow, Tray, Menu } = require('electron'); const isDev = require('electron-is-dev'); const { autoUpdater } = require('electron-updater'); @@ -9,9 +9,9 @@ if (require('electron-squirrel-startup')) app.quit(); function createWindow() { let iconPath = ''; if (isDev) { - iconPath = path.join(__dirname, '../public/favicon-516x516.png'); + iconPath = path.join(__dirname, '../public/icon-rounded.png'); } else { - iconPath = path.join(__dirname, '../dist/favicon-516x516.png'); + iconPath = path.join(__dirname, '../dist/icon-rounded.png'); } autoUpdater.checkForUpdatesAndNotify(); @@ -19,6 +19,14 @@ function createWindow() { show: false, icon: iconPath, }); + + createTray(win); + + win.on('minimize', (event) => { + event.preventDefault(); + win.hide(); + }); + win.maximize(); win.show(); @@ -31,8 +39,35 @@ function createWindow() { if (isDev) { win.webContents.openDevTools({ mode: 'detach' }); } + + return win; } +const createTray = (window) => { + const tray = new Tray( + path.join( + __dirname, + isDev ? '../public/icon-rounded.png' : '../dist/icon-rounded.png' + ) + ); + const contextMenu = Menu.buildFromTemplate([ + { label: 'Show', click: () => window.show() }, + { + label: 'Exit', + click: () => { + app.isQuiting = true; + app.quit(); + }, + }, + ]); + + tray.on('click', () => window.show()); + tray.setToolTip('Better ChatGPT'); + tray.setContextMenu(contextMenu); + + return tray; +}; + app.whenReady().then(createWindow); app.on('window-all-closed', () => { diff --git a/package.json b/package.json index f634976..c6a4c2c 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ }, "dmg": { "title": "${productName} ${version}", - "icon": "dist/favicon-516x516.png" + "icon": "dist/icon-rounded.png" }, "linux": { "target": [ @@ -32,11 +32,11 @@ "AppImage" ], "category": "Chat", - "icon": "dist/favicon-516x516.png" + "icon": "dist/icon-rounded.png" }, "win": { "target": "NSIS", - "icon": "dist/favicon-516x516.png" + "icon": "dist/icon-rounded.png" } }, "dependencies": { diff --git a/public/icon-rounded.png b/public/icon-rounded.png new file mode 100644 index 0000000..be659d6 Binary files /dev/null and b/public/icon-rounded.png differ