chore(icon): use platform-specific tray icons (#21)

This commit is contained in:
DigHuang
2026-02-09 05:22:38 -08:00
committed by GitHub
Unverified
parent 0667a241d6
commit fa22a17d7d
4 changed files with 61 additions and 13 deletions

View File

@@ -7,22 +7,42 @@ import { join } from 'path';
let tray: Tray | null = null;
/**
* Resolve the icons directory path (works in both dev and packaged mode)
*/
function getIconsDir(): string {
if (app.isPackaged) {
return join(process.resourcesPath, 'resources', 'icons');
}
return join(__dirname, '../../resources/icons');
}
/**
* Create system tray icon and menu
*/
export function createTray(mainWindow: BrowserWindow): Tray {
// Create tray icon
const iconPath = join(__dirname, '../../resources/icons/tray-icon.png');
// Create a template image for macOS (adds @2x support automatically)
let icon = nativeImage.createFromPath(iconPath);
// If icon doesn't exist, create a simple placeholder
if (icon.isEmpty()) {
// Create a simple 16x16 icon as placeholder
icon = nativeImage.createEmpty();
// Use platform-appropriate icon for system tray
const iconsDir = getIconsDir();
let iconPath: string;
if (process.platform === 'win32') {
// Windows: use .ico for best quality in system tray
iconPath = join(iconsDir, 'icon.ico');
} else if (process.platform === 'darwin') {
// macOS: use 16x16 PNG as template image
iconPath = join(iconsDir, '16x16.png');
} else {
// Linux: use 32x32 PNG
iconPath = join(iconsDir, '32x32.png');
}
let icon = nativeImage.createFromPath(iconPath);
// Fallback to icon.png if platform-specific icon not found
if (icon.isEmpty()) {
icon = nativeImage.createFromPath(join(iconsDir, 'icon.png'));
}
// On macOS, set as template image for proper dark/light mode support
if (process.platform === 'darwin') {
icon.setTemplateImage(true);