@@ -5,10 +5,8 @@ import {
5
5
postConstruct ,
6
6
} from '@theia/core/shared/inversify' ;
7
7
import { DialogProps } from '@theia/core/lib/browser/dialogs' ;
8
- import { AbstractDialog } from '../../theia/dialogs/dialogs' ;
9
- import { Widget } from '@theia/core/shared/@phosphor/widgets' ;
10
8
import { Message } from '@theia/core/shared/@phosphor/messaging' ;
11
- import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget ' ;
9
+ import { ReactDialog } from '../../theia/dialogs/dialogs ' ;
12
10
import { nls } from '@theia/core' ;
13
11
import { IDEUpdaterComponent , UpdateProgress } from './ide-updater-component' ;
14
12
import {
@@ -22,47 +20,11 @@ import { WindowService } from '@theia/core/lib/browser/window/window-service';
22
20
23
21
const DOWNLOAD_PAGE_URL = 'https://www.arduino.cc/en/software' ;
24
22
25
- @injectable ( )
26
- export class IDEUpdaterDialogWidget extends ReactWidget {
27
- private _updateInfo : UpdateInfo ;
28
- private _updateProgress : UpdateProgress = { } ;
29
-
30
- setUpdateInfo ( updateInfo : UpdateInfo ) : void {
31
- this . _updateInfo = updateInfo ;
32
- this . update ( ) ;
33
- }
34
-
35
- mergeUpdateProgress ( updateProgress : UpdateProgress ) : void {
36
- this . _updateProgress = { ...this . _updateProgress , ...updateProgress } ;
37
- this . update ( ) ;
38
- }
39
-
40
- get updateInfo ( ) : UpdateInfo {
41
- return this . _updateInfo ;
42
- }
43
-
44
- get updateProgress ( ) : UpdateProgress {
45
- return this . _updateProgress ;
46
- }
47
-
48
- protected render ( ) : React . ReactNode {
49
- return ! ! this . _updateInfo ? (
50
- < IDEUpdaterComponent
51
- updateInfo = { this . _updateInfo }
52
- updateProgress = { this . _updateProgress }
53
- />
54
- ) : null ;
55
- }
56
- }
57
-
58
23
@injectable ( )
59
24
export class IDEUpdaterDialogProps extends DialogProps { }
60
25
61
26
@injectable ( )
62
- export class IDEUpdaterDialog extends AbstractDialog < UpdateInfo > {
63
- @inject ( IDEUpdaterDialogWidget )
64
- private readonly widget : IDEUpdaterDialogWidget ;
65
-
27
+ export class IDEUpdaterDialog extends ReactDialog < UpdateInfo | undefined > {
66
28
@inject ( IDEUpdater )
67
29
private readonly updater : IDEUpdater ;
68
30
@@ -75,6 +37,9 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
75
37
@inject ( WindowService )
76
38
private readonly windowService : WindowService ;
77
39
40
+ private _updateInfo : UpdateInfo | undefined ;
41
+ private _updateProgress : UpdateProgress = { } ;
42
+
78
43
constructor (
79
44
@inject ( IDEUpdaterDialogProps )
80
45
protected override readonly props : IDEUpdaterDialogProps
@@ -94,26 +59,34 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
94
59
protected init ( ) : void {
95
60
this . updaterClient . onUpdaterDidFail ( ( error ) => {
96
61
this . appendErrorButtons ( ) ;
97
- this . widget . mergeUpdateProgress ( { error } ) ;
62
+ this . mergeUpdateProgress ( { error } ) ;
98
63
} ) ;
99
64
this . updaterClient . onDownloadProgressDidChange ( ( progressInfo ) => {
100
- this . widget . mergeUpdateProgress ( { progressInfo } ) ;
65
+ this . mergeUpdateProgress ( { progressInfo } ) ;
101
66
} ) ;
102
67
this . updaterClient . onDownloadDidFinish ( ( ) => {
103
68
this . appendInstallButtons ( ) ;
104
- this . widget . mergeUpdateProgress ( { downloadFinished : true } ) ;
69
+ this . mergeUpdateProgress ( { downloadFinished : true } ) ;
105
70
} ) ;
106
71
}
107
72
108
- get value ( ) : UpdateInfo {
109
- return this . widget . updateInfo ;
73
+ protected render ( ) : React . ReactNode {
74
+ return (
75
+ this . updateInfo && (
76
+ < IDEUpdaterComponent
77
+ updateInfo = { this . updateInfo }
78
+ updateProgress = { this . updateProgress }
79
+ />
80
+ )
81
+ ) ;
82
+ }
83
+
84
+ get value ( ) : UpdateInfo | undefined {
85
+ return this . updateInfo ;
110
86
}
111
87
112
88
protected override onAfterAttach ( msg : Message ) : void {
113
- if ( this . widget . isAttached ) {
114
- Widget . detach ( this . widget ) ;
115
- }
116
- Widget . attach ( this . widget , this . contentNode ) ;
89
+ this . update ( ) ;
117
90
this . appendInitialButtons ( ) ;
118
91
super . onAfterAttach ( msg ) ;
119
92
}
@@ -196,15 +169,19 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
196
169
}
197
170
198
171
private skipVersion ( ) : void {
172
+ if ( ! this . updateInfo ) {
173
+ console . warn ( `Nothing to skip. No update info is available` ) ;
174
+ return ;
175
+ }
199
176
this . localStorageService . setData < string > (
200
177
SKIP_IDE_VERSION ,
201
- this . widget . updateInfo . version
178
+ this . updateInfo . version
202
179
) ;
203
180
this . close ( ) ;
204
181
}
205
182
206
183
private startDownload ( ) : void {
207
- this . widget . mergeUpdateProgress ( {
184
+ this . mergeUpdateProgress ( {
208
185
downloadStarted : true ,
209
186
} ) ;
210
187
this . clearButtons ( ) ;
@@ -216,31 +193,48 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
216
193
this . close ( ) ;
217
194
}
218
195
196
+ private set updateInfo ( updateInfo : UpdateInfo | undefined ) {
197
+ this . _updateInfo = updateInfo ;
198
+ this . update ( ) ;
199
+ }
200
+
201
+ private get updateInfo ( ) : UpdateInfo | undefined {
202
+ return this . _updateInfo ;
203
+ }
204
+
205
+ private get updateProgress ( ) : UpdateProgress {
206
+ return this . _updateProgress ;
207
+ }
208
+
209
+ private mergeUpdateProgress ( updateProgress : UpdateProgress ) : void {
210
+ this . _updateProgress = { ...this . _updateProgress , ...updateProgress } ;
211
+ this . update ( ) ;
212
+ }
213
+
219
214
override async open (
220
215
data : UpdateInfo | undefined = undefined
221
216
) : Promise < UpdateInfo | undefined > {
222
217
if ( data && data . version ) {
223
- this . widget . mergeUpdateProgress ( {
218
+ this . mergeUpdateProgress ( {
224
219
progressInfo : undefined ,
225
220
downloadStarted : false ,
226
221
downloadFinished : false ,
227
222
error : undefined ,
228
223
} ) ;
229
- this . widget . setUpdateInfo ( data ) ;
224
+ this . updateInfo = data ;
230
225
return super . open ( ) ;
231
226
}
232
227
}
233
228
234
229
protected override onActivateRequest ( msg : Message ) : void {
235
230
super . onActivateRequest ( msg ) ;
236
- this . widget . activate ( ) ;
231
+ this . update ( ) ;
237
232
}
238
233
239
234
override close ( ) : void {
240
- this . widget . dispose ( ) ;
241
235
if (
242
- this . widget . updateProgress ?. downloadStarted &&
243
- ! this . widget . updateProgress ?. downloadFinished
236
+ this . updateProgress ?. downloadStarted &&
237
+ ! this . updateProgress ?. downloadFinished
244
238
) {
245
239
this . updater . stopDownload ( ) ;
246
240
}
0 commit comments