@@ -2,9 +2,9 @@ import { join, dirname } from 'path';
22import { Readable } from 'stream' ;
33import { createGunzip } from 'zlib' ;
44import { fileURLToPath } from 'node:url' ;
5- import { createReadStream , createWriteStream , unlink } from 'fs' ;
5+ import { createReadStream , createWriteStream , existsSync , unlink } from 'fs' ;
66
7- import { app , ipcMain } from 'electron' ;
7+ import { app , ipcMain , nativeImage } from 'electron' ;
88import { BrowserWindow } from 'electron' ;
99
1010export const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
@@ -14,7 +14,44 @@ let window: any;
1414
1515process . env [ 'ELECTRON_DISABLE_SECURITY_WARNINGS' ] = 'true' ;
1616
17+ const resolveAppIconPath = ( ) => {
18+ const devIconPath = join ( process . cwd ( ) , 'public' , 'icon.png' ) ;
19+ const bundledIconPath = join ( app . getAppPath ( ) , 'dist' , 'icon.png' ) ;
20+
21+ if ( existsSync ( devIconPath ) ) {
22+ return devIconPath ;
23+ }
24+
25+ if ( existsSync ( bundledIconPath ) ) {
26+ return bundledIconPath ;
27+ }
28+
29+ return undefined ;
30+ } ;
31+
32+ const applyAppIcon = ( ) => {
33+ const iconPath = resolveAppIconPath ( ) ;
34+
35+ if ( ! iconPath ) {
36+ return undefined ;
37+ }
38+
39+ const icon = nativeImage . createFromPath ( iconPath ) ;
40+
41+ if ( icon . isEmpty ( ) ) {
42+ return undefined ;
43+ }
44+
45+ if ( process . platform === 'darwin' ) {
46+ app . dock . setIcon ( icon ) ;
47+ }
48+
49+ return icon ;
50+ } ;
51+
1752const createWindow = ( ) => {
53+ const appIcon = applyAppIcon ( ) ;
54+
1855 window = new BrowserWindow ( {
1956 width : 1300 ,
2057 height : 800 ,
@@ -32,7 +69,8 @@ const createWindow = () => {
3269 // 网页的 JavaScript 代码与 Electron 提供的 API(如 require)共享同一个上下文
3370 contextIsolation : true
3471 } ,
35- title : 'JumpServer Video Player'
72+ title : 'Video Player' ,
73+ icon : appIcon
3674 } ) ;
3775
3876 const serveUrl = process . env . VITE_DEV_SERVER_URL ;
@@ -124,7 +162,7 @@ app.whenReady().then(() => {
124162 } ) ;
125163
126164 ipcMain . handle ( 'set-title' , _event => {
127- window . setTitle ( 'JumpServer Video Player' ) ;
165+ window . setTitle ( 'Video Player' ) ;
128166 } ) ;
129167} ) ;
130168
0 commit comments