import { getLargeOperationThrottle, getPerformanceProfile, hasAudibleTabs, setPerformanceProfile } from '../core'; import { CommandGroup } from '../classes/CommandGroup'; import type { CommandEntry } from '../classes/CommandGroup'; import type { Job, PerfSetProfileArgs, JobIdArgs } from '../types'; // PerfCommands also owns the jobs.* status/cancel queries: they read the same // JobManager (ctx.jobs) that perf.status reports, and there is no dedicated // jobs command group. export class PerfCommands extends CommandGroup { readonly namespace = "perf"; readonly commands: Record = { "perf.status": () => this.perfStatus(), "perf.set_profile": (a: PerfSetProfileArgs) => setPerformanceProfile(typeof a.profile === "string" ? a.profile : undefined), "jobs.status": (a: JobIdArgs) => this.ctx.jobs.status(a), "jobs.cancel": (a: JobIdArgs) => this.ctx.jobs.cancel(a), }; private jobSummary(job: Job) { return { id: job.id, command: job.command, status: job.status, phase: job.phase, current: job.current, total: job.total, percent: job.percent, cancelRequested: job.cancelRequested, }; } private async perfStatus() { const profile = await getPerformanceProfile(); const audible = await hasAudibleTabs(); const throttle = await getLargeOperationThrottle(0, "auto"); return { performanceProfile: profile, audible, throttle, jobs: this.ctx.jobs.list().map(job => this.jobSummary(job)), }; } }