Skip to content

Commit bdc4a53

Browse files
author
Akos Kitta
committed
better progress report for the index update.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 57fb2e0 commit bdc4a53

File tree

9 files changed

+176
-131
lines changed

9 files changed

+176
-131
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ import { CompilerErrors } from './contributions/compiler-errors';
303303
import { WidgetManager } from './theia/core/widget-manager';
304304
import { WidgetManager as TheiaWidgetManager } from '@theia/core/lib/browser/widget-manager';
305305
import { IndexesUpdateProgress } from './contributions/indexes-update-progress';
306+
import { Daemon } from './contributions/daemon';
306307

307308
MonacoThemingService.register({
308309
id: 'arduino-theme',
@@ -700,6 +701,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
700701
Contribution.configure(bind, Format);
701702
Contribution.configure(bind, CompilerErrors);
702703
Contribution.configure(bind, IndexesUpdateProgress);
704+
Contribution.configure(bind, Daemon);
703705

704706
// Disabled the quick-pick customization from Theia when multiple formatters are available.
705707
// Use the default VS Code behavior, and pick the first one. In the IDE2, clang-format has `exclusive` selectors.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { nls } from '@theia/core';
2+
import { inject, injectable } from '@theia/core/shared/inversify';
3+
import { ArduinoDaemon } from '../../common/protocol';
4+
import { Contribution, Command, CommandRegistry } from './contribution';
5+
6+
@injectable()
7+
export class Daemon extends Contribution {
8+
@inject(ArduinoDaemon)
9+
private readonly daemon: ArduinoDaemon;
10+
11+
override registerCommands(registry: CommandRegistry): void {
12+
registry.registerCommand(Daemon.Commands.START_DAEMON, {
13+
execute: () => this.daemon.start(),
14+
});
15+
registry.registerCommand(Daemon.Commands.STOP_DAEMON, {
16+
execute: () => this.daemon.stop(),
17+
});
18+
registry.registerCommand(Daemon.Commands.RESTART_DAEMON, {
19+
execute: () => this.daemon.restart(),
20+
});
21+
}
22+
}
23+
export namespace Daemon {
24+
export namespace Commands {
25+
export const START_DAEMON: Command = {
26+
id: 'arduino-start-daemon',
27+
label: nls.localize('arduino/daemon/start', 'Start Daemon'),
28+
};
29+
export const STOP_DAEMON: Command = {
30+
id: 'arduino-stop-daemon',
31+
label: nls.localize('arduino/daemon/stop', 'Stop Daemon'),
32+
};
33+
export const RESTART_DAEMON: Command = {
34+
id: 'arduino-restart-daemon',
35+
label: nls.localize('arduino/daemon/restart', 'Restart Daemon'),
36+
};
37+
}
38+
}

arduino-ide-extension/src/browser/contributions/indexes-update-progress.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Progress } from '@theia/core/lib/common/message-service-protocol';
22
import { ProgressService } from '@theia/core/lib/common/progress-service';
33
import { inject, injectable } from '@theia/core/shared/inversify';
4-
import { ProgressMessage } from '../../common/protocol';
4+
import { CoreMessages, ProgressMessage } from '../../common/protocol';
55
import { NotificationCenter } from '../notification-center';
66
import { Contribution } from './contribution';
77

@@ -54,16 +54,13 @@ export class IndexesUpdateProgress extends Contribution {
5454
}
5555
this.currentProgress = undefined;
5656
const progress = await this.progressService.showProgress({
57-
text: 'Arduino',
58-
// TODO: IDE2 could show the progress in `notification`, like the platform/library install and uninstall.
59-
// However, the index update progress responses are not much helpful. They cannot provide a fine-grain progress.
60-
// So IDE2 could report two total works only: index update and library index update.
61-
// See here an example: https://github.com/arduino/arduino-ide/issues/906#issuecomment-1171145630
62-
// Due to this, IDE2 shows a spinner on the status bar.
63-
options: { location: 'window' },
57+
text: '',
58+
options: { location: 'notification' },
6459
});
6560
if (ProgressMessage.is(progressOrId)) {
66-
progress.report(progressOrId); // if the client has missed the `willStart` event, report the progress immediately.
61+
progress.report(progressOrId);
62+
} else {
63+
progress.report({ message: CoreMessages.UpdateIndex });
6764
}
6865
this.currentProgress = { ...progress, progressId };
6966
return this.currentProgress;

arduino-ide-extension/src/common/protocol/arduino-daemon.ts

+3
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ export interface ArduinoDaemon {
1212
* Otherwise resolves to the CLI daemon port.
1313
*/
1414
tryGetPort(): Promise<string | undefined>;
15+
start(): Promise<string>;
16+
stop(): Promise<void>;
17+
restart(): Promise<string>;
1518
}

arduino-ide-extension/src/common/protocol/core-service.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
import { ApplicationError } from '@theia/core';
2-
import { Location } from '@theia/core/shared/vscode-languageserver-protocol';
3-
import { BoardUserField } from '.';
4-
import { Board, Port } from '../../common/protocol/boards-service';
5-
import { ErrorInfo as CliErrorInfo } from '../../node/cli-error-parser';
6-
import { Programmer } from './boards-service';
7-
import { Sketch } from './sketches-service';
1+
import { nls } from '@theia/core/lib/common/nls';
2+
import { ApplicationError } from '@theia/core/lib/common/application-error';
3+
import type { Location } from '@theia/core/shared/vscode-languageserver-protocol';
4+
import type {
5+
Board,
6+
BoardUserField,
7+
Port,
8+
} from '../../common/protocol/boards-service';
9+
import type { ErrorInfo as CliErrorInfo } from '../../node/cli-error-parser';
10+
import type { Programmer } from './boards-service';
11+
import type { Sketch } from './sketches-service';
12+
13+
export namespace CoreMessages {
14+
export const UpdateIndex = nls.localize(
15+
'arduino/coreService/updateIndex',
16+
'Updating indexes'
17+
);
18+
}
819

920
export const CompilerWarningLiterals = [
1021
'None',

arduino-ide-extension/src/node/arduino-daemon-impl.ts

+32-26
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { inject, injectable, named } from '@theia/core/shared/inversify';
44
import { spawn, ChildProcess } from 'child_process';
55
import { FileUri } from '@theia/core/lib/node/file-uri';
66
import { ILogger } from '@theia/core/lib/common/logger';
7-
import { Deferred } from '@theia/core/lib/common/promise-util';
7+
import { Deferred, retry } from '@theia/core/lib/common/promise-util';
88
import {
99
Disposable,
1010
DisposableCollection,
@@ -23,26 +23,26 @@ export class ArduinoDaemonImpl
2323
{
2424
@inject(ILogger)
2525
@named('daemon')
26-
protected readonly logger: ILogger;
26+
private readonly logger: ILogger;
2727

2828
@inject(EnvVariablesServer)
29-
protected readonly envVariablesServer: EnvVariablesServer;
29+
private readonly envVariablesServer: EnvVariablesServer;
3030

3131
@inject(NotificationServiceServer)
32-
protected readonly notificationService: NotificationServiceServer;
32+
private readonly notificationService: NotificationServiceServer;
3333

34-
protected readonly toDispose = new DisposableCollection();
35-
protected readonly onDaemonStartedEmitter = new Emitter<string>();
36-
protected readonly onDaemonStoppedEmitter = new Emitter<void>();
34+
private readonly toDispose = new DisposableCollection();
35+
private readonly onDaemonStartedEmitter = new Emitter<string>();
36+
private readonly onDaemonStoppedEmitter = new Emitter<void>();
3737

38-
protected _running = false;
39-
protected _port = new Deferred<string>();
40-
protected _execPath: string | undefined;
38+
private _running = false;
39+
private _port = new Deferred<string>();
40+
private _execPath: string | undefined;
4141

4242
// Backend application lifecycle.
4343

4444
onStart(): void {
45-
this.startDaemon(); // no await
45+
this.start(); // no await
4646
}
4747

4848
// Daemon API
@@ -58,7 +58,7 @@ export class ArduinoDaemonImpl
5858
return undefined;
5959
}
6060

61-
async startDaemon(): Promise<void> {
61+
async start(): Promise<string> {
6262
try {
6363
this.toDispose.dispose(); // This will `kill` the previously started daemon process, if any.
6464
const cliPath = await this.getExecPath();
@@ -86,24 +86,29 @@ export class ArduinoDaemonImpl
8686
]);
8787
this.fireDaemonStarted(port);
8888
this.onData('Daemon is running.');
89+
return port;
8990
} catch (err) {
90-
this.onData('Failed to start the daemon.');
91-
this.onError(err);
92-
let i = 5; // TODO: make this better
93-
while (i) {
94-
this.onData(`Restarting daemon in ${i} seconds...`);
95-
await new Promise((resolve) => setTimeout(resolve, 1000));
96-
i--;
97-
}
98-
this.onData('Restarting daemon now...');
99-
return this.startDaemon();
91+
return retry(
92+
() => {
93+
this.onError(err);
94+
return this.start();
95+
},
96+
1_000,
97+
5
98+
);
10099
}
101100
}
102101

103-
async stopDaemon(): Promise<void> {
102+
async stop(): Promise<void> {
104103
this.toDispose.dispose();
105104
}
106105

106+
async restart(): Promise<string> {
107+
return this.start();
108+
}
109+
110+
// Backend only daemon API
111+
107112
get onDaemonStarted(): Event<string> {
108113
return this.onDaemonStartedEmitter.event;
109114
}
@@ -275,14 +280,14 @@ export class ArduinoDaemonImpl
275280
return ready.promise;
276281
}
277282

278-
protected fireDaemonStarted(port: string): void {
283+
private fireDaemonStarted(port: string): void {
279284
this._running = true;
280285
this._port.resolve(port);
281286
this.onDaemonStartedEmitter.fire(port);
282287
this.notificationService.notifyDaemonDidStart(port);
283288
}
284289

285-
protected fireDaemonStopped(): void {
290+
private fireDaemonStopped(): void {
286291
if (!this._running) {
287292
return;
288293
}
@@ -297,7 +302,8 @@ export class ArduinoDaemonImpl
297302
this.logger.info(message);
298303
}
299304

300-
protected onError(error: any): void {
305+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
306+
private onError(error: any): void {
301307
this.logger.error(error);
302308
}
303309
}

0 commit comments

Comments
 (0)