From 354b4f09e61ab6e69587e837fa2d84ab5b4697e2 Mon Sep 17 00:00:00 2001 From: yaofeng Date: Wed, 13 Jun 2018 15:03:12 +0800 Subject: [PATCH] add loadingWindow --- ElectronNET.CLI/ElectronNET.CLI.csproj | 2 +- ElectronNET.Host/main.js | 34 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ElectronNET.CLI/ElectronNET.CLI.csproj b/ElectronNET.CLI/ElectronNET.CLI.csproj index 4b963b1..0867fb6 100644 --- a/ElectronNET.CLI/ElectronNET.CLI.csproj +++ b/ElectronNET.CLI/ElectronNET.CLI.csproj @@ -9,7 +9,7 @@ true ..\artifacts ElectronNET.CLI - 1.0.2 + 1.0.4 Gregor Biswanger, Robert Muehsig Electron.NET diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index 09f4888..92a75d4 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -1,4 +1,5 @@ const { app } = require('electron'); +const { BrowserWindow } = require('electron') const fs = require('fs'); const path = require('path'); const process = require('child_process').spawn; @@ -6,8 +7,13 @@ const portfinder = require('detect-port'); let io, browserWindows, ipc, apiProcess, loadURL; let appApi, menu, dialog, notification, tray, webContents; let globalShortcut, shell, screen, clipboard; +let loadingWindow; app.on('ready', () => { + + // yf add + startLoadingWindow(); + portfinder(8000, (error, port) => { startSocketApiBridge(port); }); @@ -59,10 +65,38 @@ function startAspCoreBackend(electronPort) { apiProcess.stdout.on('data', (data) => { var text = data.toString(); console.log(`stdout: ${data.toString()}`); + + if (data.toString().indexOf("MainWindowShowed") > -1 && loadingWindow && !loadingWindow.isDestroyed()) { + loadingWindow.close(); + } }); }); } +function startLoadingWindow() { + const manifestFile = require("./bin/electron.manifest.json"); + let loadingUrl = manifestFile.loadingUrl; + let icon = manifestFile.icon; + if (loadingUrl) { + loadingWindow = new BrowserWindow({ + width: 400, + height: 435, + transparent: true, + frame: false, + show: false, + devTools: true, + icon: path.join(__dirname, icon) + }) + loadingWindow.loadURL(loadingUrl); + loadingWindow.once('ready-to-show', () => { + loadingWindow.show() + }) + loadingWindow.on('closed', () => { + loadingWindow = null + }) + } +} + //app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open.