-
-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy patharduino-daemon-client-impl.ts
53 lines (42 loc) · 1.49 KB
/
arduino-daemon-client-impl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { injectable, inject } from 'inversify';
import { ILogger } from '@theia/core/lib/common/logger';
import { Event, Emitter } from '@theia/core/lib/common/event';
import { MessageService } from '@theia/core/lib/common/message-service';
import { ArduinoDaemonClient } from '../common/protocol';
@injectable()
export class ArduinoDaemonClientImpl implements ArduinoDaemonClient {
@inject(ILogger)
protected readonly logger: ILogger;
@inject(MessageService)
protected readonly messageService: MessageService;
protected readonly onStartedEmitter = new Emitter<void>();
protected readonly onStoppedEmitter = new Emitter<void>();
protected _isRunning = false;
notifyStopped(): void {
if (this._isRunning) {
this._isRunning = false;
this.onStoppedEmitter.fire();
this.info('The CLI daemon process has stopped.');
}
}
notifyStarted(): void {
if (!this._isRunning) {
this._isRunning = true;
this.onStartedEmitter.fire();
this.info('The CLI daemon process has started.');
}
}
get onDaemonStarted(): Event<void> {
return this.onStartedEmitter.event;
}
get onDaemonStopped(): Event<void> {
return this.onStoppedEmitter.event;
}
get isRunning(): boolean {
return this._isRunning;
}
protected info(message: string): void {
this.messageService.info(message, { timeout: 3000 });
this.logger.info(message);
}
}