Skip to content

Commit c03d6e8

Browse files
implement splashscreen support
1 parent 5e0ef7e commit c03d6e8

File tree

8 files changed

+1953
-21
lines changed

8 files changed

+1953
-21
lines changed

ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public static void Do(string tempPath)
2727
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api.");
2828
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api.");
2929
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api.");
30+
31+
string splashscreenFolder = Path.Combine(tempPath, "splashscreen");
32+
if (Directory.Exists(splashscreenFolder) == false)
33+
{
34+
Directory.CreateDirectory(splashscreenFolder);
35+
}
36+
EmbeddedFileHelper.DeployEmbeddedFile(splashscreenFolder, "index.html", "splashscreen.");
3037
}
3138
}
3239
}

ElectronNET.CLI/ElectronNET.CLI.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ This package contains the dotnet tooling to electronize your application.</Descr
6767
<EmbeddedResource Include="..\ElectronNET.Host\ElectronHostHook\.gitignore" Link="ElectronHost\ElectronHostHook\.gitignore" />
6868
</ItemGroup>
6969

70+
<ItemGroup>
71+
<EmbeddedResource Include="..\ElectronNET.Host\splashscreen\index.html" Link="ElectronHost\splashscreen\index.html" />
72+
</ItemGroup>
7073

7174
<ItemGroup>
7275
<EmbeddedResource Include="..\ElectronNET.Host\api\app.js" Link="ElectronHost\api\app.js" />

ElectronNET.Host/electron.manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"executable": "{{executable}}",
3+
"splashscreen": {
4+
"imageFile": ""
5+
},
6+
"singleInstance": false,
37
"build": {
48
"appId": "com.{{executable}}.app",
59
"productName": "{{executable}}",

ElectronNET.Host/main.js

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { BrowserWindow } = require('electron');
33
const path = require('path');
44
const process = require('child_process').spawn;
55
const portscanner = require('portscanner');
6+
const imageSize = require('image-size');
67
let io, server, browserWindows, ipc, apiProcess, loadURL;
78
let appApi, menu, dialogApi, notification, tray, webContents;
89
let globalShortcut, shellApi, screen, clipboard;
@@ -36,36 +37,49 @@ app.on('ready', () => {
3637
});
3738

3839
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;
4047
}
4148

4249
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+
}
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

7185
function 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

Comments
 (0)