Hello, I'm using electron-forge to build my app and I'm focused on MacOS at the moment.
I plan to include a simple CLI with my app such that it can be launched from the command line. I'd also like the CLI to accept a path as well as some simple commands. I have this working with the second-instance hook like this:
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
return
}
app.on('second-instance', (event, commandLine, workingDirectory, additionalData) => {
const secondInstanceArgs = yargs(hideBin(commandLine))
.command("$0 [path]", "open to repo", () => {}, (argv) => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore()
}
selectRepo(mainWindow, argv.path || workingDirectory)
mainWindow.focus()
app.focus({ steal: true })
} else {
createMainWindow()
}
})
.command("commit [path]", "Open commit window", () => {}, (argv) => {
createCommitWindow()
})
.help()
.argv
console.log("*******************")
console.log("Args:")
console.log(secondInstanceArgs)
console.log("*******************")
})
If I have the primary instance running, this is working when I run npm exec electron . COMMAND PATH in my terminal at the root of the project. It also works if I run npm exec -c 'electron-forge start -- COMMAND PATH'.
However, I'm running into issues with a built Electron app. First, I'm not sure the best way to launch an Electron app (built with Forge) from the terminal with args. When I run MyApp.app/Contents/MacOs/MyApp the app does launch but I also get a bunch of terminal output and the process continues to run in the terminal such that when I exit the terminal, the app also exits. I also can't seem to get the app to pick up my args when I launch it this way. Is there a way I can execute electron-forge start from the built app Contents?
Thanks in advance for the help!