Skip to content

Commit a4d71c7

Browse files
author
Akos Kitta
committed
can start stop/daemon.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 8daf0ab commit a4d71c7

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

arduino-ide-extension/src/browser/contributions/daemon.ts

+3
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ export namespace Daemon {
2525
export const START_DAEMON: Command = {
2626
id: 'arduino-start-daemon',
2727
label: nls.localize('arduino/daemon/start', 'Start Daemon'),
28+
category: 'Arduino',
2829
};
2930
export const STOP_DAEMON: Command = {
3031
id: 'arduino-stop-daemon',
3132
label: nls.localize('arduino/daemon/stop', 'Stop Daemon'),
33+
category: 'Arduino',
3234
};
3335
export const RESTART_DAEMON: Command = {
3436
id: 'arduino-restart-daemon',
3537
label: nls.localize('arduino/daemon/restart', 'Restart Daemon'),
38+
category: 'Arduino',
3639
};
3740
}
3841
}

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

+14-8
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@ export class CoreClientProvider {
5151

5252
@postConstruct()
5353
protected init(): void {
54-
this.daemon.getPort().then((port) => this.create(port));
55-
this.daemon.onDaemonStopped(() => {
56-
// TODO
54+
this.daemon.tryGetPort().then((port) => {
55+
if (port) {
56+
this.create(port);
57+
}
5758
});
59+
this.daemon.onDaemonStarted((port) => this.create(port));
60+
this.daemon.onDaemonStopped(() => this.closeClient());
5861
this.configService.onConfigChange(async () => {
5962
const port = await this.daemon.getPort();
60-
this.create(port, 10); // Due to a config change, run the indexes update immediately.
63+
this.create(port, 10); // Due to a config change, run the indexes update "immediately".
6164
});
6265
}
6366

@@ -90,7 +93,7 @@ export class CoreClientProvider {
9093
port: string,
9194
indexesUpdateDelay = 10_000
9295
): Promise<CoreClientProvider.Client> {
93-
this.toDisposeBeforeCreate.dispose();
96+
this.closeClient();
9497
const address = this.address(port);
9598
const client = await this.createClient(address);
9699
this.toDisposeBeforeCreate.pushAll([
@@ -129,15 +132,18 @@ export class CoreClientProvider {
129132
}
130133
}
131134

132-
private async useClient(
135+
private useClient(
133136
client: CoreClientProvider.Client
134-
): Promise<CoreClientProvider.Client> {
135-
// TODO: why async? -> for local testing and `wait`
137+
): CoreClientProvider.Client {
136138
this._client = client;
137139
this.onClientReadyEmitter.fire(this._client);
138140
return this._client;
139141
}
140142

143+
private closeClient(): void {
144+
return this.toDisposeBeforeCreate.dispose();
145+
}
146+
141147
private async createClient(
142148
address: string
143149
): Promise<CoreClientProvider.Client> {

0 commit comments

Comments
 (0)