6
6
InitReq ,
7
7
Configuration ,
8
8
UpdateIndexReq ,
9
- UpdateIndexResp
9
+ UpdateIndexResp ,
10
+ UpdateLibrariesIndexReq ,
11
+ UpdateLibrariesIndexResp
10
12
} from './cli-protocol/commands/commands_pb' ;
11
13
import { WorkspaceServiceExt } from '../browser/workspace-service-ext' ;
12
14
import { FileSystem } from '@theia/filesystem/lib/common' ;
@@ -111,20 +113,34 @@ export class CoreClientProviderImpl implements CoreClientProvider {
111
113
}
112
114
113
115
// in a separate promise, try and update the index
114
- let succeeded = true ;
116
+ let indexUpdateSucceeded = true ;
115
117
for ( let i = 0 ; i < 10 ; i ++ ) {
116
118
try {
117
119
await this . updateIndex ( client , instance ) ;
118
- succeeded = true ;
120
+ indexUpdateSucceeded = true ;
119
121
break ;
120
122
} catch ( e ) {
121
123
this . toolOutputService . publishNewOutput ( "daemon" , `Error while updating index in attempt ${ i } : ${ e } ` ) ;
122
124
}
123
125
}
124
- if ( ! succeeded ) {
126
+ if ( ! indexUpdateSucceeded ) {
125
127
this . toolOutputService . publishNewOutput ( "daemon" , `Was unable to update the index. Please restart to try again.` ) ;
126
128
}
127
129
130
+ let libIndexUpdateSucceeded = true ;
131
+ for ( let i = 0 ; i < 10 ; i ++ ) {
132
+ try {
133
+ await this . updateLibraryIndex ( client , instance ) ;
134
+ libIndexUpdateSucceeded = true ;
135
+ break ;
136
+ } catch ( e ) {
137
+ this . toolOutputService . publishNewOutput ( "daemon" , `Error while updating library index in attempt ${ i } : ${ e } ` ) ;
138
+ }
139
+ }
140
+ if ( ! libIndexUpdateSucceeded ) {
141
+ this . toolOutputService . publishNewOutput ( "daemon" , `Was unable to update the library index. Please restart to try again.` ) ;
142
+ }
143
+
128
144
const result = {
129
145
client,
130
146
instance
@@ -134,6 +150,38 @@ export class CoreClientProviderImpl implements CoreClientProvider {
134
150
return result ;
135
151
}
136
152
153
+ protected async updateLibraryIndex ( client : ArduinoCoreClient , instance : Instance ) : Promise < void > {
154
+ const req = new UpdateLibrariesIndexReq ( ) ;
155
+ req . setInstance ( instance ) ;
156
+ const resp = client . updateLibrariesIndex ( req ) ;
157
+ let file : string | undefined ;
158
+ resp . on ( 'data' , ( data : UpdateLibrariesIndexResp ) => {
159
+ const progress = data . getDownloadProgress ( ) ;
160
+ if ( progress ) {
161
+ if ( ! file && progress . getFile ( ) ) {
162
+ file = `${ progress . getFile ( ) } ` ;
163
+ }
164
+ if ( progress . getCompleted ( ) ) {
165
+ if ( file ) {
166
+ if ( / \s / . test ( file ) ) {
167
+ this . toolOutputService . publishNewOutput ( "daemon" , `${ file } completed.\n` ) ;
168
+ } else {
169
+ this . toolOutputService . publishNewOutput ( "daemon" , `Download of '${ file } ' completed.\n'` ) ;
170
+ }
171
+ } else {
172
+ this . toolOutputService . publishNewOutput ( "daemon" , `The library index has been successfully updated.\n'` ) ;
173
+ }
174
+ file = undefined ;
175
+ }
176
+ }
177
+ } ) ;
178
+ await new Promise < void > ( ( resolve , reject ) => {
179
+ resp . on ( 'error' , reject ) ;
180
+ resp . on ( 'end' , resolve ) ;
181
+ } ) ;
182
+ }
183
+
184
+
137
185
protected async updateIndex ( client : ArduinoCoreClient , instance : Instance ) : Promise < void > {
138
186
const updateReq = new UpdateIndexReq ( ) ;
139
187
updateReq . setInstance ( instance ) ;
@@ -165,4 +213,4 @@ export class CoreClientProviderImpl implements CoreClientProvider {
165
213
} ) ;
166
214
}
167
215
168
- }
216
+ }
0 commit comments