Skip to content

[Tech] System info cache #1897

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

Merged
merged 2 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ if (!gotTheLock) {
app.whenReady().then(async () => {
initOnlineMonitor()

const systemInfo = await getSystemInfo()
getSystemInfo().then((systemInfo) =>
logInfo(`\n\n${systemInfo}\n`, { prefix: LogPrefix.Backend })
)

initImagesCache()

Expand All @@ -355,7 +357,6 @@ if (!gotTheLock) {
logInfo(['GOGDL location:', join(...Object.values(getGOGdlBin()))], {
prefix: LogPrefix.Gog
})
logInfo(`\n\n${systemInfo}\n`, { prefix: LogPrefix.Backend })
// We can't use .config since apparently its not loaded fast enough.
const { language, darkTrayIcon } = await GlobalConfig.get().getSettings()

Expand Down Expand Up @@ -1001,7 +1002,6 @@ ipcMain.handle(
game.logFileLocation,
'System Info:\n' +
`${systemInfo}\n` +
'\n' +
`Game Settings: ${gameSettingsString}\n` +
'\n' +
`Game launched at: ${startPlayingDate}\n` +
Expand Down
9 changes: 8 additions & 1 deletion src/backend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ async function handleExit(window: BrowserWindow) {
app.exit()
}

// This won't change while the app is running
// Caching significantly increases performance when launching games
let systemInfoCache = ''
export const getSystemInfo = async () => {
if (systemInfoCache !== '') {
return systemInfoCache
}
const heroicVersion = getHeroicVersion()
const legendaryVersion = await getLegendaryVersion()

Expand Down Expand Up @@ -276,7 +282,7 @@ export const getSystemInfo = async () => {
? (await execAsync('echo $XDG_SESSION_TYPE')).stdout.replaceAll('\n', '')
: ''

return `Heroic Version: ${heroicVersion}
systemInfoCache = `Heroic Version: ${heroicVersion}
Legendary Version: ${legendaryVersion}
OS: ${distro} KERNEL: ${kernel} ARCH: ${arch}
CPU: ${manufacturer} ${brand} @${speed} ${
Expand All @@ -285,6 +291,7 @@ CPU: ${manufacturer} ${brand} @${speed} ${
RAM: Total: ${getFileSize(total)} Available: ${getFileSize(available)}
GRAPHICS: ${graphicsCards}
${isLinux ? `PROTOCOL: ${xEnv}` : ''}`
return systemInfoCache
}

type ErrorHandlerMessage = {
Expand Down