Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new --no-gui parameter #1362

Merged
merged 4 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ const isWindows = platform() === 'win32'
let mainWindow: BrowserWindow = null

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

let windowProps: Electron.Rectangle = {
Expand Down Expand Up @@ -139,7 +138,7 @@ async function createWindow(): Promise<BrowserWindow> {
...windowProps,
minHeight: 345,
minWidth: 600,
show: !(exitToTray && startInTray),
show: false,
webPreferences: {
webviewTag: true,
contextIsolation: false,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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')) {
Expand All @@ -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 =
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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()
}
})
}
)
Expand Down
11 changes: 10 additions & 1 deletion electron/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down