@@ -3,6 +3,7 @@ const { BrowserWindow } = require('electron');
33const path = require ( 'path' ) ;
44const process = require ( 'child_process' ) . spawn ;
55const portscanner = require ( 'portscanner' ) ;
6+ const imageSize = require ( 'image-size' ) ;
67let io , server , browserWindows , ipc , apiProcess , loadURL ;
78let appApi , menu , dialogApi , notification , tray , webContents ;
89let globalShortcut , shellApi , screen , clipboard ;
@@ -36,36 +37,49 @@ app.on('ready', () => {
3637} ) ;
3738
3839function isSplashScreenEnabled ( ) {
39- return Boolean ( manifestJsonFile . loadingUrl ) ;
40+ if ( manifestJsonFile . hasOwnProperty ( 'splashscreen' ) ) {
41+ if ( manifestJsonFile . splashscreen . hasOwnProperty ( 'imageFile' ) ) {
42+ return Boolean ( manifestJsonFile . splashscreen . imageFile ) ;
43+ }
44+ }
45+
46+ return false ;
4047}
4148
4249function startSplashScreen ( ) {
43- let loadingUrl = manifestJsonFile . loadingUrl ;
44- let icon = manifestJsonFile . icon ;
50+ let imageFile = path . join ( currentBinPath , manifestJsonFile . splashscreen . imageFile ) ;
51+ imageSize ( imageFile , ( error , dimensions ) => {
52+ if ( error ) {
53+ console . log ( `load splashscreen error:` ) ;
54+ console . log ( error ) ;
55+
56+ throw new Error ( error . message ) ;
57+ }
4558
46- if ( loadingUrl ) {
4759 splashScreen = new BrowserWindow ( {
48- width : manifestJsonFile . width ,
49- height : manifestJsonFile . height ,
60+ width : dimensions . width ,
61+ height : dimensions . height ,
5062 transparent : true ,
63+ center : true ,
5164 frame : false ,
52- show : false ,
53- icon : path . join ( __dirname , icon )
65+ alwaysOnTop : true ,
66+ skipTaskbar : true ,
67+ show : true
5468 } ) ;
5569
56- if ( manifestJsonFile . devTools ) {
57- splashScreen . webContents . openDevTools ( ) ;
58- }
59-
60- splashScreen . loadURL ( loadingUrl ) ;
61- splashScreen . once ( 'ready-to-show' , ( ) => {
62- splashScreen . show ( ) ;
70+ app . once ( 'browser-window-focus' , ( ) => {
71+ app . once ( 'browser-window-focus' , ( ) => {
72+ splashScreen . destroy ( ) ;
73+ } ) ;
6374 } ) ;
6475
65- splashScreen . on ( 'closed' , ( ) => {
76+ const loadSplashscreenUrl = path . join ( __dirname , 'splashscreen' , 'index.html' ) + '?imgPath=' + imageFile ;
77+ splashScreen . loadURL ( 'file://' + loadSplashscreenUrl ) ;
78+
79+ splashScreen . once ( 'closed' , ( ) => {
6680 splashScreen = null ;
6781 } ) ;
68- }
82+ } ) ;
6983}
7084
7185function startSocketApiBridge ( port ) {
@@ -101,10 +115,6 @@ function startSocketApiBridge(port) {
101115 screen = require ( './api/screen' ) ( socket ) ;
102116 clipboard = require ( './api/clipboard' ) ( socket ) ;
103117
104- if ( splashScreen && ! splashScreen . isDestroyed ( ) ) {
105- splashScreen . close ( ) ;
106- }
107-
108118 try {
109119 const hostHookScriptFilePath = path . join ( __dirname , 'ElectronHostHook' , 'index.js' ) ;
110120
0 commit comments