electron-tray-menu-builder
Generate system tray and context menu configurations with platform-specific icons, menu templates, and event handling
What this skill does
# electron-tray-menu-builder
Generate system tray and context menu configurations for Electron applications. This skill handles platform-specific icon requirements, menu template creation, and tray event handling across Windows, macOS, and Linux.
## Capabilities
- Generate Tray class implementation with proper lifecycle
- Create platform-specific icon sets (ICO, ICNS, PNG)
- Build menu templates with submenus and separators
- Handle click events (single, double, right-click)
- Implement tooltip and balloon notifications
- Support dynamic menu updates
- Handle tray icon state changes (normal, active, highlighted)
- Generate TypeScript types for menu items
## Input Schema
```json
{
"type": "object",
"properties": {
"projectPath": {
"type": "string",
"description": "Path to the Electron project root"
},
"menuStructure": {
"type": "array",
"description": "Menu item definitions",
"items": {
"type": "object",
"properties": {
"label": { "type": "string" },
"type": { "enum": ["normal", "separator", "submenu", "checkbox", "radio"] },
"accelerator": { "type": "string" },
"enabled": { "type": "boolean" },
"visible": { "type": "boolean" },
"click": { "type": "string", "description": "Handler function name" },
"submenu": { "type": "array" }
}
}
},
"iconPaths": {
"type": "object",
"properties": {
"default": { "type": "string" },
"pressed": { "type": "string" },
"highlighted": { "type": "string" }
}
},
"features": {
"type": "array",
"items": {
"enum": ["tooltip", "balloon", "click-handler", "double-click", "context-menu", "dynamic-update"]
}
},
"targetPlatforms": {
"type": "array",
"items": { "enum": ["win32", "darwin", "linux"] }
}
},
"required": ["projectPath", "menuStructure"]
}
```
## Output Schema
```json
{
"type": "object",
"properties": {
"success": { "type": "boolean" },
"files": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": { "type": "string" },
"description": { "type": "string" }
}
}
},
"iconRequirements": {
"type": "object",
"description": "Required icon files per platform"
},
"warnings": { "type": "array", "items": { "type": "string" } }
},
"required": ["success"]
}
```
## Platform Considerations
### Windows
- Icon format: ICO (16x16, 32x32, 48x48, 256x256)
- Supports balloon notifications
- Double-click shows main window (convention)
- Tray icon persists in system tray
### macOS
- Icon format: PNG (16x16, 32x32 @1x and @2x)
- Must be template images for dark/light mode
- Uses Menu Bar (not system tray)
- pressedImage for clicked state
- No balloon notifications (use Notification Center)
### Linux
- Icon format: PNG (various sizes)
- Behavior varies by desktop environment
- AppIndicator support recommended
- May require libappindicator
## Generated Code Example
```javascript
// tray-manager.js
const { app, Tray, Menu, nativeImage } = require('electron');
const path = require('path');
class TrayManager {
constructor(mainWindow) {
this.mainWindow = mainWindow;
this.tray = null;
}
create() {
const iconPath = this.getIconPath();
this.tray = new Tray(iconPath);
this.tray.setToolTip('My Application');
this.tray.setContextMenu(this.buildMenu());
// Platform-specific behavior
if (process.platform === 'win32') {
this.tray.on('double-click', () => this.showWindow());
} else if (process.platform === 'darwin') {
this.tray.on('click', () => this.toggleWindow());
}
}
getIconPath() {
const iconName = process.platform === 'win32'
? 'tray.ico'
: process.platform === 'darwin'
? 'trayTemplate.png' // Template image for macOS
: 'tray.png';
return path.join(__dirname, '../assets/icons', iconName);
}
buildMenu() {
const template = [
{
label: 'Show App',
click: () => this.showWindow()
},
{ type: 'separator' },
{
label: 'Status',
submenu: [
{ label: 'Online', type: 'radio', checked: true },
{ label: 'Away', type: 'radio' },
{ label: 'Busy', type: 'radio' }
]
},
{ type: 'separator' },
{
label: 'Quit',
accelerator: process.platform === 'darwin' ? 'Cmd+Q' : 'Ctrl+Q',
click: () => app.quit()
}
];
return Menu.buildFromTemplate(template);
}
showWindow() {
if (this.mainWindow) {
this.mainWindow.show();
this.mainWindow.focus();
}
}
toggleWindow() {
if (this.mainWindow.isVisible()) {
this.mainWindow.hide();
} else {
this.showWindow();
}
}
updateMenu(newTemplate) {
this.tray.setContextMenu(Menu.buildFromTemplate(newTemplate));
}
setIcon(iconPath) {
this.tray.setImage(iconPath);
}
destroy() {
if (this.tray) {
this.tray.destroy();
this.tray = null;
}
}
}
module.exports = TrayManager;
```
## Icon Requirements
### Template Images (macOS)
```javascript
// For macOS dark/light mode support
const icon = nativeImage.createFromPath('trayTemplate.png');
icon.setTemplateImage(true);
```
### Multi-Resolution Icons
```
assets/icons/
├── tray.ico # Windows (multi-resolution)
├── trayTemplate.png # macOS @1x (16x16 or 22x22)
├── [email protected] # macOS @2x
├── tray.png # Linux (24x24 or 22x22)
└── tray-active.png # State variant
```
## Best Practices
1. **Use template images on macOS**: Automatically adapts to dark/light mode
2. **Provide multiple resolutions**: Support high DPI displays
3. **Handle tray destruction**: Clean up on app quit
4. **Minimize tray updates**: Batch menu updates to avoid flicker
5. **Follow platform conventions**: Double-click on Windows, single-click on macOS
6. **Test on all platforms**: Behavior varies significantly
## Related Skills
- `electron-builder-config` - Include tray icons in build
- `native-notification-builder` - Notifications from tray
- `appkit-menu-bar-builder` - macOS native menu bar apps
## Related Agents
- `electron-architect` - Architecture guidance
- `platform-convention-advisor` - Platform UI conventions
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.