Skip to content

Commit f10051f

Browse files
authored
Add new --no-gui parameter (Heroic-Games-Launcher#1362)
* Make handleProtocol search for the protocol string by itself * Hide UI if --no-ui parameter is passed * Exit after game launch if --no-ui is passed * Rename "--no-ui" -> "--no-gui"
1 parent be15ad4 commit f10051f

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

electron/main.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ const isWindows = platform() === 'win32'
100100
let mainWindow: BrowserWindow = null
101101

102102
async function createWindow(): Promise<BrowserWindow> {
103-
const { exitToTray, startInTray } = await GlobalConfig.get().getSettings()
104103
configStore.set('userHome', userHome)
105104

106105
let windowProps: Electron.Rectangle = {
@@ -139,7 +138,7 @@ async function createWindow(): Promise<BrowserWindow> {
139138
...windowProps,
140139
minHeight: 345,
141140
minWidth: 600,
142-
show: !(exitToTray && startInTray),
141+
show: false,
143142
webPreferences: {
144143
webviewTag: true,
145144
contextIsolation: false,
@@ -280,17 +279,7 @@ if (!gotTheLock) {
280279
mainWindow.show()
281280
}
282281

283-
// Figure out which argv element is our protocol
284-
let heroicProtocolString = ''
285-
argv.forEach((value) => {
286-
if (value.startsWith('heroic://')) {
287-
heroicProtocolString = value
288-
}
289-
})
290-
291-
if (heroicProtocolString) {
292-
handleProtocol(mainWindow, heroicProtocolString)
293-
}
282+
handleProtocol(mainWindow, argv)
294283
})
295284
app.whenReady().then(async () => {
296285
const systemInfo = await getSystemInfo()
@@ -364,7 +353,7 @@ if (!gotTheLock) {
364353
await createWindow()
365354

366355
protocol.registerStringProtocol('heroic', (request, callback) => {
367-
handleProtocol(mainWindow, request.url)
356+
handleProtocol(mainWindow, [request.url])
368357
callback('Operation initiated.')
369358
})
370359
if (!app.isDefaultProtocolClient('heroic')) {
@@ -376,11 +365,15 @@ if (!gotTheLock) {
376365
} else {
377366
logWarning('Protocol already registered.', LogPrefix.Backend)
378367
}
379-
if (process.argv[1]) {
380-
const url = process.argv[1]
381-
handleProtocol(mainWindow, url)
368+
369+
const { startInTray } = await GlobalConfig.get().getSettings()
370+
const headless = process.argv.includes('--no-gui') || startInTray
371+
if (!headless) {
372+
mainWindow.show()
382373
}
383374

375+
handleProtocol(mainWindow, process.argv)
376+
384377
// set initial zoom level after a moment, if set in sync the value stays as 1
385378
setTimeout(() => {
386379
const zoomFactor =
@@ -512,7 +505,7 @@ app.on('window-all-closed', () => {
512505

513506
app.on('open-url', (event, url) => {
514507
event.preventDefault()
515-
handleProtocol(mainWindow, url)
508+
handleProtocol(mainWindow, [url])
516509
})
517510

518511
ipcMain.on('openFolder', async (event, folder) => openUrlOrFile(folder))
@@ -895,6 +888,11 @@ Game Settings: ${JSON.stringify(gameSettings, null, '\t')}
895888
runner,
896889
status: 'done'
897890
})
891+
892+
// Exit if we've been launched without UI
893+
if (process.argv.includes('--no-gui')) {
894+
app.exit()
895+
}
898896
})
899897
}
900898
)

electron/protocol.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@ import { Game, Runner } from './games'
33
import { logInfo, LogPrefix } from './logger/logger'
44
import i18next from 'i18next'
55

6-
export async function handleProtocol(window: BrowserWindow, url: string) {
6+
export async function handleProtocol(window: BrowserWindow, args: string[]) {
77
const mainWindow = BrowserWindow.getAllWindows()[0]
8+
9+
// Figure out which argv element is our protocol
10+
let url = ''
11+
args.forEach((val) => {
12+
if (val.startsWith('heroic://')) {
13+
url = val
14+
}
15+
})
16+
817
const [scheme, path] = url.split('://')
918
if (!url || scheme !== 'heroic' || !path) {
1019
return

0 commit comments

Comments
 (0)