|
| 1 | +import { inject, injectable } from 'inversify'; |
| 2 | +import { window } from 'vscode'; |
| 3 | +import { IExtensionSingleActivationService } from '../activation/types'; |
| 4 | +import { IDisposable, IDisposableRegistry } from '../common/types'; |
| 5 | +import { sendTelemetryEvent } from '../telemetry'; |
| 6 | +import { EventName } from '../telemetry/constants'; |
| 7 | + |
| 8 | +// Every 5 min look, through active terminals to see if any are running `tensorboard` |
| 9 | +@injectable() |
| 10 | +export class TerminalWatcher implements IExtensionSingleActivationService, IDisposable { |
| 11 | + private handle: NodeJS.Timeout | undefined; |
| 12 | + |
| 13 | + constructor(@inject(IDisposableRegistry) private disposables: IDisposableRegistry) {} |
| 14 | + |
| 15 | + public async activate(): Promise<void> { |
| 16 | + const handle = setInterval(() => { |
| 17 | + // When user runs a command in VSCode terminal, the terminal's name |
| 18 | + // becomes the program that is currently running. Since tensorboard |
| 19 | + // stays running in the terminal while the webapp is running and |
| 20 | + // until the user kills it, the terminal with the updated name should |
| 21 | + // stick around for long enough that we only need to run this check |
| 22 | + // every 5 min or so |
| 23 | + const matches = window.terminals.filter((terminal) => terminal.name === 'tensorboard'); |
| 24 | + if (matches.length > 0) { |
| 25 | + sendTelemetryEvent(EventName.TENSORBOARD_DETECTED_IN_INTEGRATED_TERMINAL); |
| 26 | + clearInterval(handle); // Only need telemetry sent once per VS Code session |
| 27 | + } |
| 28 | + }, 300_000); |
| 29 | + this.handle = handle; |
| 30 | + this.disposables.push(this); |
| 31 | + } |
| 32 | + |
| 33 | + public dispose(): void { |
| 34 | + if (this.handle) { |
| 35 | + clearInterval(this.handle); |
| 36 | + } |
| 37 | + } |
| 38 | +} |
0 commit comments