1
1
import { injectable , inject } from 'inversify' ;
2
2
import { MessageService } from '@theia/core/lib/common/message-service' ;
3
3
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application' ;
4
- import { BoardsService , BoardsPackage } from '../../common/protocol/boards-service' ;
4
+ import { BoardsService , BoardsPackage , Board } from '../../common/protocol/boards-service' ;
5
5
import { BoardsServiceProvider } from './boards-service-provider' ;
6
6
import { BoardsListWidgetFrontendContribution } from './boards-widget-frontend-contribution' ;
7
- import { InstallationProgressDialog } from '../widgets/progress-dialog' ;
8
7
import { BoardsConfig } from './boards-config' ;
8
+ import { Installable } from '../../common/protocol' ;
9
+ import { ResponseServiceImpl } from '../response-service-impl' ;
9
10
10
11
/**
11
12
* Listens on `BoardsConfig.Config` changes, if a board is selected which does not
@@ -23,32 +24,45 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
23
24
@inject ( BoardsServiceProvider )
24
25
protected readonly boardsServiceClient : BoardsServiceProvider ;
25
26
27
+ @inject ( ResponseServiceImpl )
28
+ protected readonly responseService : ResponseServiceImpl ;
29
+
26
30
@inject ( BoardsListWidgetFrontendContribution )
27
31
protected readonly boardsManagerFrontendContribution : BoardsListWidgetFrontendContribution ;
28
32
33
+ // Workaround for https://github.com/eclipse-theia/theia/issues/9349
34
+ protected notifications : Board [ ] = [ ] ;
35
+
29
36
onStart ( ) : void {
30
37
this . boardsServiceClient . onBoardsConfigChanged ( this . ensureCoreExists . bind ( this ) ) ;
31
38
this . ensureCoreExists ( this . boardsServiceClient . boardsConfig ) ;
32
39
}
33
40
34
41
protected ensureCoreExists ( config : BoardsConfig . Config ) : void {
35
42
const { selectedBoard } = config ;
36
- if ( selectedBoard ) {
43
+ if ( selectedBoard && ! this . notifications . find ( board => Board . sameAs ( board , selectedBoard ) ) ) {
44
+ this . notifications . push ( selectedBoard ) ;
37
45
this . boardsService . search ( { } ) . then ( packages => {
38
46
const candidates = packages
39
47
. filter ( pkg => BoardsPackage . contains ( selectedBoard , pkg ) )
40
48
. filter ( ( { installable, installedVersion } ) => installable && ! installedVersion ) ;
41
- for ( const candidate of candidates ) {
49
+ const candidate = candidates [ 0 ] ;
50
+ if ( candidate ) {
42
51
// tslint:disable-next-line:max-line-length
43
52
this . messageService . info ( `The \`"${ candidate . name } "\` core has to be installed for the currently selected \`"${ selectedBoard . name } "\` board. Do you want to install it now?` , 'Install Manually' , 'Yes' ) . then ( async answer => {
53
+ const index = this . notifications . findIndex ( board => Board . sameAs ( board , selectedBoard ) ) ;
54
+ if ( index !== - 1 ) {
55
+ this . notifications . splice ( index , 1 ) ;
56
+ }
44
57
if ( answer === 'Yes' ) {
45
- const dialog = new InstallationProgressDialog ( candidate . name , candidate . availableVersions [ 0 ] ) ;
46
- dialog . open ( ) ;
47
- try {
48
- await this . boardsService . install ( { item : candidate } ) ;
49
- } finally {
50
- dialog . close ( ) ;
51
- }
58
+ await Installable . installWithProgress ( {
59
+ installable : this . boardsService ,
60
+ item : candidate ,
61
+ messageService : this . messageService ,
62
+ responseService : this . responseService ,
63
+ version : candidate . availableVersions [ 0 ]
64
+ } ) ;
65
+ return
52
66
}
53
67
if ( answer ) {
54
68
this . boardsManagerFrontendContribution . openView ( { reveal : true } ) . then ( widget => widget . refresh ( candidate . name . toLocaleLowerCase ( ) ) ) ;
0 commit comments