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

[Experimental] Automatic installation of known winetricks fixes #3335

Merged
merged 10 commits into from
Jan 2, 2024
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@
"exit-to-tray": "Exit to System Tray",
"experimental_features": {
"enableHelp": "Help component",
"automaticWinetricksFixes": "Apply known Winetricks fixes automatically",
"enableNewDesign": "New design"
},
"frameless-window": {
Expand Down
9 changes: 8 additions & 1 deletion src/backend/downloadmanager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { notify, showDialogBoxModalAuto } from '../dialog/dialog'
import { isOnline } from '../online_monitor'
import { fixesPath } from 'backend/constants'
import path from 'path'
import { existsSync, mkdirSync } from 'graceful-fs'
import { platform } from 'os'

async function installQueueElement(params: InstallParams): Promise<{
status: DMStatus
Expand Down Expand Up @@ -70,7 +72,9 @@ async function installQueueElement(params: InstallParams): Promise<{
}

try {
downloadFixesFor(appName, runner)
if (platform() !== 'win32') {
downloadFixesFor(appName, runner)
}

const { status, error } = await gameManagerMap[runner].install(appName, {
path: path.replaceAll("'", ''),
Expand Down Expand Up @@ -174,6 +178,9 @@ const runnerToStore = {
async function downloadFixesFor(appName: string, runner: Runner) {
const url = `https://raw.githubusercontent.com/arielj/test-appname-winetricks/main/${appName}-${runnerToStore[runner]}.json`
const dest = path.join(fixesPath, `${appName}-${runnerToStore[runner]}.json`)
if (!existsSync(fixesPath)) {
mkdirSync(fixesPath, { recursive: true })
}
downloadFile({ url, dest })
}

Expand Down
9 changes: 7 additions & 2 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,12 @@ async function prepareWineLaunch(
if (runner === 'legendary') {
await legendarySetup(appName)
}
await installFix(appName, runner)
if (
GlobalConfig.get().getSettings().experimentalFeatures
.automaticWinetricksFixes
) {
await installFixes(appName, runner)
}
}

// If DXVK/VKD3D installation is enabled, install it
Expand Down Expand Up @@ -390,7 +395,7 @@ const runnerToStore = {
nile: 'amazon'
}

async function installFix(appName: string, runner: Runner) {
async function installFixes(appName: string, runner: Runner) {
const fixPath = path.join(
fixesPath,
`${appName}-${runnerToStore[runner]}.json`
Expand Down
1 change: 1 addition & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type Release = {
export type ExperimentalFeatures = {
enableNewDesign: boolean
enableHelp: boolean
automaticWinetricksFixes: boolean
}

export interface AppSettings extends GameSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import useSetting from 'frontend/hooks/useSetting'
import { ToggleSwitch } from 'frontend/components/UI'
import ContextProvider from 'frontend/state/ContextProvider'

const FEATURES = ['enableNewDesign', 'enableHelp']
const FEATURES = ['enableNewDesign', 'enableHelp', 'automaticWinetricksFixes']

const ExperimentalFeatures = () => {
const { t } = useTranslation()
const [experimentalFeatures, setExperimentalFeatures] = useSetting(
'experimentalFeatures',
{ enableNewDesign: false, enableHelp: false }
{
enableNewDesign: false,
enableHelp: false,
automaticWinetricksFixes: false
}
)
const { handleExperimentalFeatures } = useContext(ContextProvider)

Expand All @@ -27,6 +31,7 @@ const ExperimentalFeatures = () => {
Translations:
t('setting.experimental_features.enableNewDesign', 'New design')
t('setting.experimental_features.enableHelp', 'Help component')
t('setting.experimental_features.automaticWinetricksFixes', 'Apply known Winetricks fixes automatically')
*/

return (
Expand Down
6 changes: 5 additions & 1 deletion src/frontend/state/ContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ const initialContext: ContextType = {
addHelpItem: () => null,
removeHelpItem: () => null
},
experimentalFeatures: { enableNewDesign: false, enableHelp: false },
experimentalFeatures: {
enableNewDesign: false,
enableHelp: false,
automaticWinetricksFixes: false
},
handleExperimentalFeatures: () => null
}

Expand Down
3 changes: 2 additions & 1 deletion src/frontend/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ class GlobalState extends PureComponent<Props> {
helpItems: {},
experimentalFeatures: globalSettings?.experimentalFeatures || {
enableNewDesign: false,
enableHelp: false
enableHelp: false,
automaticWinetricksFixes: false
}
}

Expand Down