Run local server while inside packed version, Fixes: #310

This commit is contained in:
ziajka 2019-02-28 15:07:06 +01:00
parent 3cf7492452
commit 50b12f54d8
2 changed files with 41 additions and 20 deletions

View File

@ -17,6 +17,9 @@ files:
- local-server.js - local-server.js
- package.json - package.json
extraFiles:
- dist/exe.gns3server/**
mac: mac:
category: public.app-category.developer-tools category: public.app-category.developer-tools
# publish: github # publish: github

View File

@ -3,34 +3,23 @@ const kill = require('tree-kill');
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const { ipcMain } = require('electron') const { ipcMain } = require('electron')
const { app } = require('electron')
const isWin = /^win/.test(process.platform); const isWin = /^win/.test(process.platform);
let runningServers = {}; let runningServers = {};
exports.getLocalServerPath = async () => { exports.getLocalServerPath = async () => {
const distDirectory = path.join(__dirname, 'dist'); const lookupDirectories = [
if (!fs.existsSync(distDirectory)) { __dirname,
return; path.dirname(app.getPath('exe'))
} ];
const files = fs.readdirSync(distDirectory); for(var directory of lookupDirectories) {
const serverPath = await findLocalServerPath(directory);
let serverPath = null; if(serverPath !== undefined) {
return serverPath;
files.forEach((directory) => {
if(directory.startsWith('exe.')) {
if (isWin) {
serverPath = path.join(__dirname, 'dist', directory, 'gns3server.exe');
}
else {
serverPath = path.join(__dirname, 'dist', directory, 'gns3server');
}
} }
});
if(serverPath !== null && fs.existsSync(serverPath)) {
return serverPath;
} }
return; return;
@ -54,6 +43,35 @@ exports.stopAllLocalServers = async () => {
return await stopAll(); return await stopAll();
} }
async function findLocalServerPath(baseDirectory) {
const distDirectory = path.join(baseDirectory, 'dist');
if (!fs.existsSync(distDirectory)) {
return;
}
const files = fs.readdirSync(distDirectory);
let serverPath = null;
files.forEach((directory) => {
if(directory.startsWith('exe.')) {
if (isWin) {
serverPath = path.join(baseDirectory, 'dist', directory, 'gns3server.exe');
}
else {
serverPath = path.join(baseDirectory, 'dist', directory, 'gns3server');
}
}
});
if(serverPath !== null && fs.existsSync(serverPath)) {
return serverPath;
}
return;
}
function getServerArguments(server, overrides) { function getServerArguments(server, overrides) {
let serverArguments = []; let serverArguments = [];
if(server.host) { if(server.host) {