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

[UX] Allow setting the Disable UMU default in General Settings > Game Defaults #4378

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
103 changes: 103 additions & 0 deletions src/backend/__tests__/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { GlobalConfig } from 'backend/config'
import {
appFolder,
configPath,
defaultWinePrefix,
getSteamCompatFolder,
heroicInstallPath,
setPlatformConstants
} from 'backend/constants'
import { existsSync, mkdirSync, rmSync } from 'graceful-fs'

describe('GlobalConfig', () => {
const sharedDefaults = {
checkUpdatesInterval: 10,
enableUpdates: false,
addDesktopShortcuts: false,
addStartMenuShortcuts: false,
addSteamShortcuts: false,
checkForUpdatesOnStartup: true,
autoUpdateGames: false,
framelessWindow: false,
beforeLaunchScriptPath: '',
afterLaunchScriptPath: '',
verboseLogs: false,
hideChangelogsOnStartup: false,
language: 'en',
maxWorkers: 0,
minimizeOnLaunch: false,
libraryTopSection: 'disabled'
}

const windowsDefaults = {
wineVersion: {}
}

const macDefaults = {
enableMsync: true,
wineCrossoverBottle: 'Heroic'
}

const linuxDefaults = {
autoInstallDxvk: true,
autoInstallVkd3d: true,
autoInstallDxvkNvapi: true,
preferSystemLibs: false,
customWinePaths: [],
nvidiaPrime: false,
enviromentOptions: [],
wrapperOptions: [],
showFps: false,
useGameMode: false,
defaultInstallPath: heroicInstallPath,
defaultSteamPath: getSteamCompatFolder(),
defaultWinePrefix: defaultWinePrefix,
// winePrefix: '/home/<user>/Games/Heroic/Prefixes/default',
// wineVersion: {
// bin: '/usr/bin/wine',
// name: 'Wine Default - wine-10.2 (Staging)',
// type: 'wine',
// wineserver: '/usr/bin/wineserver'
// },
enableEsync: true,
enableFsync: true,
eacRuntime: true,
battlEyeRuntime: true,
disableUMU: false
}
describe('getSettings', () => {
describe('returns defaults if no settings yet', () => {
const getSettings = () => {
// create config dir if needed
if (!existsSync(appFolder)) mkdirSync(appFolder, { recursive: true })

// clear global config so we initialize a new one
if (existsSync(configPath)) rmSync(configPath)
GlobalConfig['globalInstance'] = null as any

return GlobalConfig.get().getSettings()
}

it('Linux defaults', () => {
setPlatformConstants('linux')
const settings = getSettings()
expect(settings).toMatchObject(sharedDefaults)
expect(settings).toMatchObject(linuxDefaults)
})

it('Windows defaults', () => {
setPlatformConstants('win32')
const settings = getSettings()
expect(settings).toMatchObject(sharedDefaults)
expect(settings).toMatchObject(windowsDefaults)
})

it('MacOS defaults', () => {
setPlatformConstants('darwin')
const settings = getSettings()
expect(settings).toMatchObject(sharedDefaults)
expect(settings).toMatchObject(macDefaults)
})
})
})
})
40 changes: 40 additions & 0 deletions src/backend/__tests__/game_config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { GlobalConfig } from 'backend/config'
import {
configPath,
gamesConfigPath,
setPlatformConstants
} from 'backend/constants'
import { GameConfig } from 'backend/game_config'
import { existsSync, mkdirSync, rmSync } from 'graceful-fs'
import { join } from 'path'

describe('GameSettings', () => {
describe('getSettings', () => {
describe('returns defaults if no settings yet', () => {
const getSettings = async () => {
const appName = 'some-app-name'

// create config dir if needed
if (!existsSync(gamesConfigPath))
mkdirSync(gamesConfigPath, { recursive: true })

// delete game config if present config
const path = join(gamesConfigPath, appName + '.json')
if (existsSync(path)) rmSync(path)

// reset global config singleton so we can test different platforms
GlobalConfig['globalInstance'] = null as any
if (existsSync(configPath)) rmSync(configPath)

const config = GameConfig.get(appName)
return await config.getSettings()
}

it('linux defaults', async () => {
setPlatformConstants('linux')
const settings = await getSettings()
expect(settings.disableUMU).toBe(false)
})
})
})
})
25 changes: 22 additions & 3 deletions src/backend/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ const fontsStore = new TypeCheckedStoreBackend('fontsStore', {
name: 'fonts'
})

const isMac = process.platform === 'darwin'
const isWindows = process.platform === 'win32'
const isLinux = process.platform === 'linux'
let isMac = false
let isWindows = false
let isLinux = false

// This is meant to be used only during tests to change the `isXYZ` platform constants
// and allow testing different platform logic
export function setPlatformConstants(
force_platform?: 'darwin' | 'win32' | 'linux'
) {
if (force_platform) {
isMac = force_platform === 'darwin'
isWindows = force_platform === 'win32'
isLinux = force_platform === 'linux'
} else {
isMac = process.platform === 'darwin'
isWindows = process.platform === 'win32'
isLinux = process.platform === 'linux'
}
}
setPlatformConstants()

const isSteamDeckGameMode = process.env.XDG_CURRENT_DESKTOP === 'gamescope'
const isCLIFullscreen = process.argv.includes('--fullscreen')
const isCLINoGui = process.argv.includes('--no-gui')
Expand Down Expand Up @@ -230,6 +248,7 @@ export function createNecessaryFolders() {
}

export {
appFolder,
currentGameConfigVersion,
currentGlobalConfigVersion,
currentLogFile,
Expand Down
12 changes: 8 additions & 4 deletions src/backend/game_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
isMac,
isWindows,
userHome,
defaultWinePrefix
defaultWinePrefix,
isLinux
} from './constants'
import { logError, logInfo, LogPrefix } from './logger/logger'
import { join } from 'path'
Expand Down Expand Up @@ -235,7 +236,8 @@ class GameConfigV0 extends GameConfig {
beforeLaunchScriptPath,
afterLaunchScriptPath,
gamescope,
verboseLogs
verboseLogs,
disableUMU
} = GlobalConfig.get().getSettings()

// initialize generic defaults
Expand Down Expand Up @@ -277,10 +279,12 @@ class GameConfigV0 extends GameConfig {
// read game's settings
const settings = JSON.parse(readFileSync(this.path, 'utf-8'))
gameSettings = settings[this.appName] || ({} as GameSettings)
} else {
}

if (isLinux && gameSettings.disableUMU === undefined) {
// only set the `disableUMU` default value when getting settings for a new game
// we want it to be `undefined` for games that were installed already
defaultSettings.disableUMU = false
defaultSettings.disableUMU = disableUMU
}

if (!isWindows) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface AppSettings extends GameSettings {
disableController: boolean
disablePlaytimeSync: boolean
disableLogs: boolean
disableUMU: boolean
discordRPC: boolean
downloadNoHttps: boolean
egsLinkedPath: string
Expand All @@ -104,7 +105,6 @@ export interface AppSettings extends GameSettings {
minimizeOnLaunch: boolean
startInTray: boolean
allowInstallationBrokenAnticheat: boolean
disableUMU: boolean
verboseLogs: boolean
}

Expand Down
6 changes: 5 additions & 1 deletion src/frontend/screens/Settings/components/DisableUMU.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const DisableUMU = () => {
const [disableUMU, setDisableUMU] = useSetting('disableUMU', false)
const [wineVersion] = useSetting('wineVersion', defaultWineVersion)

if (isDefault || platform !== 'linux' || wineVersion.type !== 'proton') {
if (platform !== 'linux') {
return <></>
}

if (!isDefault && wineVersion.type !== 'proton') {
return <></>
}

Expand Down
Loading