-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add system tray support for application #6
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
Conversation
- Import Tray and Menu from Electron for system tray functionality - Create tray icon with context menu containing Show/Hide and Quit options - Implement platform-specific icon sizing (16x16 for Windows/Linux, 22x22 for macOS) - Add single-click handler to toggle window visibility from tray - Modify window-all-closed handler to keep app running in tray instead of quitting - Add proper tray cleanup in will-quit event handler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 3 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="main.js">
<violation number="1" location="main.js:116">
P3: The tray menu label can become stale because `isVisible` changes from global shortcuts/blur without calling `updateTrayMenu()`. Consider updating the tray menu whenever the window visibility changes (e.g., in `showWindow`/`hideWindow` or in the global shortcut handler).</violation>
<violation number="2" location="main.js:355">
P2: With `window-all-closed` no longer quitting, closing the window can destroy `mainWindow` while the app keeps running. Tray/shortcut actions will then try to show a destroyed window. Add a `close` handler that hides instead of destroys, or recreate the window when it’s missing/destroyed before toggling.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Greptile OverviewGreptile SummaryThis PR adds system tray functionality, allowing the app to run in the background with a tray icon. Users can toggle window visibility via tray click or context menu, and quit via the tray menu. Key Changes:
Issues Found:
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| main.js | Added system tray with toggle functionality; tray menu update missing for global shortcut toggling |
| package.json | Added icon configuration for build targets across all platforms |
| icon/icon.png | New icon asset added for application and tray |
Sequence Diagram
sequenceDiagram
participant User
participant Tray
participant Main
participant Window
Note over Main: App starts
Main->>Main: createWindow()
Main->>Main: createTray()
Main->>Tray: new Tray(icon)
Main->>Tray: setContextMenu()
User->>Tray: Click tray icon
Tray->>Main: 'click' event
Main->>Main: toggleWindow()
alt Window hidden
Main->>Window: show()
Main->>Main: isVisible = true
else Window visible
Main->>Window: hide()
Main->>Main: isVisible = false
end
Main->>Main: updateTrayMenu()
Main->>Tray: setContextMenu(updated)
User->>Tray: Right-click menu
Tray->>User: Show menu
User->>Tray: Click "Show/Hide"
Tray->>Main: menu click handler
Main->>Main: toggleWindow()
Main->>Main: updateTrayMenu()
User->>Main: Press Ctrl+Space
Note over Main: Global shortcut
Main->>Main: toggleWindow()
Note right of Main: Bug: updateTrayMenu()<br/>not called here
User->>Tray: Click "Quit"
Tray->>Main: app.quit()
Main->>Main: 'will-quit' event
Main->>Tray: destroy()
Main->>Main: cleanTempDir()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, 4 comments
| function createTray() { | ||
| // Use the existing icon | ||
| const iconPath = path.join(__dirname, 'icon', 'icon.png'); | ||
|
|
||
| // Create tray icon - resize for system tray (16x16 on most platforms) | ||
| let trayIcon = nativeImage.createFromPath(iconPath); | ||
|
|
||
| // Resize for tray (16x16 is standard for Windows/Linux, macOS uses 22x22 but handles scaling) | ||
| if (process.platform === 'win32' || process.platform === 'linux') { | ||
| trayIcon = trayIcon.resize({ width: 16, height: 16 }); | ||
| } else if (process.platform === 'darwin') { | ||
| trayIcon = trayIcon.resize({ width: 22, height: 22 }); | ||
| trayIcon.setTemplateImage(true); // Makes it adapt to dark/light menu bar on macOS | ||
| } | ||
|
|
||
| tray = new Tray(trayIcon); | ||
| tray.setToolTip('RenderDragon Assets'); | ||
|
|
||
| // Create context menu | ||
| const contextMenu = Menu.buildFromTemplate([ | ||
| { | ||
| label: isVisible ? 'Hide' : 'Show', | ||
| click: () => { | ||
| toggleWindow(); | ||
| updateTrayMenu(); | ||
| } | ||
| }, | ||
| { type: 'separator' }, | ||
| { | ||
| label: 'Quit', | ||
| click: () => { | ||
| app.quit(); | ||
| } | ||
| } | ||
| ]); | ||
|
|
||
| tray.setContextMenu(contextMenu); | ||
|
|
||
| // Single click on tray icon toggles window (Windows/Linux) | ||
| tray.on('click', () => { | ||
| toggleWindow(); | ||
| updateTrayMenu(); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tray icon path lookup could fail if createTray() is called before app.whenReady() completes, since __dirname might not be reliable in packaged apps
Use app.getAppPath() for packaged apps:
const iconPath = path.join(app.getAppPath(), 'icon', 'icon.png');Prompt To Fix With AI
This is a comment left during a code review.
Path: main.js
Line: 95:138
Comment:
tray icon path lookup could fail if `createTray()` is called before `app.whenReady()` completes, since `__dirname` might not be reliable in packaged apps
Use `app.getAppPath()` for packaged apps:
```javascript
const iconPath = path.join(app.getAppPath(), 'icon', 'icon.png');
```
How can I resolve this? If you propose a fix, please make it concise.| "build": { | ||
| "appId": "com.renderdragon.assets", | ||
| "productName": "RenderDragon Assets", | ||
| "icon": "icon/icon.png", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macOS requires .icns format for best quality app icons; Windows requires .ico
PNG works but platform-specific formats are recommended for production apps
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: package.json
Line: 28:28
Comment:
macOS requires `.icns` format for best quality app icons; Windows requires `.ico`
PNG works but platform-specific formats are recommended for production apps
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (2)
Prompt To Fix With AIThis is a comment left during a code review.
Path: main.js
Line: 287:289
Comment:
tray menu won't update when window is toggled via global shortcut (Ctrl+Space)
```suggestion
const registered = globalShortcut.register('CommandOrControl+Space', () => {
toggleWindow();
updateTrayMenu();
});
```
How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix With AIThis is a comment left during a code review.
Path: main.js
Line: 296:298
Comment:
tray menu won't update when window is hidden via IPC handler
```suggestion
ipcMain.handle('hide-window', () => {
hideWindow();
updateTrayMenu();
});
```
How can I resolve this? If you propose a fix, please make it concise. |
… packaged apps - Add close event handler to hide window to tray instead of destroying it - Set app.isQuitting flag to properly exit app when requested - Update tray menu state when window visibility changes - Fix icon path using app.getAppPath() for packaged Electron apps
Summary by cubic
Adds a system tray so the app runs in the background with a tray icon. You can show/hide the window and quit from the tray; closing the window no longer quits the app.
Written for commit 09b3200. Summary will update on new commits.