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

@@ -78,7 +78,7 @@ dmg:
win:
forceCodeSigning: false
verifyUpdateCodeSignature: false
signAndEditExecutable: false
signAndEditExecutable: true
extraResources:
- from: resources/bin/win32-${arch}
to: bin

View File

@@ -2,7 +2,7 @@
* Electron Main Process Entry
* Manages window creation, system tray, and IPC handlers
*/
import { app, BrowserWindow, session, shell } from 'electron';
import { app, BrowserWindow, nativeImage, session, shell } from 'electron';
import { join } from 'path';
import { GatewayManager } from '../gateway/manager';
import { registerIpcHandlers } from './ipc-handlers';
@@ -22,6 +22,33 @@ let mainWindow: BrowserWindow | null = null;
const gatewayManager = new GatewayManager();
const clawHubService = new ClawHubService();
/**
* Resolve the icons directory path (works in both dev and packaged mode)
*/
function getIconsDir(): string {
if (app.isPackaged) {
// Packaged: icons are in extraResources → process.resourcesPath/resources/icons
return join(process.resourcesPath, 'resources', 'icons');
}
// Development: relative to dist-electron/main/
return join(__dirname, '../../resources/icons');
}
/**
* Get the app icon for the current platform
*/
function getAppIcon(): Electron.NativeImage | undefined {
if (process.platform === 'darwin') return undefined; // macOS uses the app bundle icon
const iconsDir = getIconsDir();
const iconPath =
process.platform === 'win32'
? join(iconsDir, 'icon.ico')
: join(iconsDir, 'icon.png');
const icon = nativeImage.createFromPath(iconPath);
return icon.isEmpty() ? undefined : icon;
}
/**
* Create the main application window
*/
@@ -33,6 +60,7 @@ function createWindow(): BrowserWindow {
height: 800,
minWidth: 960,
minHeight: 600,
icon: getAppIcon(),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
nodeIntegration: false,

View File

@@ -7,20 +7,40 @@ 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');
// 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');
}
// Create a template image for macOS (adds @2x support automatically)
let icon = nativeImage.createFromPath(iconPath);
// If icon doesn't exist, create a simple placeholder
// Fallback to icon.png if platform-specific icon not found
if (icon.isEmpty()) {
// Create a simple 16x16 icon as placeholder
icon = nativeImage.createEmpty();
icon = nativeImage.createFromPath(join(iconsDir, 'icon.png'));
}
// On macOS, set as template image for proper dark/light mode support

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB