Skip to content

workaround: stop discoveries before install/uninstall boards/libs #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions arduino-ide-extension/src/node/board-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,29 @@ export class BoardDiscovery extends CoreClientAware {
this.startBoardListWatch(coreClient);
}

stopBoardListWatch(coreClient: CoreClientProvider.Client): Promise<void> {
return new Promise((resolve, reject) => {
if (!this.boardWatchDuplex) {
return resolve();
}

const { instance } = coreClient;
const req = new BoardListWatchRequest();
req.setInstance(instance);
try {
this.boardWatchDuplex.write(req.setInterrupt(true), resolve);
} catch (e) {
this.discoveryLogger.error(e);
resolve();
}
});
}

startBoardListWatch(coreClient: CoreClientProvider.Client): void {
if (this.watching) {
// We want to avoid starting the board list watch process multiple
// times to meet unforseen consequences
return
return;
}
this.watching = true;
const { client, instance } = coreClient;
Expand All @@ -73,9 +91,19 @@ export class BoardDiscovery extends CoreClientAware {
this.boardWatchDuplex = client.boardListWatch();
this.boardWatchDuplex.on('end', () => {
this.watching = false;
console.info('board watch ended')
})
console.info('board watch ended');
});
this.boardWatchDuplex.on('close', () => {
this.watching = false;
console.info('board watch ended');
});
this.boardWatchDuplex.on('data', (resp: BoardListWatchResponse) => {
if (resp.getEventType() === 'quit') {
this.watching = false;
console.info('board watch ended');
return;
}

const detectedPort = resp.getPort();
if (detectedPort) {
let eventType: 'add' | 'remove' | 'unknown' = 'unknown';
Expand All @@ -96,7 +124,7 @@ export class BoardDiscovery extends CoreClientAware {

const address = (detectedPort as any).getPort().getAddress();
const protocol = (detectedPort as any).getPort().getProtocol();
const label = (detectedPort as any).getPort().getLabel();;
const label = (detectedPort as any).getPort().getLabel();
const port = { address, protocol, label };
const boards: Board[] = [];
for (const item of detectedPort.getMatchingBoardsList()) {
Expand All @@ -111,7 +139,9 @@ export class BoardDiscovery extends CoreClientAware {
if (newState[port.address]) {
const [, knownBoards] = newState[port.address];
console.warn(
`Port '${port.address}' was already available. Known boards before override: ${JSON.stringify(
`Port '${
port.address
}' was already available. Known boards before override: ${JSON.stringify(
knownBoards
)}`
);
Expand Down
36 changes: 23 additions & 13 deletions arduino-ide-extension/src/node/boards-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import { InstallWithProgress } from './grpc-installable';
@injectable()
export class BoardsServiceImpl
extends CoreClientAware
implements BoardsService {
implements BoardsService
{
@inject(ILogger)
protected logger: ILogger;

Expand Down Expand Up @@ -247,7 +248,10 @@ export class BoardsServiceImpl
return boards;
}

async getBoardUserFields(options: { fqbn: string, protocol: string }): Promise<BoardUserField[]> {
async getBoardUserFields(options: {
fqbn: string;
protocol: string;
}): Promise<BoardUserField[]> {
await this.coreClientProvider.initialized;
const coreClient = await this.coreClient();
const { client, instance } = coreClient;
Expand All @@ -257,25 +261,23 @@ export class BoardsServiceImpl
supportedUserFieldsReq.setFqbn(options.fqbn);
supportedUserFieldsReq.setProtocol(options.protocol);

const supportedUserFieldsResp = await new Promise<SupportedUserFieldsResponse>(
(resolve, reject) => {
const supportedUserFieldsResp =
await new Promise<SupportedUserFieldsResponse>((resolve, reject) => {
client.supportedUserFields(supportedUserFieldsReq, (err, resp) => {
(!!err ? reject : resolve)(!!err ? err : resp)
})
}
);
return supportedUserFieldsResp.getUserFieldsList().map(e => {
(!!err ? reject : resolve)(!!err ? err : resp);
});
});
return supportedUserFieldsResp.getUserFieldsList().map((e) => {
return {
toolId: e.getToolId(),
name: e.getName(),
label: e.getLabel(),
secret: e.getSecret(),
value: "",
value: '',
};
});
}


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

console.info('>>> Starting boards package installation...', item);

// stop the board discovery
await this.boardDiscovery.stopBoardListWatch(coreClient);

const resp = client.platformInstall(req);
resp.on(
'data',
Expand All @@ -418,7 +424,7 @@ export class BoardsServiceImpl
);
await new Promise<void>((resolve, reject) => {
resp.on('end', () => {
this.boardDiscovery.startBoardListWatch(coreClient)
this.boardDiscovery.startBoardListWatch(coreClient);
resolve();
});
resp.on('error', (error) => {
Expand Down Expand Up @@ -456,6 +462,10 @@ export class BoardsServiceImpl
req.setPlatformPackage(platform);

console.info('>>> Starting boards package uninstallation...', item);

// stop the board discovery
await this.boardDiscovery.stopBoardListWatch(coreClient);

const resp = client.platformUninstall(req);
resp.on(
'data',
Expand All @@ -466,7 +476,7 @@ export class BoardsServiceImpl
);
await new Promise<void>((resolve, reject) => {
resp.on('end', () => {
this.boardDiscovery.startBoardListWatch(coreClient)
this.boardDiscovery.startBoardListWatch(coreClient);
resolve();
});
resp.on('error', reject);
Expand Down
12 changes: 12 additions & 0 deletions arduino-ide-extension/src/node/library-service-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ export class LibraryServiceImpl
req.setNoDeps(!options.installDependencies);

console.info('>>> Starting library package installation...', item);

// stop the board discovery
await this.boardDiscovery.stopBoardListWatch(coreClient);

const resp = client.libraryInstall(req);
resp.on(
'data',
Expand Down Expand Up @@ -322,6 +326,10 @@ export class LibraryServiceImpl
if (typeof overwrite === 'boolean') {
req.setOverwrite(overwrite);
}

// stop the board discovery
await this.boardDiscovery.stopBoardListWatch(coreClient);

const resp = client.zipLibraryInstall(req);
resp.on(
'data',
Expand Down Expand Up @@ -354,6 +362,10 @@ export class LibraryServiceImpl
req.setVersion(item.installedVersion!);

console.info('>>> Starting library package uninstallation...', item);

// stop the board discovery
await this.boardDiscovery.stopBoardListWatch(coreClient);

const resp = client.libraryUninstall(req);
resp.on(
'data',
Expand Down