Skip to content

Commit

Permalink
Built-in Winetricks: show component in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
arielj committed Oct 8, 2023
1 parent 1a096d6 commit 920dc99
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
2 changes: 1 addition & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@
"winetricks": {
"install": "Install",
"installed": "Installed components:",
"installing": "Installation in progress",
"installing": "Installation in progress: {{component}}",
"loading": "Loading",
"nothingYet": "Nothing was installed by Winetricks yet",
"openGUI": "Open Winetricks GUI",
Expand Down
5 changes: 4 additions & 1 deletion src/backend/api/wine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,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
21 changes: 19 additions & 2 deletions src/backend/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ export const DXVK = {
}
}

let installingComponent = ''
export const Winetricks = {
download: async () => {
if (isWindows) {
Expand Down Expand Up @@ -491,7 +492,10 @@ export const Winetricks = {
}
const sendProgress = setInterval(() => {
if (progressUpdated) {
sendFrontendMessage('progressOfWinetricks', executeMessages)
sendFrontendMessage('progressOfWinetricks', {
messages: executeMessages,
installingComponent
})
progressUpdated = false
}
}, 1000)
Expand Down Expand Up @@ -558,7 +562,10 @@ export const Winetricks = {
})

child.on('exit', () => {
sendFrontendMessage('progressOfWinetricks', ['Done'])
sendFrontendMessage('progressOfWinetricks', {
messages: ['Done'],
installingComponent
})
clearInterval(sendProgress)
resolve(returnOutput ? output : null)
})
Expand Down Expand Up @@ -630,6 +637,16 @@ export const Winetricks = {
} catch {
return []
}
},
install: async (runner: Runner, appName: string, component: string) => {
sendFrontendMessage('installing-winetricks-component', component)
try {
installingComponent = component
await Winetricks.runWithArgs(runner, appName, ['-q', component])
} finally {
installingComponent = ''
sendFrontendMessage('installing-winetricks-component', '')
}
}
}

Expand Down
13 changes: 2 additions & 11 deletions src/backend/tools/ipc_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { gameManagerMap } from 'backend/storeManagers'
import { ipcMain } from 'electron'
import { Winetricks, runWineCommandOnGame } from '.'
import path from 'path'
import { sendFrontendMessage } from 'backend/main_window'
import { isWindows } from 'backend/constants'
import { execAsync } from 'backend/utils'

Expand Down Expand Up @@ -51,16 +50,8 @@ ipcMain.handle('callTool', async (event, { tool, exe, appName, runner }) => {
}
})

ipcMain.on(
'winetricksInstall',
async (event, { runner, appName, component }) => {
sendFrontendMessage('installing-winetricks-component', component)
try {
await Winetricks.runWithArgs(runner, appName, ['-q', component])
} finally {
sendFrontendMessage('installing-winetricks-component', '')
}
}
ipcMain.on('winetricksInstall', async (event, { runner, appName, component }) =>
Winetricks.install(runner, appName, component)
)

ipcMain.handle('winetricksAvailable', async (event, { runner, appName }) => {
Expand Down
22 changes: 15 additions & 7 deletions src/frontend/components/UI/Winetricks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function Winetricks({ onClose }: Props) {

// handles the installation of components
const [installing, setInstalling] = useState(false)
const [installingComponent, setInstallingComponent] = useState('')
const [logs, setLogs] = useState<string[]>([])
function install(component: string) {
window.api.winetricksInstall(runner, appName, component)
Expand All @@ -70,16 +71,17 @@ export default function Winetricks({ onClose }: Props) {

async function onWinetricksProgress(
e: Electron.IpcRendererEvent,
newLogs: string[]
payload: { messages: string[]; installingComponent: string }
) {
// this conditionals help to show the correct state if the dialog
// is closed during an installation and then re-opened
if (newLogs[0] && newLogs[0] === 'Done') {
setInstalling(false)
} else if (!installing) {
setInstalling(true)
if (payload.installingComponent.length) {
setInstalling(payload.messages[0] !== 'Done')
}
setLogs((currentLogs) => [...currentLogs, ...newLogs])
if (installingComponent !== payload.installingComponent) {
setInstallingComponent(payload.installingComponent)
}
setLogs((currentLogs) => [...currentLogs, ...payload.messages])
}

const removeListener1 =
Expand Down Expand Up @@ -123,7 +125,13 @@ export default function Winetricks({ onClose }: Props) {
</div>
)}
{installing && (
<p>{t('winetricks.installing', 'Installation in progress')}</p>
<p>
{t(
'winetricks.installing',
'Installation in progress: {{component}}',
{ component: installingComponent }
)}
</p>
)}
</div>
)}
Expand Down

0 comments on commit 920dc99

Please sign in to comment.