Skip to content

Commit 21dd5b6

Browse files
committed
fix discoveries
1 parent 49d12d9 commit 21dd5b6

File tree

3 files changed

+69
-18
lines changed

3 files changed

+69
-18
lines changed

Diff for: arduino-ide-extension/src/node/board-discovery.ts

+34-5
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,28 @@ 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+
reject(e);
76+
}
77+
});
78+
}
79+
6380
startBoardListWatch(coreClient: CoreClientProvider.Client): void {
6481
if (this.watching) {
6582
// We want to avoid starting the board list watch process multiple
6683
// times to meet unforseen consequences
67-
return
84+
return;
6885
}
6986
this.watching = true;
7087
const { client, instance } = coreClient;
@@ -73,9 +90,19 @@ export class BoardDiscovery extends CoreClientAware {
7390
this.boardWatchDuplex = client.boardListWatch();
7491
this.boardWatchDuplex.on('end', () => {
7592
this.watching = false;
76-
console.info('board watch ended')
77-
})
93+
console.info('board watch ended');
94+
});
95+
this.boardWatchDuplex.on('close', () => {
96+
this.watching = false;
97+
console.info('board watch ended');
98+
});
7899
this.boardWatchDuplex.on('data', (resp: BoardListWatchResponse) => {
100+
if (resp.getEventType() === 'quit') {
101+
this.watching = false;
102+
console.info('board watch ended');
103+
return;
104+
}
105+
79106
const detectedPort = resp.getPort();
80107
if (detectedPort) {
81108
let eventType: 'add' | 'remove' | 'unknown' = 'unknown';
@@ -96,7 +123,7 @@ export class BoardDiscovery extends CoreClientAware {
96123

97124
const address = (detectedPort as any).getPort().getAddress();
98125
const protocol = (detectedPort as any).getPort().getProtocol();
99-
const label = (detectedPort as any).getPort().getLabel();;
126+
const label = (detectedPort as any).getPort().getLabel();
100127
const port = { address, protocol, label };
101128
const boards: Board[] = [];
102129
for (const item of detectedPort.getMatchingBoardsList()) {
@@ -111,7 +138,9 @@ export class BoardDiscovery extends CoreClientAware {
111138
if (newState[port.address]) {
112139
const [, knownBoards] = newState[port.address];
113140
console.warn(
114-
`Port '${port.address}' was already available. Known boards before override: ${JSON.stringify(
141+
`Port '${
142+
port.address
143+
}' was already available. Known boards before override: ${JSON.stringify(
115144
knownBoards
116145
)}`
117146
);

Diff for: arduino-ide-extension/src/node/boards-service-impl.ts

+23-13
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 = await new Promise<SupportedUserFieldsResponse>(
261-
(resolve, reject) => {
264+
const supportedUserFieldsResp =
265+
await new Promise<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);

Diff for: arduino-ide-extension/src/node/library-service-server-impl.ts

+12
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)