|
1 | 1 | namespace ElectronNET.Runtime.Services.ElectronProcess |
2 | 2 | { |
3 | | - using ElectronNET.Common; |
4 | | - using ElectronNET.Runtime.Data; |
5 | 3 | using System; |
6 | 4 | using System.ComponentModel; |
7 | 5 | using System.IO; |
@@ -43,6 +41,8 @@ protected override async Task StartCore() |
43 | 41 |
|
44 | 42 | if (this.isUnpackaged) |
45 | 43 | { |
| 44 | + this.CheckRuntimeIdentifier(); |
| 45 | + |
46 | 46 | var electrondir = Path.Combine(dir.FullName, ".electron"); |
47 | 47 |
|
48 | 48 | ProcessRunner chmodRunner = null; |
@@ -88,11 +88,65 @@ protected override async Task StartCore() |
88 | 88 | workingDir = dir.FullName; |
89 | 89 | } |
90 | 90 |
|
91 | | - |
92 | 91 | // We don't await this in order to let the state transition to "Starting" |
93 | 92 | Task.Run(async () => await this.StartInternal(startCmd, args, workingDir).ConfigureAwait(false)); |
| 93 | + } |
94 | 94 |
|
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 | + } |
96 | 150 | } |
97 | 151 |
|
98 | 152 | protected override Task StopCore() |
|
0 commit comments