From afcd113675c36282db8855788cd6901009236258 Mon Sep 17 00:00:00 2001 From: Gregor Biswanger Date: Fri, 2 Jul 2021 16:50:48 +0200 Subject: [PATCH] singleInstance handle command line arguments --- Changelog.md | 1 + ElectronNET.Host/main.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 8dc8821..ed123ff 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,6 +16,7 @@ ElectronNET.API: * Breaking API Changes (from native Electron 13.1.5): - `Shell.MoveItemToTrashAsync` renamed with `Shell.TrashItemAsync` - The deprecated extension APIs have been removed: `BrowserWindow.GetAllExtensionsAsync()`, `BrowserWindow.RemoveExtension()`, `BrowserWindow.AddExtensionAsync()`. Use the session APIs instead: `Session.GetAllExtensionsAsync()`, `Session.RemoveExtension()`, `Session.LoadExtensionAsync()`. +* New Feature: singleInstance handle command line arguments [\#520](https://github.com/ElectronNET/Electron.NET/issues/520) * New Feature: Add WebContents [insertCSS](https://www.electronjs.org/docs/api/web-contents#contentsinsertcsscss-options) functionality (thanks [nfichter](https://github.com/nfichter)) [\#559](https://github.com/ElectronNET/Electron.NET/pull/559) * New Feature: Allow IpcMain to send IPC messages to BrowserViews (thanks [nfichter](https://github.com/nfichter)) [\#560](https://github.com/ElectronNET/Electron.NET/pull/560) * New Feature: Add support for proxies that require basic username/password authentication (thanks [nfichter](https://github.com/nfichter)) [\#561](https://github.com/ElectronNET/Electron.NET/pull/561) diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index 838d237..37d8be8 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -50,7 +50,17 @@ app.on('will-finish-launching', () => { const manifestJsonFile = require(manifestJsonFilePath); if (manifestJsonFile.singleInstance || manifestJsonFile.aspCoreBackendPort) { const mainInstance = app.requestSingleInstanceLock(); - app.on('second-instance', () => { + app.on('second-instance', (events, args = []) => { + args.forEach(parameter => { + const words = parameter.split('='); + + if(words.length > 1) { + app.commandLine.appendSwitch(words[0].replace('--', ''), words[1]); + } else { + app.commandLine.appendSwitch(words[0].replace('--', '')); + } + }); + const windows = BrowserWindow.getAllWindows(); if (windows.length) { if (windows[0].isMinimized()) {