diff --git a/electron/main.ts b/electron/main.ts index dea4321458..02c78ac85b 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, @@ -280,17 +279,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 +353,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,11 +365,15 @@ if (!gotTheLock) { } else { logWarning('Protocol already registered.', LogPrefix.Backend) } - if (process.argv[1]) { - const url = process.argv[1] - handleProtocol(mainWindow, url) + + const { startInTray } = await GlobalConfig.get().getSettings() + const headless = process.argv.includes('--no-gui') || 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 setTimeout(() => { const zoomFactor = @@ -512,7 +505,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)) @@ -895,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-gui')) { + app.exit() + } }) } ) 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