@@ -27,11 +27,25 @@ import { generatePoToken } from './poTokenGenerator'
27
27
const brotliDecompressAsync = promisify ( brotliDecompress )
28
28
29
29
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 ( )
30
34
app . exit ( )
31
35
} else {
32
36
runApp ( )
33
37
}
34
38
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
+
35
49
function runApp ( ) {
36
50
/** @type {Set<string> } */
37
51
let ALLOWED_RENDERER_FILES
@@ -246,14 +260,24 @@ function runApp() {
246
260
}
247
261
248
262
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
250
264
if ( typeof commandLine !== 'undefined' ) {
251
265
const url = getLinkUrl ( commandLine )
252
266
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 ( )
255
278
256
- if ( url ) mainWindow . webContents . send ( IpcChannels . OPEN_URL , url )
279
+ if ( url ) mainWindow . webContents . send ( IpcChannels . OPEN_URL , url )
280
+ }
257
281
} else {
258
282
if ( url ) startupUrl = url
259
283
createWindow ( )
0 commit comments