From 768aee1d2302590d4192030c2de3a54774f7c960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= Date: Mon, 23 May 2022 13:19:59 +0200 Subject: [PATCH 1/4] Make handleProtocol search for the protocol string by itself --- electron/main.ts | 22 +++++----------------- electron/protocol.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index dea4321458..126d902ec6 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -280,17 +280,7 @@ if (!gotTheLock) { mainWindow.show() } - // Figure out which argv element is our protocol - let heroicProtocolString = '' - argv.forEach((value) => { - if (value.startsWith('heroic://')) { - heroicProtocolString = value - } - }) - - if (heroicProtocolString) { - handleProtocol(mainWindow, heroicProtocolString) - } + handleProtocol(mainWindow, argv) }) app.whenReady().then(async () => { const systemInfo = await getSystemInfo() @@ -364,7 +354,7 @@ if (!gotTheLock) { await createWindow() protocol.registerStringProtocol('heroic', (request, callback) => { - handleProtocol(mainWindow, request.url) + handleProtocol(mainWindow, [request.url]) callback('Operation initiated.') }) if (!app.isDefaultProtocolClient('heroic')) { @@ -376,10 +366,8 @@ if (!gotTheLock) { } else { logWarning('Protocol already registered.', LogPrefix.Backend) } - if (process.argv[1]) { - const url = process.argv[1] - handleProtocol(mainWindow, url) - } + + handleProtocol(mainWindow, process.argv) // set initial zoom level after a moment, if set in sync the value stays as 1 setTimeout(() => { @@ -512,7 +500,7 @@ app.on('window-all-closed', () => { app.on('open-url', (event, url) => { event.preventDefault() - handleProtocol(mainWindow, url) + handleProtocol(mainWindow, [url]) }) ipcMain.on('openFolder', async (event, folder) => openUrlOrFile(folder)) diff --git a/electron/protocol.ts b/electron/protocol.ts index 33585a1ffa..270f0c7556 100644 --- a/electron/protocol.ts +++ b/electron/protocol.ts @@ -3,8 +3,17 @@ import { Game, Runner } from './games' import { logInfo, LogPrefix } from './logger/logger' import i18next from 'i18next' -export async function handleProtocol(window: BrowserWindow, url: string) { +export async function handleProtocol(window: BrowserWindow, args: string[]) { const mainWindow = BrowserWindow.getAllWindows()[0] + + // Figure out which argv element is our protocol + let url = '' + args.forEach((val) => { + if (val.startsWith('heroic://')) { + url = val + } + }) + const [scheme, path] = url.split('://') if (!url || scheme !== 'heroic' || !path) { return From 1105846a33d31bd5c891b178e2dff992e8bb4e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= Date: Mon, 23 May 2022 13:20:52 +0200 Subject: [PATCH 2/4] Hide UI if --no-ui parameter is passed --- electron/main.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index 126d902ec6..b7c1107419 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -100,7 +100,6 @@ const isWindows = platform() === 'win32' let mainWindow: BrowserWindow = null async function createWindow(): Promise { - const { exitToTray, startInTray } = await GlobalConfig.get().getSettings() configStore.set('userHome', userHome) let windowProps: Electron.Rectangle = { @@ -139,7 +138,7 @@ async function createWindow(): Promise { ...windowProps, minHeight: 345, minWidth: 600, - show: !(exitToTray && startInTray), + show: false, webPreferences: { webviewTag: true, contextIsolation: false, @@ -367,6 +366,12 @@ if (!gotTheLock) { logWarning('Protocol already registered.', LogPrefix.Backend) } + const { startInTray } = await GlobalConfig.get().getSettings() + const headless = process.argv.includes('--no-ui') || startInTray + if (!headless) { + mainWindow.show() + } + handleProtocol(mainWindow, process.argv) // set initial zoom level after a moment, if set in sync the value stays as 1 From a1d61ee048788cfe486e959b0b4b8af992d2d0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= Date: Mon, 23 May 2022 13:23:43 +0200 Subject: [PATCH 3/4] Exit after game launch if --no-ui is passed --- electron/main.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/electron/main.ts b/electron/main.ts index b7c1107419..967ee9a665 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -888,6 +888,11 @@ Game Settings: ${JSON.stringify(gameSettings, null, '\t')} runner, status: 'done' }) + + // Exit if we've been launched without UI + if (process.argv.includes('--no-ui')) { + app.exit() + } }) } ) From 19e3fb47da4d5331deb7175b04a254d3648711aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Dr=C3=B6ge?= Date: Tue, 24 May 2022 11:24:42 +0200 Subject: [PATCH 4/4] Rename "--no-ui" -> "--no-gui" --- electron/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index 967ee9a665..02c78ac85b 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -367,7 +367,7 @@ if (!gotTheLock) { } const { startInTray } = await GlobalConfig.get().getSettings() - const headless = process.argv.includes('--no-ui') || startInTray + const headless = process.argv.includes('--no-gui') || startInTray if (!headless) { mainWindow.show() } @@ -890,7 +890,7 @@ Game Settings: ${JSON.stringify(gameSettings, null, '\t')} }) // Exit if we've been launched without UI - if (process.argv.includes('--no-ui')) { + if (process.argv.includes('--no-gui')) { app.exit() } })