Skip to content

Commit 041313b

Browse files
authored
Ask for confirmation before performing entitlement command (microsoft#196750)
1 parent 55e2780 commit 041313b

File tree

2 files changed

+17
-34
lines changed

2 files changed

+17
-34
lines changed

src/vs/base/common/product.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ export interface IAiGeneratedWorkspaceTrust {
293293
export interface IGitHubEntitlement {
294294
providerId: string;
295295
command: { title: string; titleWithoutPlaceHolder: string; action: string; when: string };
296-
altCommand: { title: string; action: string; when: string };
297296
entitlementUrl: string;
298297
extensionId: string;
299298
enablementKey: string;
299+
confirmationMessage: string;
300+
confirmationAction: string;
300301
}

src/vs/workbench/contrib/accountEntitlements/browser/accountsEntitlements.contribution.ts

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle
77
import { Registry } from 'vs/platform/registry/common/platform';
88
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution } from 'vs/workbench/common/contributions';
99
import { Disposable, MutableDisposable } from 'vs/base/common/lifecycle';
10-
import { ContextKeyExpr, ContextKeyTrueExpr, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
11-
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
10+
import { ContextKeyExpr, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
11+
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1212
import { ICommandService } from 'vs/platform/commands/common/commands';
1313
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
14-
import { IOpenerService } from 'vs/platform/opener/common/opener';
1514
import { AuthenticationSession, IAuthenticationService } from 'vs/workbench/services/authentication/common/authentication';
1615
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
1716
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
@@ -26,6 +25,7 @@ import { localize } from 'vs/nls';
2625
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2726
import { IRequestService, asText } from 'vs/platform/request/common/request';
2827
import { CancellationToken } from 'vs/base/common/cancellation';
28+
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
2929

3030
const configurationKey = 'workbench.accounts.experimental.showEntitlements';
3131

@@ -35,10 +35,8 @@ class AccountsEntitlement extends Disposable implements IWorkbenchContribution {
3535

3636
constructor(
3737
@IContextKeyService readonly contextService: IContextKeyService,
38-
@IInstantiationService readonly instantiationService: IInstantiationService,
3938
@ICommandService readonly commandService: ICommandService,
4039
@ITelemetryService readonly telemetryService: ITelemetryService,
41-
@IOpenerService readonly openerService: IOpenerService,
4240
@IAuthenticationService readonly authenticationService: IAuthenticationService,
4341
@IProductService readonly productService: IProductService,
4442
@IStorageService readonly storageService: IStorageService,
@@ -168,40 +166,24 @@ class AccountsEntitlement extends Disposable implements IWorkbenchContribution {
168166
const commandService = accessor.get(ICommandService);
169167
const contextKeyService = accessor.get(IContextKeyService);
170168
const storageService = accessor.get(IStorageService);
171-
commandService.executeCommand(productService.gitHubEntitlement!.command.action, productService.gitHubEntitlement!.extensionId!);
169+
const dialogService = accessor.get(IDialogService);
170+
171+
const confirmation = await dialogService.confirm({
172+
type: 'question',
173+
message: productService.gitHubEntitlement!.confirmationMessage,
174+
primaryButton: productService.gitHubEntitlement!.confirmationAction,
175+
});
176+
177+
if (confirmation.confirmed) {
178+
commandService.executeCommand(productService.gitHubEntitlement!.command.action, productService.gitHubEntitlement!.extensionId!);
179+
}
180+
172181
accountsMenuBadgeDisposable.clear();
173182
const contextKey = new RawContextKey<boolean>(configurationKey, true).bindTo(contextKeyService);
174183
contextKey.set(false);
175184
storageService.store(configurationKey, false, StorageScope.APPLICATION, StorageTarget.MACHINE);
176185
}
177186
});
178-
179-
const altMenuTitle = this.productService.gitHubEntitlement!.altCommand.title!;
180-
const altContextKey = this.productService.gitHubEntitlement!.altCommand.when;
181-
182-
registerAction2(class extends Action2 {
183-
constructor() {
184-
super({
185-
id: 'workbench.action.entitlementAltAction',
186-
title: altMenuTitle,
187-
f1: false,
188-
toggled: ContextKeyTrueExpr.INSTANCE,
189-
menu: {
190-
id: MenuId.AccountsContext,
191-
group: '5_AccountsEntitlements',
192-
when: ContextKeyExpr.equals(altContextKey, true),
193-
}
194-
});
195-
}
196-
197-
public async run(
198-
accessor: ServicesAccessor
199-
) {
200-
const productService = accessor.get(IProductService);
201-
const commandService = accessor.get(ICommandService);
202-
commandService.executeCommand(productService.gitHubEntitlement!.altCommand.action, productService.gitHubEntitlement!.extensionId!);
203-
}
204-
});
205187
}
206188
}
207189

0 commit comments

Comments
 (0)