@@ -205,39 +205,88 @@ export const Winetricks = {
205205 logWarning ( 'Error Downloading Winetricks' , LogPrefix . Backend )
206206 } )
207207 } ,
208- run : async ( wineVersion : WineInstallation , baseWinePrefix : string ) => {
209- const winetricks = `${ heroicToolsPath } /winetricks`
208+ run : async (
209+ wineVersion : WineInstallation ,
210+ baseWinePrefix : string ,
211+ event : Electron . IpcMainInvokeEvent
212+ ) => {
213+ return new Promise < void > ( ( resolve ) => {
214+ const winetricks = `${ heroicToolsPath } /winetricks`
210215
211- const { winePrefix, wineBin } = getWineFromProton (
212- wineVersion ,
213- baseWinePrefix
214- )
216+ const { winePrefix, wineBin } = getWineFromProton (
217+ wineVersion ,
218+ baseWinePrefix
219+ )
215220
216- const winepath = dirname ( wineBin )
221+ const winepath = dirname ( wineBin )
217222
218- const envs = {
219- ...process . env ,
220- WINEPREFIX : winePrefix ,
221- PATH : `${ winepath } :${ process . env . PATH } `
222- }
223+ const envs = {
224+ ...process . env ,
225+ WINEPREFIX : winePrefix ,
226+ PATH : `${ winepath } :${ process . env . PATH } `
227+ }
223228
224- logInfo (
225- `Running WINEPREFIX='${ winePrefix } ' PATH='${ winepath } ':$PATH ${ winetricks } -q` ,
226- LogPrefix . WineTricks
227- )
229+ const executeMessages = [ ] as string [ ]
230+ let progressUpdated = false
231+ const appendMessage = ( message : string ) => {
232+ // Don't store more than 100 messages, to not
233+ // fill the storage and make render still fast
234+ if ( executeMessages . length > 100 ) {
235+ executeMessages . shift ( )
236+ }
237+ executeMessages . push ( message )
238+ progressUpdated = true
239+ }
240+ const sendProgress = setInterval ( ( ) => {
241+ if ( progressUpdated ) {
242+ event . sender . send ( 'progressOfWinetricks' , executeMessages )
243+ progressUpdated = false
244+ }
245+ } , 1000 )
246+
247+ logInfo (
248+ `Running WINEPREFIX='${ winePrefix } ' PATH='${ winepath } ':$PATH ${ winetricks } -q` ,
249+ LogPrefix . WineTricks
250+ )
228251
229- const child = spawn ( winetricks , [ '-q' ] , { env : envs } )
252+ const child = spawn ( winetricks , [ '-q' ] , { env : envs } )
230253
231- child . stdout . on ( 'data' , ( data : Buffer ) => {
232- logInfo ( data . toString ( ) , LogPrefix . WineTricks )
233- } )
254+ child . stdout . setEncoding ( 'utf8' )
255+ child . stdout . on ( 'data' , ( data : string ) => {
256+ logInfo ( data , LogPrefix . WineTricks )
257+ appendMessage ( data )
258+ } )
234259
235- child . stderr . on ( 'data' , ( data : Buffer ) => {
236- logError ( data . toString ( ) , LogPrefix . WineTricks )
237- } )
260+ child . stderr . setEncoding ( 'utf8' )
261+ child . stderr . on ( 'data' , ( data : string ) => {
262+ logError ( data , LogPrefix . WineTricks )
263+ appendMessage ( data )
264+ } )
238265
239- child . on ( 'error' , ( error ) => {
240- logError ( `Winetricks throwed Error: ${ error } ` , LogPrefix . WineTricks )
266+ child . on ( 'error' , ( error ) => {
267+ logError ( `Winetricks threw Error: ${ error } ` , LogPrefix . WineTricks )
268+ showErrorBoxModalAuto (
269+ i18next . t ( 'box.error.winetricks.title' , 'Winetricks error' ) ,
270+ i18next . t ( 'box.error.winetricks.message' , {
271+ defaultValue :
272+ 'Winetricks returned the following error during execution:{{newLine}}{{error}}' ,
273+ newLine : '\n' ,
274+ error : `${ error } `
275+ } )
276+ )
277+ clearInterval ( sendProgress )
278+ resolve ( )
279+ } )
280+
281+ child . on ( 'exit' , ( ) => {
282+ clearInterval ( sendProgress )
283+ resolve ( )
284+ } )
285+
286+ child . on ( 'close' , ( ) => {
287+ clearInterval ( sendProgress )
288+ resolve ( )
289+ } )
241290 } )
242291 }
243292}
0 commit comments