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

@@ -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,