fix: 为主窗口设置应用图标及打包包含图标文件

This commit is contained in:
2026-07-16 08:00:13 +08:00
parent d9f9782677
commit 7c519a0014
3 changed files with 7 additions and 1 deletions
+6 -1
View File
@@ -1,5 +1,6 @@
import { BrowserWindow, screen } from 'electron'
import { BrowserWindow, screen, nativeImage } from 'electron'
import * as path from 'path'
import * as fs from 'fs'
let mainWindow: BrowserWindow | null = null
export let baseAppUrl = ''
@@ -12,6 +13,9 @@ export function createMainWindow(): BrowserWindow {
cursor.y >= d.bounds.y && cursor.y <= d.bounds.y + d.bounds.height
) || displays[0]
const iconPath = path.join(__dirname, '../../src/assets/icon.png')
const appIcon = fs.existsSync(iconPath) ? nativeImage.createFromPath(iconPath) : undefined
mainWindow = new BrowserWindow({
x: Math.round(targetDisplay.bounds.x + targetDisplay.bounds.width / 2 - 300),
y: targetDisplay.bounds.y,
@@ -21,6 +25,7 @@ export function createMainWindow(): BrowserWindow {
transparent: true,
alwaysOnTop: true,
resizable: false,
icon: appIcon,
webPreferences: {
preload: path.join(__dirname, '../preload/preload.js'),
contextIsolation: true,
+1
View File
@@ -28,6 +28,7 @@
"files": [
"dist/**/*",
"dist-electron/**/*",
"src/assets/icon.png",
"package.json"
],
"win": {
Binary file not shown.

Before

Width:  |  Height:  |  Size: 483 B

After

Width:  |  Height:  |  Size: 408 KiB