1
1
import { ipcMain } from 'electron'
2
- import { ProgressInfo , State } from 'common/types'
3
2
import {
4
3
installWineVersion ,
5
4
removeWineVersion ,
6
5
updateWineVersionInfos
7
6
} from './utils'
8
7
import { logError , LogPrefix } from '../../logger/logger'
9
8
import { sendFrontendMessage } from '../../main_window'
9
+ import type { WineManagerStatus } from 'common/types'
10
+ import { notify } from '../../dialog/dialog'
11
+ import { t } from 'i18next'
10
12
11
13
ipcMain . handle ( 'installWineVersion' , async ( e , release ) => {
12
- const onProgress = ( state : State , progress ?: ProgressInfo ) => {
13
- sendFrontendMessage ( 'progressOfWineManager' + release . version , {
14
- state,
15
- progress
16
- } )
14
+ const onProgress = ( state : WineManagerStatus ) => {
15
+ sendFrontendMessage ( 'progressOfWineManager' , release . version , state )
17
16
}
17
+
18
+ notify ( { title : release . version , body : t ( 'notify.install.startInstall' ) } )
19
+ onProgress ( {
20
+ status : 'downloading' ,
21
+ percentage : 0 ,
22
+ avgSpeed : 0 ,
23
+ eta : '00:00:00'
24
+ } )
25
+
18
26
const result = await installWineVersion ( release , onProgress )
19
- return result
27
+
28
+ let notifyBody : string | null = null
29
+ switch ( result ) {
30
+ case 'error' :
31
+ notifyBody = t ( 'notify.install.error' )
32
+ break
33
+ case 'abort' :
34
+ notifyBody = t ( 'notify.install.canceled' )
35
+ break
36
+ case 'success' :
37
+ notifyBody = t ( 'notify.install.finished' )
38
+ }
39
+ if ( notifyBody ) notify ( { title : release . version , body : notifyBody } )
40
+ onProgress ( {
41
+ status : 'idle'
42
+ } )
20
43
} )
21
44
22
45
ipcMain . handle ( 'refreshWineVersionInfo' , async ( e , fetch ?) => {
@@ -29,6 +52,7 @@ ipcMain.handle('refreshWineVersionInfo', async (e, fetch?) => {
29
52
}
30
53
} )
31
54
32
- ipcMain . handle ( 'removeWineVersion' , async ( e , release ) =>
33
- removeWineVersion ( release )
34
- )
55
+ ipcMain . handle ( 'removeWineVersion' , async ( e , release ) => {
56
+ const result = await removeWineVersion ( release )
57
+ if ( result ) notify ( { title : release . version , body : t ( 'notify.uninstalled' ) } )
58
+ } )
0 commit comments