Skip to content

Allow to hide Copilot via user setting and policy (fix #249615) #251110

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/vs/platform/menubar/electron-main/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,8 @@ export class Menubar extends Disposable {
}

private shouldDrawMenu(menuId: string): boolean {
// We need to draw an empty menu to override the electron default
if (!isMacintosh && !this.showNativeMenu) {
return false;
return false; // We need to draw an empty menu to override the electron default
}

switch (menuId) {
Expand Down
11 changes: 11 additions & 0 deletions src/vs/workbench/contrib/chat/browser/chat.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,17 @@ configurationRegistry.registerConfiguration({
default: false,
tags: ['onExp', 'experimental'],
},
'chat.hideGettingStarted': {
type: 'boolean',
description: nls.localize('chat.hideGettingStarted', "Hide the getting started UI elements for setting up Chat. This setting has no effect when Copilot extensions are installed."),
default: false,
scope: ConfigurationScope.APPLICATION,
policy: {
name: 'ChatHideGettingStarted',
minimumVersion: '1.102'
},
tags: ['experimental']
},
}
});
Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane).registerEditorPane(
Expand Down
42 changes: 39 additions & 3 deletions src/vs/workbench/contrib/chat/common/chatEntitlementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ export interface IChatEntitlementContextState extends IChatSentiment {
export class ChatEntitlementContext extends Disposable {

private static readonly CHAT_ENTITLEMENT_CONTEXT_STORAGE_KEY = 'chat.setupContext';
private static readonly CHAT_HIDDEN_CONFIGURATION_KEY = 'chat.hideGettingStarted';

private readonly canSignUpContextKey: IContextKey<boolean>;
private readonly signedOutContextKey: IContextKey<boolean>;
Expand Down Expand Up @@ -914,6 +915,7 @@ export class ChatEntitlementContext extends Disposable {
@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
@ILogService private readonly logService: ILogService,
@IExtensionsWorkbenchService private readonly extensionsWorkbenchService: IExtensionsWorkbenchService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super();

Expand All @@ -931,8 +933,38 @@ export class ChatEntitlementContext extends Disposable {

this._state = this.storageService.getObject<IChatEntitlementContextState>(ChatEntitlementContext.CHAT_ENTITLEMENT_CONTEXT_STORAGE_KEY, StorageScope.PROFILE) ?? { entitlement: ChatEntitlement.Unknown };

const configuredDisabled = this.isUserConfiguredDisabled();
if (typeof configuredDisabled === 'boolean') {
this._state.hidden = configuredDisabled; // user configuration always takes precedence
}

this.checkExtensionInstallation();
this.updateContextSync();

this.registerListeners();
}

private registerListeners(): void {
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(ChatEntitlementContext.CHAT_HIDDEN_CONFIGURATION_KEY)) {
this.update({ hidden: this.isUserConfiguredDisabled() === true }, true /* from event */);
}
}));
}

private isUserConfiguredDisabled(): boolean | undefined {
const configuration = this.configurationService.inspect(ChatEntitlementContext.CHAT_HIDDEN_CONFIGURATION_KEY);
if (
typeof configuration.applicationValue === 'boolean' ||
typeof configuration.userLocalValue === 'boolean' ||
typeof configuration.userRemoteValue === 'boolean' ||
typeof configuration.userValue === 'boolean' ||
typeof configuration.workspaceValue === 'boolean'
) {
return configuration.value === true;
}

return undefined;
}

private async checkExtensionInstallation(): Promise<void> {
Expand All @@ -955,23 +987,27 @@ export class ChatEntitlementContext extends Disposable {
}

update(context: { installed: boolean; disabled: boolean }): Promise<void>;
update(context: { hidden: boolean }): Promise<void>;
update(context: { hidden: boolean }, fromEvent?: boolean): Promise<void>;
update(context: { later: boolean }): Promise<void>;
update(context: { entitlement: ChatEntitlement }): Promise<void>;
update(context: { installed?: boolean; disabled?: boolean; hidden?: boolean; later?: boolean; entitlement?: ChatEntitlement }): Promise<void> {
update(context: { installed?: boolean; disabled?: boolean; hidden?: boolean; later?: boolean; entitlement?: ChatEntitlement }, fromEvent?: boolean): Promise<void> {
this.logService.trace(`[chat entitlement context] update(): ${JSON.stringify(context)}`);

if (typeof context.installed === 'boolean' && typeof context.disabled === 'boolean') {
this._state.installed = context.installed;
this._state.disabled = context.disabled;

if (context.installed && !context.disabled) {
if (context.installed && !context.disabled && !this.isUserConfiguredDisabled()) {
context.hidden = false; // treat this as a sign to make Chat visible again in case it is hidden
}
}

if (typeof context.hidden === 'boolean') {
this._state.hidden = context.hidden;

if (!fromEvent) {
this.configurationService.updateValue(ChatEntitlementContext.CHAT_HIDDEN_CONFIGURATION_KEY, context.hidden); // no need to await, will trigger change event that is handled
}
}

if (typeof context.later === 'boolean') {
Expand Down
Loading