@@ -3,6 +3,7 @@ const { BrowserWindow } = require('electron');
3
3
const path = require ( 'path' ) ;
4
4
const process = require ( 'child_process' ) . spawn ;
5
5
const portscanner = require ( 'portscanner' ) ;
6
+ const imageSize = require ( 'image-size' ) ;
6
7
let io , server , browserWindows , ipc , apiProcess , loadURL ;
7
8
let appApi , menu , dialogApi , notification , tray , webContents ;
8
9
let globalShortcut , shellApi , screen , clipboard ;
@@ -36,36 +37,49 @@ app.on('ready', () => {
36
37
} ) ;
37
38
38
39
function 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 ;
40
47
}
41
48
42
49
function 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
+ }
45
58
46
- if ( loadingUrl ) {
47
59
splashScreen = new BrowserWindow ( {
48
- width : manifestJsonFile . width ,
49
- height : manifestJsonFile . height ,
60
+ width : dimensions . width ,
61
+ height : dimensions . height ,
50
62
transparent : true ,
63
+ center : true ,
51
64
frame : false ,
52
- show : false ,
53
- icon : path . join ( __dirname , icon )
65
+ alwaysOnTop : true ,
66
+ skipTaskbar : true ,
67
+ show : true
54
68
} ) ;
55
69
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
+ } ) ;
63
74
} ) ;
64
75
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' , ( ) => {
66
80
splashScreen = null ;
67
81
} ) ;
68
- }
82
+ } ) ;
69
83
}
70
84
71
85
function startSocketApiBridge ( port ) {
@@ -101,10 +115,6 @@ function startSocketApiBridge(port) {
101
115
screen = require ( './api/screen' ) ( socket ) ;
102
116
clipboard = require ( './api/clipboard' ) ( socket ) ;
103
117
104
- if ( splashScreen && ! splashScreen . isDestroyed ( ) ) {
105
- splashScreen . close ( ) ;
106
- }
107
-
108
118
try {
109
119
const hostHookScriptFilePath = path . join ( __dirname , 'ElectronHostHook' , 'index.js' ) ;
110
120
0 commit comments