Skip to content

Commit

Permalink
Add --help and --new-window flag and fix --version flag (FreeTubeApp#…
Browse files Browse the repository at this point in the history
…6455)

* Add --new-window command line flag

* Fix --version flag

* Add --help command line flag

* Update src/main/index.js

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

---------

Co-authored-by: Alexander Rosenberg <zanderpkg@pm.me>
Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>
  • Loading branch information
3 people authored and Alban Dumas committed Jan 24, 2025
1 parent de97797 commit 5414039
Showing 1 changed file with 28 additions and 4 deletions.
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

0 comments on commit 5414039

Please sign in to comment.