Skip to content

Commit

Permalink
show GUI when launched from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Nov 6, 2019
1 parent 8306a7b commit 41f49c5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
39 changes: 18 additions & 21 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ function compareArrays(a, b) {
}

const isShell = args._.length > 0;
const debug = (process.env.SERVEZ_ECHO && !isShell) ? logToWindow : require('debug')('main');
const debug = (process.env.SERVEZ_ECHO) ? logToWindow : require('debug')('main');
c.enabled = colorSupport.hasBasic || !isShell;
let skipSaveBecauseStartedByShell = isShell;

function createWindow() {
const {width: screenWidth, height: screenHeight} = electron.screen.getPrimaryDisplay().workAreaSize;
Expand All @@ -131,7 +132,7 @@ function createWindow() {
defaultEncoding: "utf8",
});

mainWindow.loadURL(`file://${__dirname}/src/index.html`);
mainWindow.loadURL(`file://${__dirname}/src/index.html?start=${isShell}`);
if (isDevMode) {
mainWindow.webContents.openDevTools();
}
Expand Down Expand Up @@ -187,7 +188,7 @@ function startServer() {
}));
servez.on('start', (startInfo) => {
running = true;
if (!isShell) {
if (!skipSaveBecauseStartedByShell) {
saveSettings();
}
sendToWindow('started', startInfo);
Expand All @@ -205,6 +206,8 @@ function stopServer() {
debug("running:", running);
debug("server:", servez);
if (running && servez) {
// if the stopped the server they changed settings manually I think?
skipSaveBecauseStartedByShell = false;
debug("stopServer really");
servez.close();
}
Expand Down Expand Up @@ -251,11 +254,7 @@ function launch(event, startInfo) {
}

function logToWindow(...args) {
if (isShell) {
console.log(...args);
} else {
sendToWindow('log', ...args);
}
sendToWindow('log', ...args);
}

function errorToWindow(...args) {
Expand Down Expand Up @@ -287,21 +286,19 @@ if (isShell) {
settings.index = args.index;
settings.cors = args.cors;
settings.root = args._[0];
startServer();
} else {
}

app.on('ready', () => {
startIfReady();
});
app.on('ready', () => {
startIfReady();
});

app.on('window-all-closed', () => {
mainWebContents = null;
if (running && servez) {
servez.close();
}
app.quit();
});
}
app.on('window-all-closed', () => {
mainWebContents = null;
if (running && servez) {
servez.close();
}
app.quit();
});

function setupMenus() {
const menuTemplate = [
Expand Down
19 changes: 17 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const clearElem = $("#clear");

launchElem.disabled = true;

const queryParams = Object.fromEntries(new URLSearchParams(window.location.search).entries());
let startOnLaunch = queryParams.start === 'true';

let startInfo;
const settingsInfo = {
};
Expand Down Expand Up @@ -137,6 +140,10 @@ ipcRenderer.on('settings', (event, settings) => {
const info = settingsInfo[id];
info.set(settings);
});
if (startOnLaunch) {
startOnLaunch = false;
startServer();
}
});

ipcRenderer.on('log', (event, ...args) => {
Expand Down Expand Up @@ -229,11 +236,19 @@ function updateSettings() {
}
}

function startServer() {
ipcRenderer.send('start');
}

function stopServer() {
ipcRenderer.send('stop');
}

startElem.addEventListener('click', e => {
if (launchElem.disabled) {
ipcRenderer.send('start');
startServer();
} else {
ipcRenderer.send('stop');
stopServer();
}
});

Expand Down

0 comments on commit 41f49c5

Please sign in to comment.