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

[Fix] Several System Information improvements #3070

Merged
merged 4 commits into from
Sep 26, 2023
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
3 changes: 3 additions & 0 deletions src/backend/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export function initLogger() {
forceLog: true
})
})
.catch((error) =>
logError(['Failed to fetch system information', error], LogPrefix.Backend)
)

logInfo(['Legendary location:', join(...Object.values(getLegendaryBin()))], {
prefix: LogPrefix.Legendary,
Expand Down
10 changes: 9 additions & 1 deletion src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,15 @@ ipcMain.handle(

const logFileLocation = getLogFileLocation(appName)

const systemInfo = await getSystemInfo().then(formatSystemInfo)
const systemInfo = await getSystemInfo()
.then(formatSystemInfo)
.catch((error) => {
logError(
['Failed to fetch system information', error],
LogPrefix.Backend
)
return 'Error, check general log'
})
writeFileSync(logFileLocation, 'System Info:\n' + `${systemInfo}\n` + '\n')

const gameSettingsString = JSON.stringify(gameSettings, null, '\t')
Expand Down
3 changes: 2 additions & 1 deletion src/backend/utils/os/processes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ChildProcess, spawn } from 'child_process'
type SpawnWrapperOptions = Partial<{
onStdout: (data: string, child: ChildProcess) => unknown
onStderr: (data: string, child: ChildProcess) => unknown
env: Record<string, string | undefined>
}>

interface SpawnWrapperReturn {
Expand All @@ -17,7 +18,7 @@ async function genericSpawnWrapper(
args: string[] = [],
options: SpawnWrapperOptions = {}
): Promise<SpawnWrapperReturn> {
const child = spawn(command, args)
const child = spawn(command, args, { env: options?.env })
child.stdout.setEncoding('utf-8')
child.stderr.setEncoding('utf-8')

Expand Down
4 changes: 2 additions & 2 deletions src/backend/utils/systeminfo/gpu/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async function getGpuInfo_linux(): Promise<PartialGpuInfo[]> {
gpus.push({
// Electron gives us these IDs as numbers, most other use cases need
// them as hexadecimal strings
deviceId: gpu.deviceId.toString(16),
vendorId: gpu.vendorId.toString(16),
deviceId: gpu.deviceId.toString(16).padStart(4, '0'),
vendorId: gpu.vendorId.toString(16).padStart(4, '0'),
...(hasLspci ? await getLspciInfo(gpu.deviceId, gpu.vendorId) : {})
})
}
Expand Down
10 changes: 6 additions & 4 deletions src/backend/utils/systeminfo/memory/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import type { PartialMemoryInfo } from './index'
import { genericSpawnWrapper } from '../../os/processes'

async function getMemoryInfo_linux(): Promise<PartialMemoryInfo> {
const { stdout } = await genericSpawnWrapper('free', ['-b'])
const match = stdout.match(/^\w*:\s*(\d*)\s*(\d*)/m)
const { stdout } = await genericSpawnWrapper('free', ['-b'], {
env: { ...process.env, LANG: 'C' }
})
const match = stdout.match(/^\S*:\s*(\d*)\s*(\d*)/m)
const totalString = match?.[1]
const usedString = match?.[2]
return {
total: Number(totalString),
used: Number(usedString)
total: totalString ? Number(totalString) : 0,
used: usedString ? Number(usedString) : 0
}
}

Expand Down
1 change: 1 addition & 0 deletions src/backend/utils/systeminfo/osInfo/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function osInfo_linux(): Promise<{ name: string; version?: string }> {
try {
await stat(potPath)
os_release_path = potPath
break
} catch {
// We want to ignore errors here, since we're searching for a file that may not exist
}
Expand Down