forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterminalWatcher.ts
More file actions
38 lines (34 loc) · 1.68 KB
/
terminalWatcher.ts
File metadata and controls
38 lines (34 loc) · 1.68 KB
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
import { inject, injectable } from 'inversify';
import { window } from 'vscode';
import { IExtensionSingleActivationService } from '../activation/types';
import { IDisposable, IDisposableRegistry } from '../common/types';
import { sendTelemetryEvent } from '../telemetry';
import { EventName } from '../telemetry/constants';
// Every 5 min look, through active terminals to see if any are running `tensorboard`
@injectable()
export class TerminalWatcher implements IExtensionSingleActivationService, IDisposable {
private handle: NodeJS.Timeout | undefined;
constructor(@inject(IDisposableRegistry) private disposables: IDisposableRegistry) {}
public async activate(): Promise<void> {
const handle = setInterval(() => {
// When user runs a command in VSCode terminal, the terminal's name
// becomes the program that is currently running. Since tensorboard
// stays running in the terminal while the webapp is running and
// until the user kills it, the terminal with the updated name should
// stick around for long enough that we only need to run this check
// every 5 min or so
const matches = window.terminals.filter((terminal) => terminal.name === 'tensorboard');
if (matches.length > 0) {
sendTelemetryEvent(EventName.TENSORBOARD_DETECTED_IN_INTEGRATED_TERMINAL);
clearInterval(handle); // Only need telemetry sent once per VS Code session
}
}, 300_000);
this.handle = handle;
this.disposables.push(this);
}
public dispose(): void {
if (this.handle) {
clearInterval(this.handle);
}
}
}