@@ -5,10 +5,8 @@ import {
55 postConstruct ,
66} from '@theia/core/shared/inversify' ;
77import { DialogProps } from '@theia/core/lib/browser/dialogs' ;
8- import { AbstractDialog } from '../../theia/dialogs/dialogs' ;
9- import { Widget } from '@theia/core/shared/@phosphor/widgets' ;
108import { 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 ' ;
1210import { nls } from '@theia/core' ;
1311import { IDEUpdaterComponent , UpdateProgress } from './ide-updater-component' ;
1412import {
@@ -22,47 +20,11 @@ import { WindowService } from '@theia/core/lib/browser/window/window-service';
2220
2321const DOWNLOAD_PAGE_URL = 'https://www.arduino.cc/en/software' ;
2422
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-
5823@injectable ( )
5924export class IDEUpdaterDialogProps extends DialogProps { }
6025
6126@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 > {
6628 @inject ( IDEUpdater )
6729 private readonly updater : IDEUpdater ;
6830
@@ -75,6 +37,9 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
7537 @inject ( WindowService )
7638 private readonly windowService : WindowService ;
7739
40+ private _updateInfo : UpdateInfo | undefined ;
41+ private _updateProgress : UpdateProgress = { } ;
42+
7843 constructor (
7944 @inject ( IDEUpdaterDialogProps )
8045 protected override readonly props : IDEUpdaterDialogProps
@@ -94,26 +59,34 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
9459 protected init ( ) : void {
9560 this . updaterClient . onUpdaterDidFail ( ( error ) => {
9661 this . appendErrorButtons ( ) ;
97- this . widget . mergeUpdateProgress ( { error } ) ;
62+ this . mergeUpdateProgress ( { error } ) ;
9863 } ) ;
9964 this . updaterClient . onDownloadProgressDidChange ( ( progressInfo ) => {
100- this . widget . mergeUpdateProgress ( { progressInfo } ) ;
65+ this . mergeUpdateProgress ( { progressInfo } ) ;
10166 } ) ;
10267 this . updaterClient . onDownloadDidFinish ( ( ) => {
10368 this . appendInstallButtons ( ) ;
104- this . widget . mergeUpdateProgress ( { downloadFinished : true } ) ;
69+ this . mergeUpdateProgress ( { downloadFinished : true } ) ;
10570 } ) ;
10671 }
10772
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 ;
11086 }
11187
11288 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 ( ) ;
11790 this . appendInitialButtons ( ) ;
11891 super . onAfterAttach ( msg ) ;
11992 }
@@ -196,15 +169,19 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
196169 }
197170
198171 private skipVersion ( ) : void {
172+ if ( ! this . updateInfo ) {
173+ console . warn ( `Nothing to skip. No update info is available` ) ;
174+ return ;
175+ }
199176 this . localStorageService . setData < string > (
200177 SKIP_IDE_VERSION ,
201- this . widget . updateInfo . version
178+ this . updateInfo . version
202179 ) ;
203180 this . close ( ) ;
204181 }
205182
206183 private startDownload ( ) : void {
207- this . widget . mergeUpdateProgress ( {
184+ this . mergeUpdateProgress ( {
208185 downloadStarted : true ,
209186 } ) ;
210187 this . clearButtons ( ) ;
@@ -216,31 +193,48 @@ export class IDEUpdaterDialog extends AbstractDialog<UpdateInfo> {
216193 this . close ( ) ;
217194 }
218195
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+
219214 override async open (
220215 data : UpdateInfo | undefined = undefined
221216 ) : Promise < UpdateInfo | undefined > {
222217 if ( data && data . version ) {
223- this . widget . mergeUpdateProgress ( {
218+ this . mergeUpdateProgress ( {
224219 progressInfo : undefined ,
225220 downloadStarted : false ,
226221 downloadFinished : false ,
227222 error : undefined ,
228223 } ) ;
229- this . widget . setUpdateInfo ( data ) ;
224+ this . updateInfo = data ;
230225 return super . open ( ) ;
231226 }
232227 }
233228
234229 protected override onActivateRequest ( msg : Message ) : void {
235230 super . onActivateRequest ( msg ) ;
236- this . widget . activate ( ) ;
231+ this . update ( ) ;
237232 }
238233
239234 override close ( ) : void {
240- this . widget . dispose ( ) ;
241235 if (
242- this . widget . updateProgress ?. downloadStarted &&
243- ! this . widget . updateProgress ?. downloadFinished
236+ this . updateProgress ?. downloadStarted &&
237+ ! this . updateProgress ?. downloadFinished
244238 ) {
245239 this . updater . stopDownload ( ) ;
246240 }
0 commit comments