Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --help and --new-window flag and fix --version flag #6455

Merged
merged 5 commits into from
Jan 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} */
let ALLOWED_RENDERER_FILES
Expand Down Expand Up @@ -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()
Expand Down
Loading