Skip to content

Commit

Permalink
[UX] Enable/disable logs game-by-game instead of globally
Browse files Browse the repository at this point in the history
  • Loading branch information
arielj committed Dec 27, 2024
1 parent fd0b49a commit 5494279
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 36 deletions.
3 changes: 3 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@
"showMetalOverlay": "Show Stats Overlay",
"start-in-tray": "Start Minimized",
"steamruntime": "Use Steam Runtime",
"verboseLogs": {
"description": "Enable verbose logs"
},
"winecrossoverbottle": "CrossOver Bottle",
"wineprefix": "WinePrefix folder",
"wineversion": "Wine Version"
Expand Down
3 changes: 2 additions & 1 deletion src/backend/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ class GlobalConfigV0 extends GlobalConfig {
framelessWindow: false,
beforeLaunchScriptPath: '',
afterLaunchScriptPath: '',
disableUMU: false
disableUMU: false,
verboseLogs: false
}
// @ts-expect-error TODO: We need to settle on *one* place to define settings defaults
return settings
Expand Down
6 changes: 4 additions & 2 deletions src/backend/game_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ class GameConfigV0 extends GameConfig {
battlEyeRuntime,
beforeLaunchScriptPath,
afterLaunchScriptPath,
gamescope
gamescope,
verboseLogs
} = GlobalConfig.get().getSettings()

// initialize generic defaults
Expand Down Expand Up @@ -266,7 +267,8 @@ class GameConfigV0 extends GameConfig {
language: '', // we want to fallback to '' always here, fallback lang for games should be ''
beforeLaunchScriptPath,
afterLaunchScriptPath,
gamescope
gamescope,
verboseLogs
} as GameSettings

let gameSettings = {} as GameSettings
Expand Down
26 changes: 15 additions & 11 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1461,23 +1461,27 @@ async function runScriptForGame(
env: scriptEnv
})

child.stdout.on('data', (data) => {
appendGamePlayLog(gameInfo, data.toString())
})
if (gameSettings.verboseLogs) {
child.stdout.on('data', (data) => {
appendGamePlayLog(gameInfo, data.toString())
})

child.stderr.on('data', (data) => {
appendGamePlayLog(gameInfo, data.toString())
})
}

child.stderr.on('data', (data) => {
appendGamePlayLog(gameInfo, data.toString())
child.on('error', (err: Error) => {
if (gameSettings.verboseLogs) {
appendGamePlayLog(gameInfo, err.message)
if (err.stack) appendGamePlayLog(gameInfo, err.stack)
}
reject(err.message)
})

child.on('exit', () => {
resolve(true)
})

child.on('error', (err: Error) => {
appendGamePlayLog(gameInfo, err.message)
if (err.stack) appendGamePlayLog(gameInfo, err.stack)
reject(err.message)
})
})
}

Expand Down
8 changes: 0 additions & 8 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ import {
logError,
logInfo,
LogPrefix,
logsDisabled,
logWarning,
stopLogger
} from './logger/logger'
Expand Down Expand Up @@ -1017,13 +1016,6 @@ ipcMain.handle(

initGamePlayLog(game)

if (logsDisabled) {
appendGamePlayLog(
game,
'IMPORTANT: Logs are disabled. Enable logs before reporting an issue.'
)
}

const isNative = gameManagerMap[runner].isNative(appName)

// check if isNative, if not, check if wine is valid
Expand Down
10 changes: 8 additions & 2 deletions src/backend/storeManagers/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import {
logFileLocation,
logInfo,
LogPrefix,
logsDisabled,
logWarning
} from '../../logger/logger'
import { GOGUser } from './user'
Expand Down Expand Up @@ -686,6 +685,13 @@ export async function launch(
)
appendGamePlayLog(gameInfo, `Launch Command: ${fullCommand}\n\nGame Log:\n`)

if (!gameSettings.verboseLogs) {
appendGamePlayLog(
gameInfo,
'IMPORTANT: Logs are disabled. Enable verbose logs before reporting an issue.'
)
}

const userData: UserData | undefined = configStore.get_nodefault('userData')

sendGameStatusUpdate({ appName, runner: 'gog', status: 'playing' })
Expand Down Expand Up @@ -720,7 +726,7 @@ export async function launch(
wrappers,
logMessagePrefix: `Launching ${gameInfo.title}`,
onOutput: (output: string) => {
if (!logsDisabled) appendGamePlayLog(gameInfo, output)
if (gameSettings.verboseLogs) appendGamePlayLog(gameInfo, output)
}
})

Expand Down
12 changes: 9 additions & 3 deletions src/backend/storeManagers/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ import {
logError,
logFileLocation,
logInfo,
LogPrefix,
logsDisabled
LogPrefix
} from '../../logger/logger'
import {
prepareLaunch,
Expand Down Expand Up @@ -951,6 +950,13 @@ export async function launch(
)
appendGamePlayLog(gameInfo, `Launch Command: ${fullCommand}\n\nGame Log:\n`)

if (!gameSettings.verboseLogs) {
appendGamePlayLog(
gameInfo,
'IMPORTANT: Logs are disabled. Enable verbose logs before reporting an issue.'
)
}

sendGameStatusUpdate({ appName, runner: 'legendary', status: 'playing' })

const { error } = await runLegendaryCommand(command, {
Expand All @@ -959,7 +965,7 @@ export async function launch(
wrappers: wrappers,
logMessagePrefix: `Launching ${gameInfo.title}`,
onOutput: (output) => {
if (!logsDisabled) appendGamePlayLog(gameInfo, output)
if (gameSettings.verboseLogs) appendGamePlayLog(gameInfo, output)
}
})

Expand Down
12 changes: 9 additions & 3 deletions src/backend/storeManagers/nile/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import {
logDebug,
logError,
logFileLocation,
logInfo,
logsDisabled
logInfo
} from 'backend/logger/logger'
import { isLinux, isWindows } from 'backend/constants'
import { GameConfig } from 'backend/game_config'
Expand Down Expand Up @@ -416,6 +415,13 @@ export async function launch(
)
appendGamePlayLog(gameInfo, `Launch Command: ${fullCommand}\n\nGame Log:\n`)

if (!gameSettings.verboseLogs) {
appendGamePlayLog(
gameInfo,
'IMPORTANT: Logs are disabled. Enable verbose logs before reporting an issue.'
)
}

sendGameStatusUpdate({ appName, runner: 'nile', status: 'playing' })

const { error } = await runNileCommand(commandParts, {
Expand All @@ -424,7 +430,7 @@ export async function launch(
wrappers,
logMessagePrefix: `Launching ${gameInfo.title}`,
onOutput(output) {
if (!logsDisabled) appendGamePlayLog(gameInfo, output)
if (gameSettings.verboseLogs) appendGamePlayLog(gameInfo, output)
}
})

Expand Down
3 changes: 1 addition & 2 deletions src/backend/storeManagers/storeManagerCommon/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
lastPlayLogFileLocation,
logInfo,
LogPrefix,
logsDisabled,
logWarning
} from '../../logger/logger'
import { basename, dirname } from 'path'
Expand Down Expand Up @@ -262,7 +261,7 @@ export async function launchGame(
logFile: lastPlayLogFileLocation(appName),
logMessagePrefix: LogPrefix.Backend,
onOutput: (output) => {
if (!logsDisabled) appendGamePlayLog(gameInfo, output)
if (gameSettings.verboseLogs) appendGamePlayLog(gameInfo, output)
}
}
})
Expand Down
12 changes: 8 additions & 4 deletions src/backend/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,9 @@ export async function checkWineBeforeLaunch(
`Wine version ${gameSettings.wineVersion.name} is not valid, trying another one.`,
LogPrefix.Backend
)
}

if (gameSettings.verboseLogs) {
appendGamePlayLog(
gameInfo,
`Wine version ${gameSettings.wineVersion.name} is not valid, trying another one.\n`
Expand All @@ -992,10 +994,12 @@ export async function checkWineBeforeLaunch(

if (response === 0) {
logInfo(`Changing wine version to ${defaultwine.name}`)
appendGamePlayLog(
gameInfo,
`Changing wine version to ${defaultwine.name}\n`
)
if (gameSettings.verboseLogs) {
appendGamePlayLog(
gameInfo,
`Changing wine version to ${defaultwine.name}\n`
)
}
gameSettings.wineVersion = defaultwine
GameConfig.get(gameInfo.app_name).setSetting('wineVersion', defaultwine)
return true
Expand Down
2 changes: 2 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export interface AppSettings extends GameSettings {
startInTray: boolean
allowInstallationBrokenAnticheat: boolean
disableUMU: boolean
verboseLogs: boolean
}

export type LibraryTopSectionOptions =
Expand Down Expand Up @@ -203,6 +204,7 @@ export interface GameSettings {
beforeLaunchScriptPath: string
afterLaunchScriptPath: string
disableUMU: boolean
verboseLogs: boolean
}

export type Status =
Expand Down
30 changes: 30 additions & 0 deletions src/frontend/screens/Settings/components/VerboseLogs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { useContext } from 'react'
import { useTranslation } from 'react-i18next'
import { ToggleSwitch } from 'frontend/components/UI'
import useSetting from 'frontend/hooks/useSetting'
import SettingsContext from '../SettingsContext'

const VerboseLogs = () => {
const { t } = useTranslation()

const { isDefault } = useContext(SettingsContext)

const [verboseLogs, setVerboseLogs] = useSetting('verboseLogs', false)

if (isDefault) {
return <></>
}

return (
<div className="toggleRow">
<ToggleSwitch
htmlId="verboseLogs"
value={verboseLogs}
handleChange={() => setVerboseLogs(!verboseLogs)}
title={t('setting.verboseLogs.description', 'Enable verbose logs')}
/>
</div>
)
}

export default VerboseLogs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import FooterInfo from '../FooterInfo'
import { Tabs, Tab } from '@mui/material'
import { GameInfo } from 'common/types'
import DisableUMU from '../../components/DisableUMU'
import VerboseLogs from '../../components/VerboseLogs'

const windowsPlatforms = ['Win32', 'Windows', 'windows']
function getStartingTab(platform: string, gameInfo?: GameInfo | null): string {
Expand Down Expand Up @@ -215,6 +216,7 @@ export default function GamesSettings() {
<OfflineMode />
</>
)}
<VerboseLogs />
<DisableUMU />
<AlternativeExe />
<LauncherArgs />
Expand Down

0 comments on commit 5494279

Please sign in to comment.