Skip to content

Commit da4e930

Browse files
New Feature: Support for set a custom static Port to ASP.NET Backend - #155
1 parent 8e9f7b0 commit da4e930

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ElectronNET.CLI:
99
ElectronNET.API:
1010

1111
* New Feature: Implement full support for Auto Updater [(Based on electron-updater - Version 4.0.6)](https://www.electron.build/auto-update)
12+
* New Feature: Support for set a custom static Port to ASP.NET Backend [\#155](https://github.com/ElectronNET/Electron.NET/issues/155)
1213
* Fixed bug: Electron tray icon TypeError ([Electron original issue](https://github.com/electron/electron/issues/7657)) (thanks [Tum4ik](https://github.com/Tum4ik))
1314
* Fixed bug: Wrong tray icon path in the application built via `electronize build` command (thanks [Tum4ik](https://github.com/Tum4ik))
1415
* Fixed bug: fix async issue where same port is considered open [\#261](https://github.com/ElectronNET/Electron.NET/issues/261) (thanks [netpoetica](https://github.com/netpoetica))

ElectronNET.Host/api/tray.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ElectronNET.Host/main.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let splashScreen, hostHook;
1212
const currentBinPath = path.join(__dirname.replace('app.asar', ''), 'bin');
1313
const manifestJsonFilePath = path.join(currentBinPath, 'electron.manifest.json');
1414
const manifestJsonFile = require(manifestJsonFilePath);
15-
if (manifestJsonFile.singleInstance) {
15+
if (manifestJsonFile.singleInstance || manifestJsonFile.aspCoreBackendPort) {
1616
const mainInstance = app.requestSingleInstanceLock();
1717
app.on('second-instance', () => {
1818
const windows = BrowserWindow.getAllWindows();
@@ -145,12 +145,19 @@ function isModuleAvailable(name) {
145145
}
146146

147147
function startAspCoreBackend(electronPort) {
148+
if(manifestJsonFile.aspCoreBackendPort) {
149+
startBackend(manifestJsonFile.aspCoreBackendPort)
150+
} else {
151+
// hostname needs to be localhost, otherwise Windows Firewall will be triggered.
152+
portscanner.findAPortNotInUse(8000, 65535, 'localhost', function (error, electronWebPort) {
153+
startBackend(electronWebPort);
154+
});
155+
}
148156

149-
// hostname needs to be localhost, otherwise Windows Firewall will be triggered.
150-
portscanner.findAPortNotInUse(8000, 65535, 'localhost', function (error, electronWebPort) {
151-
console.log('ASP.NET Core Port: ' + electronWebPort);
152-
loadURL = `http://localhost:${electronWebPort}`;
153-
const parameters = [`/electronPort=${electronPort}`, `/electronWebPort=${electronWebPort}`];
157+
function startBackend(aspCoreBackendPort) {
158+
console.log('ASP.NET Core Port: ' + aspCoreBackendPort);
159+
loadURL = `http://localhost:${aspCoreBackendPort}`;
160+
const parameters = [`/electronPort=${electronPort}`, `/electronWebPort=${aspCoreBackendPort}`];
154161
let binaryFile = manifestJsonFile.executable;
155162

156163
const os = require('os');
@@ -165,5 +172,5 @@ function startAspCoreBackend(electronPort) {
165172
apiProcess.stdout.on('data', (data) => {
166173
console.log(`stdout: ${data.toString()}`);
167174
});
168-
});
175+
}
169176
}

0 commit comments

Comments
 (0)