Skip to content

Commit

Permalink
warn on empty WinePrefixesBasePath
Browse files Browse the repository at this point in the history
  • Loading branch information
pt8o committed Aug 24, 2024
1 parent 0b1e1c7 commit 17fb14e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@
"default-install-path": "Default Installation Path",
"default-steam-path": "Default Steam path",
"defaultWinePrefix": "Set Folder for new Wine Prefixes",
"defaultWinePrefixEmpty": "Warning: empty path may cause installation problems.",
"disable_controller": "Disable Heroic navigation using controller",
"disable_logs": "Disable Logs",
"disablePlaytimeSync": "Disable playtime synchronization",
Expand Down
49 changes: 46 additions & 3 deletions src/frontend/screens/Settings/components/WinePrefixesBasePath.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useContext } from 'react'
import React, { useContext, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import ContextProvider from 'frontend/state/ContextProvider'
import useSetting from 'frontend/hooks/useSetting'
import { PathSelectionBox } from 'frontend/components/UI'
import { PathSelectionBox, SvgButton } from 'frontend/components/UI'
import SettingsContext from 'frontend/screens/Settings/SettingsContext'
import { Undo } from '@mui/icons-material'
import { Box } from '@mui/material'

const WinePrefixesBasePath = () => {
const { t } = useTranslation()
Expand All @@ -19,20 +21,61 @@ const WinePrefixesBasePath = () => {
'defaultWinePrefix',
''
)
const [lastValidPrefix, setLastValidPrefix] = useState(defaultWinePrefix)

function handlePathChange(val: string) {
setDefaultWinePrefix(val)
if (val) {
setLastValidPrefix(val)
}
}

function handleRevert() {
setDefaultWinePrefix(lastValidPrefix)
}

const warning = useMemo(() => {
if (defaultWinePrefix !== '') return undefined
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
paddingBlockStart: 'var(--space-sm)',
gap: 1,
color: 'var(--status-warning)'
}}
>
{t(
'setting.defaultWinePrefixEmpty',
'Warning: empty path may cause installation problems.'
)}
{lastValidPrefix && (
<SvgButton
className="button button-icon-flex is-danger"
onClick={handleRevert}
>
<Undo />
</SvgButton>
)}
</Box>
)
}, [])

return (
<PathSelectionBox
htmlId="selectDefaultWinePrefix"
label={t('setting.defaultWinePrefix', 'Set Folder for new Wine Prefixes')}
path={defaultWinePrefix}
onPathChange={setDefaultWinePrefix}
onPathChange={handlePathChange}
type="directory"
pathDialogTitle={t(
'toolbox.settings.wineprefix',
'Select a Folder for new Wine Prefixes'
)}
noDeleteButton
pathDialogDefaultPath={defaultWinePrefix}
warning={warning}
/>
)
}
Expand Down

0 comments on commit 17fb14e

Please sign in to comment.