5
5
BoardsService ,
6
6
BoardsPackage ,
7
7
Board ,
8
- Port ,
8
+ isBoardIdentifierChangeEvent ,
9
+ BoardIdentifier ,
9
10
} from '../../common/protocol/boards-service' ;
10
11
import { BoardsServiceProvider } from './boards-service-provider' ;
11
12
import { Installable , ResponseServiceClient } from '../../common/protocol' ;
@@ -24,7 +25,7 @@ interface AutoInstallPromptAction {
24
25
type AutoInstallPromptActions = AutoInstallPromptAction [ ] ;
25
26
26
27
/**
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
28
29
* have the corresponding core installed, it proposes the user to install the core.
29
30
*/
30
31
@@ -44,7 +45,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
44
45
protected readonly boardsService : BoardsService ;
45
46
46
47
@inject ( BoardsServiceProvider )
47
- protected readonly boardsServiceClient : BoardsServiceProvider ;
48
+ protected readonly boardsServiceProvider : BoardsServiceProvider ;
48
49
49
50
@inject ( ResponseServiceClient )
50
51
protected readonly responseService : ResponseServiceClient ;
@@ -53,34 +54,28 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
53
54
protected readonly boardsManagerFrontendContribution : BoardsListWidgetFrontendContribution ;
54
55
55
56
// Workaround for https://github.com/eclipse-theia/theia/issues/9349
56
- protected notifications : Board [ ] = [ ] ;
57
+ protected notifications : BoardIdentifier [ ] = [ ] ;
57
58
58
59
// * "refusal" meaning a "prompt action" not accepting the auto-install offer ("X" or "install manually")
59
60
// we can use "portSelectedOnLastRefusal" to deduce when a board is unplugged after a user has "refused"
60
61
// an auto-install prompt. Important to know as we do not want "an unplug" to trigger a "refused" prompt
61
62
// showing again
62
- private portSelectedOnLastRefusal : Port | undefined ;
63
+ // private portSelectedOnLastRefusal: PortIdentifier | undefined;
63
64
private lastRefusedPackageId : string | undefined ;
64
65
65
66
onStart ( ) : void {
66
67
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 ) {
80
75
return ;
81
76
}
82
77
83
- this . ensureCoreExists ( selectedBoard , selectedPort ) ;
78
+ this . ensureCoreExists ( selectedBoard ) ;
84
79
} ) ;
85
80
86
81
// we "clearRefusedPackageInfo" if a "refused" package is eventually
@@ -94,23 +89,16 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
94
89
} ) ;
95
90
} ;
96
91
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
+ // });
109
94
}
110
95
111
- private removeNotificationByBoard ( selectedBoard : Board ) : void {
96
+ private removeNotificationByBoard ( selectedBoard : BoardIdentifier ) : void {
112
97
const index = this . notifications . findIndex ( ( notification ) =>
113
- Board . sameAs ( notification , selectedBoard )
98
+ Board . sameAs (
99
+ { name : notification . name , fqbn : notification . fqbn } ,
100
+ selectedBoard
101
+ )
114
102
) ;
115
103
if ( index !== - 1 ) {
116
104
this . notifications . splice ( index , 1 ) ;
@@ -119,32 +107,15 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
119
107
120
108
private clearLastRefusedPromptInfo ( ) : void {
121
109
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
- ) ;
139
110
}
140
111
141
- protected ensureCoreExists ( selectedBoard : Board , selectedPort ?: Port ) : void {
112
+ protected ensureCoreExists ( selectedBoard : BoardIdentifier ) : void {
142
113
this . notifications . push ( selectedBoard ) ;
143
114
this . boardsService . search ( { } ) . then ( ( packages ) => {
144
115
const candidate = this . getInstallCandidate ( packages , selectedBoard ) ;
145
116
146
117
if ( candidate ) {
147
- this . showAutoInstallPrompt ( candidate , selectedBoard , selectedPort ) ;
118
+ this . showAutoInstallPrompt ( candidate , selectedBoard ) ;
148
119
} else {
149
120
this . removeNotificationByBoard ( selectedBoard ) ;
150
121
}
@@ -182,8 +153,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
182
153
183
154
private showAutoInstallPrompt (
184
155
candidate : BoardsPackage ,
185
- selectedBoard : Board ,
186
- selectedPort ?: Port
156
+ selectedBoard : BoardIdentifier
187
157
) : void {
188
158
const candidateName = candidate . name ;
189
159
const version = candidate . availableVersions [ 0 ]
@@ -199,7 +169,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
199
169
const actions = this . createPromptActions ( candidate ) ;
200
170
201
171
const onRefuse = ( ) => {
202
- this . setLastRefusedPromptInfo ( candidate . id , selectedPort ) ;
172
+ // this.setLastRefusedPromptInfo(candidate.id, selectedPort); TODO: probably noop but let's revisit it.
203
173
} ;
204
174
const handleAction = this . createOnAnswerHandler ( actions , onRefuse ) ;
205
175
0 commit comments