1
1
import * as React from '@theia/core/shared/react' ;
2
- import { inject , injectable } from '@theia/core/shared/inversify' ;
2
+ import {
3
+ inject ,
4
+ injectable ,
5
+ postConstruct ,
6
+ } from '@theia/core/shared/inversify' ;
3
7
import { DialogProps } from '@theia/core/lib/browser/dialogs' ;
4
8
import { AbstractDialog } from '../../theia/dialogs/dialogs' ;
5
9
import { Widget } from '@theia/core/shared/@phosphor/widgets' ;
6
10
import { Message } from '@theia/core/shared/@phosphor/messaging' ;
7
11
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget' ;
8
- import { Disposable , nls } from '@theia/core' ;
12
+ import { nls } from '@theia/core' ;
9
13
import { IDEUpdaterComponent , UpdateProgress } from './ide-updater-component' ;
10
14
import {
11
15
IDEUpdater ,
@@ -29,7 +33,7 @@ export class IDEUpdaterDialogWidget extends ReactWidget {
29
33
this . update ( ) ;
30
34
}
31
35
32
- setUpdateProgress ( updateProgress : UpdateProgress ) : void {
36
+ mergeUpdateProgress ( updateProgress : UpdateProgress ) : void {
33
37
this . _updateProgress = { ...this . _updateProgress , ...updateProgress } ;
34
38
this . update ( ) ;
35
39
}
@@ -57,9 +61,6 @@ export class IDEUpdaterDialogProps extends DialogProps {}
57
61
58
62
@injectable ( )
59
63
export class IDEUpdaterDialog extends AbstractDialog < UpdateInfo > {
60
- private onError : Disposable ;
61
- private onDownloadProgressChanged : Disposable ;
62
- onDownloadFinished : Disposable ;
63
64
@inject ( IDEUpdaterDialogWidget )
64
65
private readonly widget : IDEUpdaterDialogWidget ;
65
66
@@ -90,32 +91,19 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
90
91
this . acceptButton = undefined ;
91
92
}
92
93
93
- private init ( ) : void {
94
- this . widget . setUpdateProgress ( {
95
- progressInfo : undefined ,
96
- downloadStarted : false ,
97
- downloadFinished : false ,
98
- error : undefined ,
94
+ @postConstruct ( )
95
+ protected init ( ) : void {
96
+ this . updaterClient . onUpdaterDidFail ( ( error ) => {
97
+ this . appendErrorButtons ( ) ;
98
+ this . widget . mergeUpdateProgress ( { error } ) ;
99
+ } ) ;
100
+ this . updaterClient . onDownloadProgressDidChange ( ( progressInfo ) => {
101
+ this . widget . mergeUpdateProgress ( { progressInfo } ) ;
102
+ } ) ;
103
+ this . updaterClient . onDownloadDidFinish ( ( ) => {
104
+ this . appendInstallButtons ( ) ;
105
+ this . widget . mergeUpdateProgress ( { downloadFinished : true } ) ;
99
106
} ) ;
100
- if ( ! this . onError ) {
101
- this . onError = this . updaterClient . onError ( ( error ) => {
102
- this . appendErrorButtons ( ) ;
103
- this . widget . setUpdateProgress ( { error } ) ;
104
- } ) ;
105
- }
106
- if ( ! this . onDownloadProgressChanged ) {
107
- this . onDownloadProgressChanged =
108
- this . updaterClient . onDownloadProgressChanged ( ( progressInfo ) => {
109
- this . widget . setUpdateProgress ( { progressInfo } ) ;
110
- } ) ;
111
- }
112
- if ( ! this . onDownloadFinished ) {
113
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
114
- this . onDownloadFinished = this . updaterClient . onDownloadFinished ( ( _ ) => {
115
- this . appendInstallButtons ( ) ;
116
- this . widget . setUpdateProgress ( { downloadFinished : true } ) ;
117
- } ) ;
118
- }
119
107
}
120
108
121
109
get value ( ) : UpdateInfo {
@@ -217,7 +205,7 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
217
205
}
218
206
219
207
private startDownload ( ) : void {
220
- this . widget . setUpdateProgress ( {
208
+ this . widget . mergeUpdateProgress ( {
221
209
downloadStarted : true ,
222
210
} ) ;
223
211
this . clearButtons ( ) ;
@@ -233,7 +221,12 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
233
221
data : UpdateInfo | undefined = undefined
234
222
) : Promise < UpdateInfo | undefined > {
235
223
if ( data && data . version ) {
236
- this . init ( ) ;
224
+ this . widget . mergeUpdateProgress ( {
225
+ progressInfo : undefined ,
226
+ downloadStarted : false ,
227
+ downloadFinished : false ,
228
+ error : undefined ,
229
+ } ) ;
237
230
this . widget . setUpdateInfo ( data ) ;
238
231
return super . open ( ) ;
239
232
}
0 commit comments