Fix processing arguments from second instance
This commit is contained in:
@@ -16,6 +16,9 @@ const windows = require('./windows')
|
||||
let shouldQuit = false
|
||||
let argv = sliceArgv(process.argv)
|
||||
|
||||
// allow electron/chromium to play startup sounds (without user interaction)
|
||||
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required')
|
||||
|
||||
// Start the app without showing the main window when auto launching on login
|
||||
// (On Windows and Linux, we get a flag. On MacOS, we get special API.)
|
||||
const hidden = argv.includes('--hidden') ||
|
||||
@@ -31,6 +34,12 @@ if (process.platform === 'win32') {
|
||||
const squirrelWin32 = require('./squirrel-win32')
|
||||
shouldQuit = squirrelWin32.handleEvent(argv[0])
|
||||
argv = argv.filter((arg) => !arg.includes('--squirrel'))
|
||||
|
||||
if (shouldQuit) {
|
||||
app.quit()
|
||||
} else {
|
||||
app.on('second-instance', (event, commandLine) => onAppOpen(commandLine))
|
||||
}
|
||||
}
|
||||
|
||||
if (!shouldQuit && !config.IS_PORTABLE) {
|
||||
@@ -39,11 +48,16 @@ if (!shouldQuit && !config.IS_PORTABLE) {
|
||||
// %APPDATA%\Roaming\WebTorrent so we do not do it for the Portable App since
|
||||
// we want to be "silent" as well as "portable".
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
app.quit()
|
||||
shouldQuit = true
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldQuit) {
|
||||
app.quit()
|
||||
} else {
|
||||
app.on('second-instance', (event, commandLine, workingDirectory) => onAppOpen(commandLine))
|
||||
}
|
||||
|
||||
if (!shouldQuit) {
|
||||
init()
|
||||
}
|
||||
@@ -168,6 +182,19 @@ function onOpen (e, torrentId) {
|
||||
}
|
||||
}
|
||||
|
||||
function onAppOpen (newArgv) {
|
||||
newArgv = sliceArgv(newArgv)
|
||||
|
||||
if (app.ipcReady) {
|
||||
log('Second app instance opened, but was prevented:', newArgv)
|
||||
windows.main.show()
|
||||
|
||||
processArgv(newArgv)
|
||||
} else {
|
||||
argv.push(...newArgv)
|
||||
}
|
||||
}
|
||||
|
||||
// Remove leading args.
|
||||
// Production: 1 arg, eg: /Applications/WebTorrent.app/Contents/MacOS/WebTorrent
|
||||
// Development: 2 args, eg: electron .
|
||||
|
||||
Reference in New Issue
Block a user