diff --git a/app/src/components/mainWindow/mainWindow.js b/app/src/components/mainWindow/mainWindow.js index 6f08211..cd9a4ef 100644 --- a/app/src/components/mainWindow/mainWindow.js +++ b/app/src/components/mainWindow/mainWindow.js @@ -113,6 +113,7 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) { // Whether the window should always stay on top of other windows. Default is false. alwaysOnTop: options.alwaysOnTop, titleBarStyle: options.titleBarStyle, + show: options.tray !== 'start-in-tray', }, DEFAULT_WINDOW_OPTIONS, ), diff --git a/docs/api.md b/docs/api.md index ffd460f..66e39d6 100644 --- a/docs/api.md +++ b/docs/api.md @@ -519,11 +519,13 @@ Prevents application from being run multiple times. If such an attempt occurs th #### [tray] ``` ---tray +--tray [start-in-tray] ``` Application will stay as an icon in the system tray. Prevents application from being closed from clicking the window close button. +When the optional argument `start-in-tray` is provided, i.e. the application is started using `--tray start-in-tray`, the main window will not be shown on first start. + #### [basic-auth-username] ``` diff --git a/src/cli.js b/src/cli.js index 5d9954f..f079778 100755 --- a/src/cli.js +++ b/src/cli.js @@ -13,6 +13,17 @@ function collect(val, memo) { return memo; } +function parseMaybeBoolString(val) { + switch (val) { + case 'true': + return true; + case 'false': + return false; + default: + return val; + } +} + function parseJson(val) { if (!val) return {}; return JSON.parse(val); @@ -36,6 +47,22 @@ function checkInternet() { } if (require.main === module) { + const sanitizedArgs = []; + process.argv.forEach((arg) => { + if (sanitizedArgs.length > 0) { + const previousArg = sanitizedArgs[sanitizedArgs.length - 1]; + + // Work around commander.js not supporting default argument for options + if ( + previousArg === '--tray' && + !['true', 'false', 'start-in-tray'].includes(arg) + ) { + sanitizedArgs.push('true'); + } + } + sanitizedArgs.push(arg); + }); + program .version(packageJson.version, '-v, --version') .arguments(' [dest]') @@ -191,7 +218,11 @@ if (require.main === module) { 'a JSON string of key/value pairs to be set as file download options. See https://github.com/sindresorhus/electron-dl for available options.', parseJson, ) - .option('--tray', 'allow app to stay in system tray') + .option( + '--tray [start-in-tray]', + "Allow app to stay in system tray. If 'start-in-tray' is given as argument, don't show main window on first start", + parseMaybeBoolString, + ) .option('--basic-auth-username ', 'basic http(s) auth username') .option('--basic-auth-password ', 'basic http(s) auth password') .option('--always-on-top', 'enable always on top window') @@ -203,7 +234,7 @@ if (require.main === module) { '--global-shortcuts ', 'JSON file with global shortcut configuration. See https://github.com/jiahaog/nativefier/blob/master/docs/api.md#global-shortcuts', ) - .parse(process.argv); + .parse(sanitizedArgs); if (!process.argv.slice(2).length) { program.help();