Skip to content

Commit b6306c3

Browse files
Akos Kittajbicker
Akos Kitta
authored andcommitted
Update/download the library_index.json at start
Signed-off-by: Akos Kitta <[email protected]>
1 parent 692c3f6 commit b6306c3

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

arduino-ide-extension/src/node/core-client-provider-impl.ts

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
InitReq,
77
Configuration,
88
UpdateIndexReq,
9-
UpdateIndexResp
9+
UpdateIndexResp,
10+
UpdateLibrariesIndexReq,
11+
UpdateLibrariesIndexResp
1012
} from './cli-protocol/commands/commands_pb';
1113
import { WorkspaceServiceExt } from '../browser/workspace-service-ext';
1214
import { FileSystem } from '@theia/filesystem/lib/common';
@@ -111,20 +113,34 @@ export class CoreClientProviderImpl implements CoreClientProvider {
111113
}
112114

113115
// in a separate promise, try and update the index
114-
let succeeded = true;
116+
let indexUpdateSucceeded = true;
115117
for (let i = 0; i < 10; i++) {
116118
try {
117119
await this.updateIndex(client, instance);
118-
succeeded = true;
120+
indexUpdateSucceeded = true;
119121
break;
120122
} catch (e) {
121123
this.toolOutputService.publishNewOutput("daemon", `Error while updating index in attempt ${i}: ${e}`);
122124
}
123125
}
124-
if (!succeeded) {
126+
if (!indexUpdateSucceeded) {
125127
this.toolOutputService.publishNewOutput("daemon", `Was unable to update the index. Please restart to try again.`);
126128
}
127129

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+
128144
const result = {
129145
client,
130146
instance
@@ -134,6 +150,38 @@ export class CoreClientProviderImpl implements CoreClientProvider {
134150
return result;
135151
}
136152

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+
137185
protected async updateIndex(client: ArduinoCoreClient, instance: Instance): Promise<void> {
138186
const updateReq = new UpdateIndexReq();
139187
updateReq.setInstance(instance);
@@ -165,4 +213,4 @@ export class CoreClientProviderImpl implements CoreClientProvider {
165213
});
166214
}
167215

168-
}
216+
}

0 commit comments

Comments
 (0)