Skip to content

Commit b27f0e5

Browse files
Zander671Alexander Rosenbergabsidue
authored
Add --help and --new-window flag and fix --version flag (#6455)
* Add --new-window command line flag * Fix --version flag * Add --help command line flag * Update src/main/index.js Co-authored-by: absidue <[email protected]> --------- Co-authored-by: Alexander Rosenberg <[email protected]> Co-authored-by: absidue <[email protected]>
1 parent bf51b86 commit b27f0e5

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/main/index.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,25 @@ import { generatePoToken } from './poTokenGenerator'
2727
const brotliDecompressAsync = promisify(brotliDecompress)
2828

2929
if (process.argv.includes('--version')) {
30+
console.log(`v${packageDetails.version} Beta`) // eslint-disable-line no-console
31+
app.exit()
32+
} else if (process.argv.includes('--help') || process.argv.includes('-h')) {
33+
printHelp()
3034
app.exit()
3135
} else {
3236
runApp()
3337
}
3438

39+
function printHelp() {
40+
// eslint-disable-next-line no-console
41+
console.log(`\
42+
usage: ${process.argv0} [options...] [url]
43+
Options:
44+
--help, -h show this message, then exit
45+
--version print the current version, then exit
46+
--new-window reuse an existing instance if possible`)
47+
}
48+
3549
function runApp() {
3650
/** @type {Set<string>} */
3751
let ALLOWED_RENDERER_FILES
@@ -246,14 +260,24 @@ function runApp() {
246260
}
247261

248262
app.on('second-instance', (_, commandLine, __) => {
249-
// Someone tried to run a second instance, we should focus our window
263+
// Someone tried to run a second instance
250264
if (typeof commandLine !== 'undefined') {
251265
const url = getLinkUrl(commandLine)
252266
if (mainWindow && mainWindow.webContents) {
253-
if (mainWindow.isMinimized()) mainWindow.restore()
254-
mainWindow.focus()
267+
if (commandLine.includes('--new-window')) {
268+
// The user wants to create a new window in the existing instance
269+
if (url) startupUrl = url
270+
createWindow({
271+
showWindowNow: true,
272+
replaceMainWindow: true,
273+
})
274+
} else {
275+
// Just focus the main window (instead of starting a new instance)
276+
if (mainWindow.isMinimized()) mainWindow.restore()
277+
mainWindow.focus()
255278

256-
if (url) mainWindow.webContents.send(IpcChannels.OPEN_URL, url)
279+
if (url) mainWindow.webContents.send(IpcChannels.OPEN_URL, url)
280+
}
257281
} else {
258282
if (url) startupUrl = url
259283
createWindow()

0 commit comments

Comments
 (0)