Skip to content

Commit

Permalink
[UX] Built in widget to install components and fonts from Winetricks (#…
Browse files Browse the repository at this point in the history
…3102)

* Add a widget to install components and fonts with winetricks witout its GUI

* Add i18n and some comment

* Small refactor and more comments

* Remove SearchBar import/export

* Move function to tools instead of importing from main

* Move ipc handlers into its own module to fix specs

* Built-in Winetricks: show component in progress
  • Loading branch information
arielj authored Oct 18, 2023
1 parent 5c9d03e commit 69407be
Show file tree
Hide file tree
Showing 15 changed files with 649 additions and 213 deletions.
9 changes: 9 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -720,5 +720,14 @@
},
"release": "Release Date",
"size": "Size"
},
"winetricks": {
"install": "Install",
"installed": "Installed components:",
"installing": "Installation in progress: {{component}}",
"loading": "Loading",
"nothingYet": "Nothing was installed by Winetricks yet",
"openGUI": "Open Winetricks GUI",
"search": "Search fonts or components"
}
}
36 changes: 34 additions & 2 deletions src/backend/api/wine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
ToolArgs,
WineVersionInfo,
ProgressInfo,
State
State,
Runner
} from 'common/types'

export const toggleDXVK = async (args: ToolArgs) =>
Expand Down Expand Up @@ -35,7 +36,10 @@ export const refreshWineVersionInfo = async (fetch?: boolean): Promise<void> =>
ipcRenderer.invoke('refreshWineVersionInfo', fetch)

export const handleProgressOfWinetricks = (
onProgress: (e: Electron.IpcRendererEvent, messages: string[]) => void
onProgress: (
e: Electron.IpcRendererEvent,
payload: { messages: string[]; installingComponent: '' }
) => void
): (() => void) => {
ipcRenderer.on('progressOfWinetricks', onProgress)
return () => {
Expand Down Expand Up @@ -67,3 +71,31 @@ export const handleWineVersionsUpdated = (
ipcRenderer.removeListener('wineVersionsUpdated', callback)
}
}

export const winetricksListInstalled = async (
runner: Runner,
appName: string
): Promise<string[]> =>
ipcRenderer.invoke('winetricksInstalled', { runner, appName })

export const winetricksListAvailable = async (
runner: Runner,
appName: string
): Promise<string[]> =>
ipcRenderer.invoke('winetricksAvailable', { runner, appName })

export const winetricksInstall = async (
runner: Runner,
appName: string,
component: string
): Promise<void> =>
ipcRenderer.send('winetricksInstall', { runner, appName, component })

export const handleWinetricksInstalling = (
callback: (e: Electron.IpcRendererEvent, component: string) => void
): (() => void) => {
ipcRenderer.on('installing-winetricks-component', callback)
return () => {
ipcRenderer.removeListener('installing-winetricks-component', callback)
}
}
76 changes: 2 additions & 74 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
DiskSpaceData,
StatusPromise,
GamepadInputEvent,
WineCommandArgs,
ExecResult,
Runner
} from 'common/types'
import * as path from 'path'
Expand Down Expand Up @@ -51,7 +49,6 @@ import { GOGUser } from './storeManagers/gog/user'
import { NileUser } from './storeManagers/nile/user'
import {
clearCache,
execAsync,
isEpicServiceOffline,
handleExit,
openUrlOrFile,
Expand Down Expand Up @@ -109,7 +106,7 @@ import {
} from './logger/logger'
import { gameInfoStore } from 'backend/storeManagers/legendary/electronStores'
import { getFonts } from 'font-list'
import { prepareWineLaunch, runWineCommand } from './launcher'
import { runWineCommand } from './launcher'
import shlex from 'shlex'
import { initQueue } from './downloadmanager/downloadqueue'
import {
Expand Down Expand Up @@ -595,60 +592,6 @@ ipcMain.on('removeFolder', async (e, [path, folderName]) => {
removeFolder(path, folderName)
})

async function runWineCommandOnGame(
runner: Runner,
appName: string,
{ commandParts, wait = false, protonVerb, startFolder }: WineCommandArgs
): Promise<ExecResult> {
if (gameManagerMap[runner].isNative(appName)) {
logError('runWineCommand called on native game!', LogPrefix.Gog)
return { stdout: '', stderr: '' }
}
const { folder_name, install } = gameManagerMap[runner].getGameInfo(appName)
const gameSettings = await gameManagerMap[runner].getSettings(appName)

await prepareWineLaunch(runner, appName)

return runWineCommand({
gameSettings,
installFolderName: folder_name,
gameInstallPath: install.install_path,
commandParts,
wait,
protonVerb,
startFolder
})
}

// Calls WineCFG or Winetricks. If is WineCFG, use the same binary as wine to launch it to dont update the prefix
ipcMain.handle('callTool', async (event, { tool, exe, appName, runner }) => {
const gameSettings = await gameManagerMap[runner].getSettings(appName)

switch (tool) {
case 'winetricks':
await Winetricks.run(runner, appName, event)
break
case 'winecfg':
await runWineCommandOnGame(runner, appName, {
gameSettings,
commandParts: ['winecfg'],
wait: false
})
break
case 'runExe':
if (exe) {
const workingDir = path.parse(exe).dir
await runWineCommandOnGame(runner, appName, {
gameSettings,
commandParts: [exe],
wait: false,
startFolder: workingDir
})
}
break
}
})

ipcMain.handle('runWineCommand', async (e, args) => runWineCommand(args))

/// IPC handlers begin here.
Expand Down Expand Up @@ -1588,22 +1531,6 @@ ipcMain.handle('getFonts', async (event, reload) => {
return cachedFonts
})

ipcMain.handle(
'runWineCommandForGame',
async (event, { appName, commandParts, runner }) => {
if (isWindows) {
return execAsync(commandParts.join(' '))
}

// FIXME: Why are we using `runinprefix` here?
return runWineCommandOnGame(runner, appName, {
commandParts,
wait: false,
protonVerb: 'runinprefix'
})
}
)

ipcMain.handle('getShellPath', async (event, path) => getShellPath(path))

ipcMain.handle('clipboardReadText', () => clipboard.readText())
Expand Down Expand Up @@ -1712,3 +1639,4 @@ import './downloadmanager/ipc_handler'
import './utils/ipc_handler'
import './wiki_game_info/ipc_handler'
import './recent_games/ipc_handler'
import './tools/ipc_handler'
Loading

0 comments on commit 69407be

Please sign in to comment.