WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9d03787

Browse files
committed
ElectronProcessActive: Add check for platform mismatch
1 parent 1d6ef7a commit 9d03787

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

src/ElectronNET.API/Runtime/Services/ElectronProcess/ElectronProcessActive.cs

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace ElectronNET.Runtime.Services.ElectronProcess
22
{
3-
using ElectronNET.Common;
4-
using ElectronNET.Runtime.Data;
53
using System;
64
using System.ComponentModel;
75
using System.IO;
@@ -43,6 +41,8 @@ protected override async Task StartCore()
4341

4442
if (this.isUnpackaged)
4543
{
44+
this.CheckRuntimeIdentifier();
45+
4646
var electrondir = Path.Combine(dir.FullName, ".electron");
4747

4848
ProcessRunner chmodRunner = null;
@@ -88,11 +88,65 @@ protected override async Task StartCore()
8888
workingDir = dir.FullName;
8989
}
9090

91-
9291
// We don't await this in order to let the state transition to "Starting"
9392
Task.Run(async () => await this.StartInternal(startCmd, args, workingDir).ConfigureAwait(false));
93+
}
9494

95-
return Task.CompletedTask;
95+
private void CheckRuntimeIdentifier()
96+
{
97+
var buildInfoRid = ElectronNetRuntime.BuildInfo.RuntimeIdentifier;
98+
if (string.IsNullOrEmpty(buildInfoRid))
99+
{
100+
return;
101+
}
102+
103+
var osPart = buildInfoRid.Split('-').First();
104+
105+
var mismatch = false;
106+
107+
switch (osPart)
108+
{
109+
case "win":
110+
111+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
112+
{
113+
mismatch = true;
114+
}
115+
116+
break;
117+
118+
case "linux":
119+
120+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
121+
{
122+
mismatch = true;
123+
}
124+
125+
break;
126+
127+
case "osx":
128+
129+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
130+
{
131+
mismatch = true;
132+
}
133+
134+
break;
135+
136+
case "freebsd":
137+
138+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
139+
{
140+
mismatch = true;
141+
}
142+
143+
break;
144+
}
145+
146+
if (mismatch)
147+
{
148+
throw new PlatformNotSupportedException($"This Electron.NET application was built for '{buildInfoRid}'. It cannot run on this platform.");
149+
}
96150
}
97151

98152
protected override Task StopCore()

0 commit comments

Comments
 (0)