55 BoardsService ,
66 BoardsPackage ,
77 Board ,
8- Port ,
8+ isBoardIdentifierChangeEvent ,
9+ BoardIdentifier ,
910} from '../../common/protocol/boards-service' ;
1011import { BoardsServiceProvider } from './boards-service-provider' ;
1112import { Installable , ResponseServiceClient } from '../../common/protocol' ;
@@ -24,7 +25,7 @@ interface AutoInstallPromptAction {
2425type AutoInstallPromptActions = AutoInstallPromptAction [ ] ;
2526
2627/**
27- * Listens on `BoardsConfig.Config ` changes, if a board is selected which does not
28+ * Listens on `BoardList ` changes, if a board is selected which does not
2829 * have the corresponding core installed, it proposes the user to install the core.
2930 */
3031
@@ -44,7 +45,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
4445 protected readonly boardsService : BoardsService ;
4546
4647 @inject ( BoardsServiceProvider )
47- protected readonly boardsServiceClient : BoardsServiceProvider ;
48+ protected readonly boardsServiceProvider : BoardsServiceProvider ;
4849
4950 @inject ( ResponseServiceClient )
5051 protected readonly responseService : ResponseServiceClient ;
@@ -53,34 +54,28 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
5354 protected readonly boardsManagerFrontendContribution : BoardsListWidgetFrontendContribution ;
5455
5556 // Workaround for https://github.com/eclipse-theia/theia/issues/9349
56- protected notifications : Board [ ] = [ ] ;
57+ protected notifications : BoardIdentifier [ ] = [ ] ;
5758
5859 // * "refusal" meaning a "prompt action" not accepting the auto-install offer ("X" or "install manually")
5960 // we can use "portSelectedOnLastRefusal" to deduce when a board is unplugged after a user has "refused"
6061 // an auto-install prompt. Important to know as we do not want "an unplug" to trigger a "refused" prompt
6162 // showing again
62- private portSelectedOnLastRefusal : Port | undefined ;
63+ // private portSelectedOnLastRefusal: PortIdentifier | undefined;
6364 private lastRefusedPackageId : string | undefined ;
6465
6566 onStart ( ) : void {
6667 const setEventListeners = ( ) => {
67- this . boardsServiceClient . onBoardsConfigChanged ( ( config ) => {
68- const { selectedBoard, selectedPort } = config ;
69-
70- const boardWasUnplugged =
71- ! selectedPort && this . portSelectedOnLastRefusal ;
72-
73- this . clearLastRefusedPromptInfo ( ) ;
74-
75- if (
76- boardWasUnplugged ||
77- ! selectedBoard ||
78- this . promptAlreadyShowingForBoard ( selectedBoard )
79- ) {
68+ this . boardsServiceProvider . onBoardsConfigDidChange ( ( config ) => {
69+ if ( ! isBoardIdentifierChangeEvent ( config ) ) {
70+ return ;
71+ }
72+ const { selectedBoard } = config ;
73+ const fqbn = selectedBoard ?. fqbn ;
74+ if ( ! fqbn ) {
8075 return ;
8176 }
8277
83- this . ensureCoreExists ( selectedBoard , selectedPort ) ;
78+ this . ensureCoreExists ( selectedBoard ) ;
8479 } ) ;
8580
8681 // we "clearRefusedPackageInfo" if a "refused" package is eventually
@@ -94,23 +89,16 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
9489 } ) ;
9590 } ;
9691
97- // we should invoke this.ensureCoreExists only once we're sure
98- // everything has been reconciled
99- this . boardsServiceClient . reconciled . then ( ( ) => {
100- const { selectedBoard, selectedPort } =
101- this . boardsServiceClient . boardsConfig ;
102-
103- if ( selectedBoard ) {
104- this . ensureCoreExists ( selectedBoard , selectedPort ) ;
105- }
106-
107- setEventListeners ( ) ;
108- } ) ;
92+ setEventListeners ( ) ; // TODO: after onDidStart
93+ // });
10994 }
11095
111- private removeNotificationByBoard ( selectedBoard : Board ) : void {
96+ private removeNotificationByBoard ( selectedBoard : BoardIdentifier ) : void {
11297 const index = this . notifications . findIndex ( ( notification ) =>
113- Board . sameAs ( notification , selectedBoard )
98+ Board . sameAs (
99+ { name : notification . name , fqbn : notification . fqbn } ,
100+ selectedBoard
101+ )
114102 ) ;
115103 if ( index !== - 1 ) {
116104 this . notifications . splice ( index , 1 ) ;
@@ -119,32 +107,15 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
119107
120108 private clearLastRefusedPromptInfo ( ) : void {
121109 this . lastRefusedPackageId = undefined ;
122- this . portSelectedOnLastRefusal = undefined ;
123- }
124-
125- private setLastRefusedPromptInfo (
126- packageId : string ,
127- selectedPort ?: Port
128- ) : void {
129- this . lastRefusedPackageId = packageId ;
130- this . portSelectedOnLastRefusal = selectedPort ;
131- }
132-
133- private promptAlreadyShowingForBoard ( board : Board ) : boolean {
134- return Boolean (
135- this . notifications . find ( ( notification ) =>
136- Board . sameAs ( notification , board )
137- )
138- ) ;
139110 }
140111
141- protected ensureCoreExists ( selectedBoard : Board , selectedPort ?: Port ) : void {
112+ protected ensureCoreExists ( selectedBoard : BoardIdentifier ) : void {
142113 this . notifications . push ( selectedBoard ) ;
143114 this . boardsService . search ( { } ) . then ( ( packages ) => {
144115 const candidate = this . getInstallCandidate ( packages , selectedBoard ) ;
145116
146117 if ( candidate ) {
147- this . showAutoInstallPrompt ( candidate , selectedBoard , selectedPort ) ;
118+ this . showAutoInstallPrompt ( candidate , selectedBoard ) ;
148119 } else {
149120 this . removeNotificationByBoard ( selectedBoard ) ;
150121 }
@@ -182,8 +153,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
182153
183154 private showAutoInstallPrompt (
184155 candidate : BoardsPackage ,
185- selectedBoard : Board ,
186- selectedPort ?: Port
156+ selectedBoard : BoardIdentifier
187157 ) : void {
188158 const candidateName = candidate . name ;
189159 const version = candidate . availableVersions [ 0 ]
@@ -199,7 +169,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
199169 const actions = this . createPromptActions ( candidate ) ;
200170
201171 const onRefuse = ( ) => {
202- this . setLastRefusedPromptInfo ( candidate . id , selectedPort ) ;
172+ // this.setLastRefusedPromptInfo(candidate.id, selectedPort); TODO: probably noop but let's revisit it.
203173 } ;
204174 const handleAction = this . createOnAnswerHandler ( actions , onRefuse ) ;
205175
0 commit comments