electron splash screen

This commit is contained in:
Jan Prochazka
2020-04-10 21:53:00 +02:00
parent 5030c673e6
commit 01e0949b28
4 changed files with 60 additions and 3 deletions

View File

@@ -11,12 +11,22 @@ const url = require('url');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
let splashWindow;
function hideSplash() {
if (splashWindow) {
splashWindow.destroy();
splashWindow = null;
}
mainWindow.show();
}
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
// width: 800,
// height: 600,
show: false,
webPreferences: {
nodeIntegration: true,
},
@@ -30,9 +40,26 @@ function createWindow() {
protocol: 'file:',
slashes: true,
});
mainWindow.webContents.on('did-finish-load', function () {
hideSplash();
});
mainWindow.loadURL(startUrl);
}
splashWindow = new BrowserWindow({
width: 300,
height: 120,
transparent: true,
frame: false,
});
splashWindow.loadURL(
url.format({
pathname: path.join(__dirname, '../packages/web/build/splash.html'),
protocol: 'file:',
slashes: true,
})
);
if (process.env.ELECTRON_START_URL) {
loadMainWindow();
} else {

View File

@@ -0,0 +1,16 @@
body {
background: #666;
}
div {
color: white;
font-size: 25pt;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
text-align: center;
font-family: Arial, Helvetica, sans-serif;
margin-top: 40px;
}

View File

@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="splash.css">
</head>
<body>
<div>Starting DbGate...</div>
</body>
</html>

View File

@@ -4,7 +4,9 @@ export default function resolveApi() {
if (electron) {
const port = electron.remote.getGlobal('port');
return `http://localhost:${port}`;
if (port) {
return `http://localhost:${port}`;
}
}
}