Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle alerts in audio cue service, add List Alerts command and settings #201833

Merged
merged 24 commits into from Jan 9, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 20 additions & 14 deletions src/vs/platform/audioCues/browser/audioCueService.ts
Expand Up @@ -30,6 +30,11 @@ export interface IAudioCueService {
export interface IAudioCueOptions {
allowManyInParallel?: boolean;
source?: string;
/**
* For actions like save or format, depending on the
* configured value, we will only
* play the sound if the user triggered the action.
*/
userGesture?: boolean;
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -45,17 +50,18 @@ export class AudioCueService extends Disposable implements IAudioCueService {
constructor(
@IConfigurationService private readonly configurationService: IConfigurationService,
@IAccessibilityService private readonly accessibilityService: IAccessibilityService,
@ITelemetryService private readonly telemetryService: ITelemetryService) {
@ITelemetryService private readonly telemetryService: ITelemetryService,
) {
super();
}

public async playAudioCue(cue: AudioCue, options: IAudioCueOptions = {}): Promise<void> {
const alertMessage = cue.alertMessage;
if (this.isAlertEnabled(cue) && alertMessage) {
if (this.isAlertEnabled(cue, options.userGesture) && alertMessage) {
this.accessibilityService.alert(alertMessage);
}

if (this.isCueEnabled(cue)) {
if (this.isCueEnabled(cue, options.userGesture)) {
this.sendAudioCueTelemetry(cue, options.source);
await this.playSound(cue.sound.getSound(), options.allowManyInParallel);
}
Expand Down Expand Up @@ -218,12 +224,12 @@ export class AudioCueService extends Disposable implements IAudioCueService {
});
});

public isAlertEnabled(cue: AudioCue): boolean {
return this.isAlertEnabledCache.get(cue).get() ?? false;
public isAlertEnabled(cue: AudioCue, userGesture?: boolean): boolean {
return this.isAlertEnabledCache.get(cue, userGesture).get() ?? false;
}

public isCueEnabled(cue: AudioCue): boolean {
return this.isCueEnabledCache.get(cue).get() ?? false;
public isCueEnabled(cue: AudioCue, userGesture?: boolean): boolean {
return this.isCueEnabledCache.get(cue, userGesture).get() ?? false;
}

public onEnabledChanged(cue: AudioCue): Event<void> {
Expand Down Expand Up @@ -254,17 +260,17 @@ function playAudio(url: string, volume: number): Promise<HTMLAudioElement> {
}

class Cache<TArg, TValue> {
private readonly map = new Map<TArg, TValue>();
constructor(private readonly getValue: (value: TArg) => TValue) {
private readonly map = new Map<{ arg: TArg; optionalArg: any }, TValue>();
constructor(private readonly getValue: (value: TArg, optionalArg?: any) => TValue) {
}

public get(arg: TArg): TValue {
if (this.map.has(arg)) {
return this.map.get(arg)!;
public get(arg: TArg, optionalArg?: any): TValue {
if (this.map.has({ arg, optionalArg })) {
meganrogge marked this conversation as resolved.
Show resolved Hide resolved
return this.map.get({ arg, optionalArg })!;
}

const value = this.getValue(arg);
this.map.set(arg, value);
const value = this.getValue(arg, optionalArg);
this.map.set({ arg, optionalArg }, value);
return value;
}
}
Expand Down