Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a8ae0bb

Browse files
authored
workaround: stop discoveries before install/uninstall boards/libs (#674)
1 parent 49d12d9 commit a8ae0bb

File tree

3 files changed

+70
-18
lines changed

3 files changed

+70
-18
lines changed

‎arduino-ide-extension/src/node/board-discovery.ts‎

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,29 @@ export class BoardDiscovery extends CoreClientAware {
6060
this.startBoardListWatch(coreClient);
6161
}
6262

63+
stopBoardListWatch(coreClient: CoreClientProvider.Client): Promise<void> {
64+
return new Promise((resolve, reject) => {
65+
if (!this.boardWatchDuplex) {
66+
return resolve();
67+
}
68+
69+
const { instance } = coreClient;
70+
const req = new BoardListWatchRequest();
71+
req.setInstance(instance);
72+
try {
73+
this.boardWatchDuplex.write(req.setInterrupt(true), resolve);
74+
} catch (e) {
75+
this.discoveryLogger.error(e);
76+
resolve();
77+
}
78+
});
79+
}
80+
6381
startBoardListWatch(coreClient: CoreClientProvider.Client): void {
6482
if (this.watching) {
6583
// We want to avoid starting the board list watch process multiple
6684
// times to meet unforseen consequences
67-
return
85+
return;
6886
}
6987
this.watching = true;
7088
const { client, instance } = coreClient;
@@ -73,9 +91,19 @@ export class BoardDiscovery extends CoreClientAware {
7391
this.boardWatchDuplex = client.boardListWatch();
7492
this.boardWatchDuplex.on('end', () => {
7593
this.watching = false;
76-
console.info('board watch ended')
77-
})
94+
console.info('board watch ended');
95+
});
96+
this.boardWatchDuplex.on('close', () => {
97+
this.watching = false;
98+
console.info('board watch ended');
99+
});
78100
this.boardWatchDuplex.on('data', (resp: BoardListWatchResponse) => {
101+
if (resp.getEventType() === 'quit') {
102+
this.watching = false;
103+
console.info('board watch ended');
104+
return;
105+
}
106+
79107
const detectedPort = resp.getPort();
80108
if (detectedPort) {
81109
let eventType: 'add' | 'remove' | 'unknown' = 'unknown';
@@ -96,7 +124,7 @@ export class BoardDiscovery extends CoreClientAware {
96124

97125
const address = (detectedPort as any).getPort().getAddress();
98126
const protocol = (detectedPort as any).getPort().getProtocol();
99-
const label = (detectedPort as any).getPort().getLabel();;
127+
const label = (detectedPort as any).getPort().getLabel();
100128
const port = { address, protocol, label };
101129
const boards: Board[] = [];
102130
for (const item of detectedPort.getMatchingBoardsList()) {
@@ -111,7 +139,9 @@ export class BoardDiscovery extends CoreClientAware {
111139
if (newState[port.address]) {
112140
const [, knownBoards] = newState[port.address];
113141
console.warn(
114-
`Port '${port.address}' was already available. Known boards before override: ${JSON.stringify(
142+
`Port '${
143+
port.address
144+
}' was already available. Known boards before override: ${JSON.stringify(
115145
knownBoards
116146
)}`
117147
);

‎arduino-ide-extension/src/node/boards-service-impl.ts‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ import { InstallWithProgress } from './grpc-installable';
4545
@injectable()
4646
export class BoardsServiceImpl
4747
extends CoreClientAware
48-
implements BoardsService {
48+
implements BoardsService
49+
{
4950
@inject(ILogger)
5051
protected logger: ILogger;
5152

@@ -247,7 +248,10 @@ export class BoardsServiceImpl
247248
return boards;
248249
}
249250

250-
async getBoardUserFields(options: { fqbn: string, protocol: string }): Promise<BoardUserField[]> {
251+
async getBoardUserFields(options: {
252+
fqbn: string;
253+
protocol: string;
254+
}): Promise<BoardUserField[]> {
251255
await this.coreClientProvider.initialized;
252256
const coreClient = await this.coreClient();
253257
const { client, instance } = coreClient;
@@ -257,25 +261,23 @@ export class BoardsServiceImpl
257261
supportedUserFieldsReq.setFqbn(options.fqbn);
258262
supportedUserFieldsReq.setProtocol(options.protocol);
259263

260-
const supportedUserFieldsResp =awaitnewPromise<SupportedUserFieldsResponse>(
261-
(resolve, reject) => {
264+
const supportedUserFieldsResp =
265+
awaitnewPromise<SupportedUserFieldsResponse>((resolve, reject) => {
262266
client.supportedUserFields(supportedUserFieldsReq, (err, resp) => {
263-
(!!err ? reject : resolve)(!!err ? err : resp)
264-
})
265-
}
266-
);
267-
return supportedUserFieldsResp.getUserFieldsList().map(e => {
267+
(!!err ? reject : resolve)(!!err ? err : resp);
268+
});
269+
});
270+
return supportedUserFieldsResp.getUserFieldsList().map((e) => {
268271
return {
269272
toolId: e.getToolId(),
270273
name: e.getName(),
271274
label: e.getLabel(),
272275
secret: e.getSecret(),
273-
value: "",
276+
value: '',
274277
};
275278
});
276279
}
277280

278-
279281
async search(options: { query?: string }): Promise<BoardsPackage[]> {
280282
await this.coreClientProvider.initialized;
281283
const coreClient = await this.coreClient();
@@ -408,6 +410,10 @@ export class BoardsServiceImpl
408410
req.setVersion(version);
409411

410412
console.info('>>> Starting boards package installation...', item);
413+
414+
// stop the board discovery
415+
await this.boardDiscovery.stopBoardListWatch(coreClient);
416+
411417
const resp = client.platformInstall(req);
412418
resp.on(
413419
'data',
@@ -418,7 +424,7 @@ export class BoardsServiceImpl
418424
);
419425
await new Promise<void>((resolve, reject) => {
420426
resp.on('end', () => {
421-
this.boardDiscovery.startBoardListWatch(coreClient)
427+
this.boardDiscovery.startBoardListWatch(coreClient);
422428
resolve();
423429
});
424430
resp.on('error', (error) => {
@@ -456,6 +462,10 @@ export class BoardsServiceImpl
456462
req.setPlatformPackage(platform);
457463

458464
console.info('>>> Starting boards package uninstallation...', item);
465+
466+
// stop the board discovery
467+
await this.boardDiscovery.stopBoardListWatch(coreClient);
468+
459469
const resp = client.platformUninstall(req);
460470
resp.on(
461471
'data',
@@ -466,7 +476,7 @@ export class BoardsServiceImpl
466476
);
467477
await new Promise<void>((resolve, reject) => {
468478
resp.on('end', () => {
469-
this.boardDiscovery.startBoardListWatch(coreClient)
479+
this.boardDiscovery.startBoardListWatch(coreClient);
470480
resolve();
471481
});
472482
resp.on('error', reject);

‎arduino-ide-extension/src/node/library-service-server-impl.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ export class LibraryServiceImpl
271271
req.setNoDeps(!options.installDependencies);
272272

273273
console.info('>>> Starting library package installation...', item);
274+
275+
// stop the board discovery
276+
await this.boardDiscovery.stopBoardListWatch(coreClient);
277+
274278
const resp = client.libraryInstall(req);
275279
resp.on(
276280
'data',
@@ -322,6 +326,10 @@ export class LibraryServiceImpl
322326
if (typeof overwrite === 'boolean') {
323327
req.setOverwrite(overwrite);
324328
}
329+
330+
// stop the board discovery
331+
await this.boardDiscovery.stopBoardListWatch(coreClient);
332+
325333
const resp = client.zipLibraryInstall(req);
326334
resp.on(
327335
'data',
@@ -354,6 +362,10 @@ export class LibraryServiceImpl
354362
req.setVersion(item.installedVersion!);
355363

356364
console.info('>>> Starting library package uninstallation...', item);
365+
366+
// stop the board discovery
367+
await this.boardDiscovery.stopBoardListWatch(coreClient);
368+
357369
const resp = client.libraryUninstall(req);
358370
resp.on(
359371
'data',

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /