Skip to content

Commit dcd637a

Browse files
fix migration problems
1 parent f832143 commit dcd637a

File tree

4 files changed

+65
-110
lines changed

4 files changed

+65
-110
lines changed

ElectronNET.API/ElectronNET.API.csproj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
66
<PackageOutputPath>..\artifacts</PackageOutputPath>
77
<PackageId>ElectronNET.API</PackageId>
@@ -29,19 +29,18 @@ This package contains the API to access the "native" electron API.</Description>
2929

3030
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
3131
<DocumentationFile>bin\Debug\netcoreapp2.0\ElectronNET.API.xml</DocumentationFile>
32+
<Optimize>true</Optimize>
3233
</PropertyGroup>
3334

34-
<ItemGroup>
35-
<PackageReference Include="EngineIoClientDotNet" Version="1.0.7.2" />
36-
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.0.0" />
37-
<PackageReference Include="SocketIoClientDotNet" Version="1.0.7.2" />
38-
</ItemGroup>
39-
4035
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(OS)' == 'Windows_NT'">
4136
<Exec Command="$(ProjectDir)devCleanup.cmd" IgnoreExitCode="true" />
4237
</Target>
4338
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(OS)' != 'Windows_NT'">
4439
<Exec Command="$(ProjectDir)devCleanup.sh" IgnoreExitCode="true" />
4540
</Target>
41+
<ItemGroup>
42+
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.1.1" />
43+
<PackageReference Include="SocketIoClientDotNet" Version="1.0.5" />
44+
</ItemGroup>
4645

4746
</Project>

ElectronNET.Host/main.js

Lines changed: 50 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,76 @@
11
const { app } = require('electron');
2-
// yf add
3-
const { BrowserWindow, dialog, shell } = require('electron')
4-
2+
const { BrowserWindow, dialog, shell } = require('electron');
53
const fs = require('fs');
64
const path = require('path');
75
const process = require('child_process').spawn;
86
const portfinder = require('detect-port');
97
let io, browserWindows, ipc, apiProcess, loadURL;
108
let appApi, menu, dialogApi, notification, tray, webContents;
119
let globalShortcut, shellApi, screen, clipboard;
10+
let splashScreen, mainWindowId;
1211

13-
// yf add
14-
let loadingWindow;
15-
let mainWindowId;
16-
let countDownInterval;
17-
18-
// yf add
19-
const manifestJsonFile = require("./bin/electron.manifest.json");
12+
const manifestJsonFile = require('./bin/electron.manifest.json');
2013
if (manifestJsonFile.singleInstance) {
2114
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
2215
mainWindowId && BrowserWindow.fromId(mainWindowId) && BrowserWindow.fromId(mainWindowId).show();
2316
});
17+
2418
if (shouldQuit) {
2519
app.quit();
26-
return;
2720
}
2821
}
2922

3023
app.on('ready', () => {
31-
32-
// yf add
33-
startLoadingWindow();
24+
if (isSplashScreenEnabled()) {
25+
startSplashScreen();
26+
}
3427

3528
portfinder(8000, (error, port) => {
3629
startSocketApiBridge(port);
3730
});
3831
});
3932

33+
function isSplashScreenEnabled() {
34+
return Boolean(manifestJsonFile.loadingUrl);
35+
}
36+
37+
function startSplashScreen() {
38+
let loadingUrl = manifestJsonFile.loadingUrl;
39+
let icon = manifestJsonFile.icon;
40+
41+
if (loadingUrl) {
42+
splashScreen = new BrowserWindow({
43+
width: manifestJsonFile.width,
44+
height: manifestJsonFile.height,
45+
transparent: true,
46+
frame: false,
47+
show: false,
48+
icon: path.join(__dirname, icon)
49+
});
50+
51+
if (manifestJsonFile.devTools) {
52+
splashScreen.webContents.openDevTools();
53+
}
54+
55+
splashScreen.loadURL(loadingUrl);
56+
splashScreen.once('ready-to-show', () => {
57+
splashScreen.show();
58+
});
59+
60+
splashScreen.on('closed', () => {
61+
splashScreen = null;
62+
});
63+
}
64+
}
65+
4066
function startSocketApiBridge(port) {
4167
io = require('socket.io')(port);
42-
43-
// yf add
4468
startAspCoreBackend(port);
4569

4670
io.on('connection', (socket) => {
47-
48-
global.elesocket = socket;
49-
global.elesocket.setMaxListeners(0);
50-
console.log('ASP.NET Core Application connected...', 'global.elesocket', global.elesocket.id, new Date());
71+
global['electronsocket'] = socket;
72+
global['electronsocket'].setMaxListeners(0);
73+
console.log('ASP.NET Core Application connected...', 'global.electronsocket', global['electronsocket'].id, new Date());
5174

5275
appApi = require('./api/app')(socket, app);
5376
browserWindows = require('./api/browserWindows')(socket);
@@ -61,19 +84,21 @@ function startSocketApiBridge(port) {
6184
shellApi = require('./api/shell')(socket);
6285
screen = require('./api/screen')(socket);
6386
clipboard = require('./api/clipboard')(socket);
87+
88+
if (splashScreen && !splashScreen.isDestroyed()) {
89+
splashScreen.close();
90+
}
6491
});
6592
}
6693

6794
function startAspCoreBackend(electronPort) {
6895
portfinder(8000, (error, electronWebPort) => {
6996
loadURL = `http://localhost:${electronWebPort}`
7097
const parameters = [`/electronPort=${electronPort}`, `/electronWebPort=${electronWebPort}`];
98+
let binaryFile = manifestJsonFile.executable;
7199

72-
const manifestFile = require("./bin/electron.manifest.json");
73-
let binaryFile = manifestFile.executable;
74-
75-
const os = require("os");
76-
if (os.platform() === "win32") {
100+
const os = require('os');
101+
if (os.platform() === 'win32') {
77102
binaryFile = binaryFile + '.exe';
78103
}
79104

@@ -82,79 +107,11 @@ function startAspCoreBackend(electronPort) {
82107
apiProcess = process(binFilePath, parameters, options);
83108

84109
apiProcess.stdout.on('data', (data) => {
85-
var text = data.toString();
86110
console.log(`stdout: ${data.toString()}`);
87-
88-
// yf add
89-
if (text.indexOf(manifestFile.mainWindowShowed) > -1 &&
90-
loadingWindow && !loadingWindow.isDestroyed()) {
91-
loadingWindow.close();
92-
93-
mainWindowId = parseInt(text.replace(`${manifestFile.mainWindowShowed}:`, "").trim());
94-
}
95111
});
96112
});
97113
}
98114

99-
// yf add
100-
function startLoadingWindow() {
101-
let loadingUrl = manifestJsonFile.loadingUrl;
102-
let icon = manifestJsonFile.icon;
103-
if (loadingUrl) {
104-
loadingWindow = new BrowserWindow({
105-
width: manifestJsonFile.width,
106-
height: manifestJsonFile.height,
107-
transparent: true,
108-
frame: false,
109-
show: false,
110-
devTools: true,
111-
icon: path.join(__dirname, icon)
112-
})
113-
if (manifestJsonFile.devTools) {
114-
loadingWindow.webContents.openDevTools();
115-
}
116-
loadingWindow.loadURL(loadingUrl);
117-
loadingWindow.once('ready-to-show', () => {
118-
loadingWindow.show()
119-
120-
// 激活倒计时
121-
activeCountDowInterval(manifestJsonFile)
122-
})
123-
loadingWindow.on('closed', () => {
124-
loadingWindow = null
125-
126-
clearInterval(countDownInterval)
127-
})
128-
}
129-
}
130-
131-
function activeCountDowInterval(manifestJsonFile) {
132-
if (!manifestJsonFile.timeout || !manifestJsonFile.timeout.limit)
133-
return
134-
135-
let limitSecond = manifestJsonFile.timeout.limit
136-
let currentSecond = 0;
137-
countDownInterval = setInterval(() => {
138-
currentSecond++;
139-
if (currentSecond < limitSecond)
140-
return;
141-
142-
clearInterval(countDownInterval);
143-
144-
dialog.showMessageBox(loadingWindow, {
145-
type: manifestJsonFile.timeout.messageBox.type || 'error',
146-
buttons: manifestJsonFile.timeout.messageBox.buttons || ["前往安装"],
147-
title: manifestJsonFile.timeout.messageBox.title || '文件缺失提示',
148-
message: manifestJsonFile.timeout.messageBox.message || '计算机缺少组件无法启动该程序,点击前往安装组件后重试',
149-
}, (res, isChecked) => {
150-
if (manifestJsonFile.timeout.help)
151-
shell.openExternal(manifestJsonFile.timeout.help)
152-
app.quit();
153-
});
154-
155-
}, 1000)
156-
}
157-
158115
//app.on('activate', () => {
159116
// On macOS it's common to re-create a window in the app when the
160117
// dock icon is clicked and there are no other windows open.

ElectronNET.Host/package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
{
2-
"name": "ElectronNET.Host",
2+
"name": "electron.net.host",
33
"version": "1.0.0",
44
"description": "",
55
"main": "main.js",
6-
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
8-
},
9-
"keywords": [],
10-
"author": "",
6+
"author": "Gregor Biswanger",
117
"license": "ISC",
128
"dependencies": {
139
"detect-port": "^1.2.1",
14-
"electron": "^2.0.2",
10+
"electron": "^2.0.5",
1511
"socket.io": "^2.0.3"
1612
},
1713
"devDependencies": {

ElectronNET.WebApp/ElectronNET.WebApp.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk.Web">
33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
55
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
66
</PropertyGroup>
77
<ItemGroup>
@@ -15,11 +15,11 @@
1515
<Folder Include="wwwroot\assets\" />
1616
</ItemGroup>
1717
<ItemGroup>
18-
<PackageReference Include="ElectronNET.API" Version="1.0.0" />
18+
<PackageReference Include="ElectronNET.API" Version="1.0.0.2" />
1919
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
2020
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
2121
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
22-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
22+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.1" />
2323
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
2424
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
2525
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
@@ -28,6 +28,9 @@
2828
<ItemGroup>
2929
<DotNetCliToolReference Include="ElectronNET.CLI" Version="*" />
3030
</ItemGroup>
31+
<ItemGroup>
32+
<ProjectReference Include="..\ElectronNET.API\ElectronNET.API.csproj" />
33+
</ItemGroup>
3134
<ItemGroup>
3235
<None Update="Assets\electron.ico">
3336
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

0 commit comments

Comments
 (0)