Skip to content

Commit

Permalink
[Tech]: electron side changes to window behavior (#3300)
Browse files Browse the repository at this point in the history
* improv: Electron side changes to window behavior

window now has a background which should prevent flashing of white, window is shown after its contents are loaded

* fix: use ready-to-show event apply maximize only when displaying window
  • Loading branch information
imLinguin authored Dec 9, 2023
1 parent e096519 commit f2911ee
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/backend/api/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export const openWebviewPage = (url: string) =>
export const setZoomFactor = (zoom: string) =>
ipcRenderer.send('setZoomFactor', zoom)
export const frontendReady = () => ipcRenderer.send('frontendReady')
export const loadingScreenReady = () => ipcRenderer.send('loadingScreenReady')
export const lock = () => ipcRenderer.send('lock')
export const unlock = () => ipcRenderer.send('unlock')
export const login = async (sid: string) => ipcRenderer.invoke('login', sid)
Expand Down
17 changes: 10 additions & 7 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ if (!gotTheLock) {
GOGUser.migrateCredentialsConfig()
const mainWindow = await initializeWindow()

protocol.registerStringProtocol('heroic', (request, callback) => {
protocol.handle('heroic', (request) => {
handleProtocol([request.url])
callback('Operation initiated.')
return new Response('Operation initiated.', { status: 201 })
})
if (!app.isDefaultProtocolClient('heroic')) {
if (app.setAsDefaultProtocolClient('heroic')) {
Expand All @@ -436,7 +436,14 @@ if (!gotTheLock) {
const { startInTray } = GlobalConfig.get().getSettings()
const headless = isCLINoGui || startInTray
if (!headless) {
ipcMain.once('loadingScreenReady', () => mainWindow.show())
mainWindow.once('ready-to-show', () => {
const props = configStore.get_nodefault('window-props')
mainWindow.show()
// Apply maximize only if we show the window
if (props?.maximized) {
mainWindow.maximize()
}
})
}

// set initial zoom level after a moment, if set in sync the value stays as 1
Expand All @@ -462,10 +469,6 @@ if (!gotTheLock) {

ipcMain.on('notify', (event, args) => notify(args))

ipcMain.once('loadingScreenReady', () => {
logInfo('Loading Screen Ready', LogPrefix.Backend)
})

ipcMain.once('frontendReady', () => {
logInfo('Frontend Ready', LogPrefix.Backend)
handleProtocol([openUrlArgument, ...process.argv])
Expand Down
8 changes: 2 additions & 6 deletions src/backend/main_window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export const createMainWindow = () => {
windowProps.frame = false
}
}
const { maximized, ...props } = windowProps

// Create the browser window.
mainWindow = new BrowserWindow({
...props,
...windowProps,
minHeight: 345,
minWidth: 600,
show: false,
Expand All @@ -85,9 +85,5 @@ export const createMainWindow = () => {
}
})

if (maximized) {
mainWindow.maximize()
}

return mainWindow
}
1 change: 0 additions & 1 deletion src/common/typedefs/ipcBridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ interface SyncIPCFunctions {
changeLanguage: (language: string) => void
notify: (args: { title: string; body: string }) => void
frontendReady: () => void
loadingScreenReady: () => void
lock: () => void
unlock: () => void
quit: () => void
Expand Down
7 changes: 1 addition & 6 deletions src/frontend/screens/Loading/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React, { useEffect } from 'react'
import React from 'react'

import { UpdateComponentBase } from 'frontend/components/UI/UpdateComponent'
import { useTranslation } from 'react-i18next'

const Loading = function () {
const { t } = useTranslation()

useEffect(() => {
window.api.loadingScreenReady()
})

return <UpdateComponentBase message={t('label.loading', 'Loading')} />
}

Expand Down

0 comments on commit f2911ee

Please sign in to comment.