diff --git a/src/main/index.js b/src/main/index.js index 4b9a8c2d2e258..beb1831c80860 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -27,11 +27,25 @@ import { generatePoToken } from './poTokenGenerator' const brotliDecompressAsync = promisify(brotliDecompress) if (process.argv.includes('--version')) { + console.log(`v${packageDetails.version} Beta`) // eslint-disable-line no-console + app.exit() +} else if (process.argv.includes('--help') || process.argv.includes('-h')) { + printHelp() app.exit() } else { runApp() } +function printHelp() { + // eslint-disable-next-line no-console + console.log(`\ +usage: ${process.argv0} [options...] [url] +Options: + --help, -h show this message, then exit + --version print the current version, then exit + --new-window reuse an existing instance if possible`) +} + function runApp() { /** @type {Set} */ let ALLOWED_RENDERER_FILES @@ -246,14 +260,24 @@ function runApp() { } app.on('second-instance', (_, commandLine, __) => { - // Someone tried to run a second instance, we should focus our window + // Someone tried to run a second instance if (typeof commandLine !== 'undefined') { const url = getLinkUrl(commandLine) if (mainWindow && mainWindow.webContents) { - if (mainWindow.isMinimized()) mainWindow.restore() - mainWindow.focus() + if (commandLine.includes('--new-window')) { + // The user wants to create a new window in the existing instance + if (url) startupUrl = url + createWindow({ + showWindowNow: true, + replaceMainWindow: true, + }) + } else { + // Just focus the main window (instead of starting a new instance) + if (mainWindow.isMinimized()) mainWindow.restore() + mainWindow.focus() - if (url) mainWindow.webContents.send(IpcChannels.OPEN_URL, url) + if (url) mainWindow.webContents.send(IpcChannels.OPEN_URL, url) + } } else { if (url) startupUrl = url createWindow()