Merge pull request #198 from ElectronNET/dev/fix-firewall-triggers

Fix firewall triggers
This commit is contained in:
Robert Muehsig
2019-01-02 23:20:30 +01:00
committed by GitHub
4 changed files with 298 additions and 260 deletions

View File

@@ -31,7 +31,7 @@ namespace ElectronNET.API
if(HybridSupport.IsElectronActive)
{
builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
.UseUrls("http://0.0.0.0:" + BridgeSettings.WebPort);
.UseUrls("http://localhost:" + BridgeSettings.WebPort);
}
return builder;

View File

@@ -3,8 +3,8 @@ const { BrowserWindow, dialog, shell } = require('electron');
const fs = require('fs');
const path = require('path');
const process = require('child_process').spawn;
const portfinder = require('detect-port');
let io, browserWindows, ipc, apiProcess, loadURL;
const portscanner = require('portscanner');
let io, server, browserWindows, ipc, apiProcess, loadURL;
let appApi, menu, dialogApi, notification, tray, webContents;
let globalShortcut, shellApi, screen, clipboard;
let splashScreen, mainWindowId;
@@ -27,9 +27,12 @@ app.on('ready', () => {
startSplashScreen();
}
portfinder(8000, (error, port) => {
// hostname needs to belocalhost, otherwise Windows Firewall will be triggered.
portscanner.findAPortNotInUse(8000, 65535, 'localhost', function (error, port) {
console.log('Electron Socket IO Port: ' + port);
startSocketApiBridge(port);
});
});
function isSplashScreenEnabled() {
@@ -66,14 +69,25 @@ function startSplashScreen() {
}
function startSocketApiBridge(port) {
io = require('socket.io')(port);
startAspCoreBackend(port);
// instead of 'require('socket.io')(port);' we need to use this workaround
// otherwise the Windows Firewall will be triggered
server = require('http').createServer();
io = require('socket.io')();
io.attach(server);
server.listen(port, 'localhost');
server.on('listening', function () {
console.log('Electron Socket started on port %s at %s', server.address().port, server.address().address);
});
startAspCoreBackend(port);
io.on('connection', (socket) => {
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, app);
ipc = require('./api/ipc')(socket);
@@ -86,7 +100,7 @@ function startSocketApiBridge(port) {
shellApi = require('./api/shell')(socket);
screen = require('./api/screen')(socket);
clipboard = require('./api/clipboard')(socket);
if (splashScreen && !splashScreen.isDestroyed()) {
splashScreen.close();
}
@@ -94,8 +108,11 @@ function startSocketApiBridge(port) {
}
function startAspCoreBackend(electronPort) {
portfinder(8000, (error, electronWebPort) => {
loadURL = `http://localhost:${electronWebPort}`
// hostname needs to be localhost, otherwise Windows Firewall will be triggered.
portscanner.findAPortNotInUse(8000, 65535, 'localhost', function (error, electronWebPort) {
console.log('ASP.NET Core Port: ' + electronWebPort);
loadURL = `http://localhost:${electronWebPort}`;
const parameters = [`/electronPort=${electronPort}`, `/electronWebPort=${electronWebPort}`];
let binaryFile = manifestJsonFile.executable;

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,7 @@
"start": "tsc -p ."
},
"dependencies": {
"detect-port": "^1.2.3",
"portscanner": "^2.2.0",
"electron": "^3.0.0",
"socket.io": "^2.1.1"
},