From 17fb14ed7c265047fb89781925d1ae218acd79bd Mon Sep 17 00:00:00 2001 From: Lucas Huang Date: Mon, 12 Aug 2024 18:26:21 -0400 Subject: [PATCH] warn on empty WinePrefixesBasePath --- public/locales/en/translation.json | 1 + .../components/WinePrefixesBasePath.tsx | 49 +++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index c45f27f1fb..7757b209d7 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -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", diff --git a/src/frontend/screens/Settings/components/WinePrefixesBasePath.tsx b/src/frontend/screens/Settings/components/WinePrefixesBasePath.tsx index 79014fb4f9..85d0b8e34d 100644 --- a/src/frontend/screens/Settings/components/WinePrefixesBasePath.tsx +++ b/src/frontend/screens/Settings/components/WinePrefixesBasePath.tsx @@ -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() @@ -19,13 +21,53 @@ 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 ( + + {t( + 'setting.defaultWinePrefixEmpty', + 'Warning: empty path may cause installation problems.' + )} + {lastValidPrefix && ( + + + + )} + + ) + }, []) return ( { )} noDeleteButton pathDialogDefaultPath={defaultWinePrefix} + warning={warning} /> ) }