diff --git a/ElectronNET.API/ElectronNET.API.csproj b/ElectronNET.API/ElectronNET.API.csproj
index 00eac8c..0358002 100644
--- a/ElectronNET.API/ElectronNET.API.csproj
+++ b/ElectronNET.API/ElectronNET.API.csproj
@@ -1,7 +1,7 @@
- netcoreapp2.0
+ netcoreapp2.1
true
..\artifacts
ElectronNET.API
@@ -29,19 +29,18 @@ This package contains the API to access the "native" electron API.
bin\Debug\netcoreapp2.0\ElectronNET.API.xml
+ true
-
-
-
-
-
-
+
+
+
+
diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js
index 0cdedb2..6e266bc 100644
--- a/ElectronNET.Host/main.js
+++ b/ElectronNET.Host/main.js
@@ -1,7 +1,5 @@
const { app } = require('electron');
-// yf add
-const { BrowserWindow, dialog, shell } = require('electron')
-
+const { BrowserWindow, dialog, shell } = require('electron');
const fs = require('fs');
const path = require('path');
const process = require('child_process').spawn;
@@ -9,45 +7,70 @@ const portfinder = require('detect-port');
let io, browserWindows, ipc, apiProcess, loadURL;
let appApi, menu, dialogApi, notification, tray, webContents;
let globalShortcut, shellApi, screen, clipboard;
+let splashScreen, mainWindowId;
-// yf add
-let loadingWindow;
-let mainWindowId;
-let countDownInterval;
-
-// yf add
-const manifestJsonFile = require("./bin/electron.manifest.json");
+const manifestJsonFile = require('./bin/electron.manifest.json');
if (manifestJsonFile.singleInstance) {
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
mainWindowId && BrowserWindow.fromId(mainWindowId) && BrowserWindow.fromId(mainWindowId).show();
});
+
if (shouldQuit) {
app.quit();
- return;
}
}
app.on('ready', () => {
-
- // yf add
- startLoadingWindow();
+ if (isSplashScreenEnabled()) {
+ startSplashScreen();
+ }
portfinder(8000, (error, port) => {
startSocketApiBridge(port);
});
});
+function isSplashScreenEnabled() {
+ return Boolean(manifestJsonFile.loadingUrl);
+}
+
+function startSplashScreen() {
+ let loadingUrl = manifestJsonFile.loadingUrl;
+ let icon = manifestJsonFile.icon;
+
+ if (loadingUrl) {
+ splashScreen = new BrowserWindow({
+ width: manifestJsonFile.width,
+ height: manifestJsonFile.height,
+ transparent: true,
+ frame: false,
+ show: false,
+ icon: path.join(__dirname, icon)
+ });
+
+ if (manifestJsonFile.devTools) {
+ splashScreen.webContents.openDevTools();
+ }
+
+ splashScreen.loadURL(loadingUrl);
+ splashScreen.once('ready-to-show', () => {
+ splashScreen.show();
+ });
+
+ splashScreen.on('closed', () => {
+ splashScreen = null;
+ });
+ }
+}
+
function startSocketApiBridge(port) {
io = require('socket.io')(port);
-
- // yf add
startAspCoreBackend(port);
io.on('connection', (socket) => {
-
- global.elesocket = socket;
- global.elesocket.setMaxListeners(0);
- console.log('ASP.NET Core Application connected...', 'global.elesocket', global.elesocket.id, new Date());
+ global['electronsocket'] = socket;
+ global['electronsocket'].setMaxListeners(0);
+ console.log('ASP.NET Core Application connected...', 'global.electronsocket', global['electronsocket'].id, new Date());
appApi = require('./api/app')(socket, app);
browserWindows = require('./api/browserWindows')(socket);
@@ -61,6 +84,10 @@ function startSocketApiBridge(port) {
shellApi = require('./api/shell')(socket);
screen = require('./api/screen')(socket);
clipboard = require('./api/clipboard')(socket);
+
+ if (splashScreen && !splashScreen.isDestroyed()) {
+ splashScreen.close();
+ }
});
}
@@ -68,12 +95,10 @@ function startAspCoreBackend(electronPort) {
portfinder(8000, (error, electronWebPort) => {
loadURL = `http://localhost:${electronWebPort}`
const parameters = [`/electronPort=${electronPort}`, `/electronWebPort=${electronWebPort}`];
+ let binaryFile = manifestJsonFile.executable;
- const manifestFile = require("./bin/electron.manifest.json");
- let binaryFile = manifestFile.executable;
-
- const os = require("os");
- if (os.platform() === "win32") {
+ const os = require('os');
+ if (os.platform() === 'win32') {
binaryFile = binaryFile + '.exe';
}
@@ -82,79 +107,11 @@ function startAspCoreBackend(electronPort) {
apiProcess = process(binFilePath, parameters, options);
apiProcess.stdout.on('data', (data) => {
- var text = data.toString();
console.log(`stdout: ${data.toString()}`);
-
- // yf add
- if (text.indexOf(manifestFile.mainWindowShowed) > -1 &&
- loadingWindow && !loadingWindow.isDestroyed()) {
- loadingWindow.close();
-
- mainWindowId = parseInt(text.replace(`${manifestFile.mainWindowShowed}:`, "").trim());
- }
});
});
}
-// yf add
-function startLoadingWindow() {
- let loadingUrl = manifestJsonFile.loadingUrl;
- let icon = manifestJsonFile.icon;
- if (loadingUrl) {
- loadingWindow = new BrowserWindow({
- width: manifestJsonFile.width,
- height: manifestJsonFile.height,
- transparent: true,
- frame: false,
- show: false,
- devTools: true,
- icon: path.join(__dirname, icon)
- })
- if (manifestJsonFile.devTools) {
- loadingWindow.webContents.openDevTools();
- }
- loadingWindow.loadURL(loadingUrl);
- loadingWindow.once('ready-to-show', () => {
- loadingWindow.show()
-
- // 激活倒计时
- activeCountDowInterval(manifestJsonFile)
- })
- loadingWindow.on('closed', () => {
- loadingWindow = null
-
- clearInterval(countDownInterval)
- })
- }
-}
-
-function activeCountDowInterval(manifestJsonFile) {
- if (!manifestJsonFile.timeout || !manifestJsonFile.timeout.limit)
- return
-
- let limitSecond = manifestJsonFile.timeout.limit
- let currentSecond = 0;
- countDownInterval = setInterval(() => {
- currentSecond++;
- if (currentSecond < limitSecond)
- return;
-
- clearInterval(countDownInterval);
-
- dialog.showMessageBox(loadingWindow, {
- type: manifestJsonFile.timeout.messageBox.type || 'error',
- buttons: manifestJsonFile.timeout.messageBox.buttons || ["前往安装"],
- title: manifestJsonFile.timeout.messageBox.title || '文件缺失提示',
- message: manifestJsonFile.timeout.messageBox.message || '计算机缺少组件无法启动该程序,点击前往安装组件后重试',
- }, (res, isChecked) => {
- if (manifestJsonFile.timeout.help)
- shell.openExternal(manifestJsonFile.timeout.help)
- app.quit();
- });
-
- }, 1000)
-}
-
//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.
diff --git a/ElectronNET.Host/package.json b/ElectronNET.Host/package.json
index c77707e..37edf97 100644
--- a/ElectronNET.Host/package.json
+++ b/ElectronNET.Host/package.json
@@ -1,17 +1,13 @@
{
- "name": "ElectronNET.Host",
+ "name": "electron.net.host",
"version": "1.0.0",
"description": "",
"main": "main.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "keywords": [],
- "author": "",
+ "author": "Gregor Biswanger",
"license": "ISC",
"dependencies": {
"detect-port": "^1.2.1",
- "electron": "^2.0.2",
+ "electron": "^2.0.5",
"socket.io": "^2.0.3"
},
"devDependencies": {
diff --git a/ElectronNET.WebApp/ElectronNET.WebApp.csproj b/ElectronNET.WebApp/ElectronNET.WebApp.csproj
index f116621..d34e480 100644
--- a/ElectronNET.WebApp/ElectronNET.WebApp.csproj
+++ b/ElectronNET.WebApp/ElectronNET.WebApp.csproj
@@ -1,7 +1,7 @@
- netcoreapp2.0
+ netcoreapp2.1
win-x64
@@ -15,11 +15,11 @@
-
+
-
+
@@ -28,6 +28,9 @@
+
+
+
PreserveNewest