This commit is contained in:
eric
2026-03-26 05:49:54 -05:00
parent cbe4585ff4
commit 082bcc8805
4 changed files with 224 additions and 6 deletions

View File

@@ -51,6 +51,15 @@ let pendingNav: string | null = null
let tray: Tray | null = null
let isQuitting = false
function resolveAppIconPath(): string | null {
// 构建后 app.asar 内也会包含 build/icon.ico见 package.json build.files
const devCandidate = path.resolve(__dirname, '../../build/icon.ico')
const packagedCandidate = path.join(app.getAppPath(), 'build', 'icon.ico')
const pick = (p: string): string | null => (p && fs.existsSync(p) ? p : null)
return pick(packagedCandidate) ?? pick(devCandidate)
}
function showMainWindow(): void {
if (!mainWindow || mainWindow.isDestroyed()) return
if (!mainWindow.isVisible()) mainWindow.show()
@@ -60,8 +69,8 @@ function showMainWindow(): void {
function ensureTray(): void {
if (tray) return
// 项目内未找到托盘图标资源先用空图标兜底Windows 会显示默认占位/可点击区域)
const img = nativeImage.createEmpty()
const p = resolveAppIconPath()
const img = p ? nativeImage.createFromPath(p) : nativeImage.createEmpty()
tray = new Tray(img)
tray.setToolTip('无人直播助手')
tray.on('click', () => showMainWindow())
@@ -389,6 +398,7 @@ function resolvePreload(): string {
}
async function createWindow(): Promise<void> {
const iconPath = resolveAppIconPath() ?? undefined
mainWindow = new BrowserWindow({
width: 1020,
height: 720,
@@ -398,6 +408,7 @@ async function createWindow(): Promise<void> {
backgroundColor: '#14161c',
title: '无人直播助手',
autoHideMenuBar: true,
...(iconPath ? { icon: iconPath } : {}),
webPreferences: {
preload: resolvePreload(),
contextIsolation: true,