Path: blob/main/src/vs/workbench/contrib/chat/browser/actions/chatGettingStarted.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IWorkbenchContribution } from '../../../../common/contributions.js';6import { Disposable } from '../../../../../base/common/lifecycle.js';7import { IProductService } from '../../../../../platform/product/common/productService.js';8import { IExtensionService } from '../../../../services/extensions/common/extensions.js';9import { ExtensionIdentifier } from '../../../../../platform/extensions/common/extensions.js';10import { IExtensionManagementService, InstallOperation } from '../../../../../platform/extensionManagement/common/extensionManagement.js';11import { IStorageService, StorageScope, StorageTarget } from '../../../../../platform/storage/common/storage.js';12import { IDefaultChatAgent } from '../../../../../base/common/product.js';13import { IWorkbenchLayoutService } from '../../../../services/layout/browser/layoutService.js';14import { showCopilotView } from '../chat.js';15import { IViewsService } from '../../../../services/views/common/viewsService.js';1617export class ChatGettingStartedContribution extends Disposable implements IWorkbenchContribution {18static readonly ID = 'workbench.contrib.chatGettingStarted';19private recentlyInstalled: boolean = false;2021private static readonly hideWelcomeView = 'workbench.chat.hideWelcomeView';2223constructor(24@IProductService private readonly productService: IProductService,25@IExtensionService private readonly extensionService: IExtensionService,26@IViewsService private readonly viewsService: IViewsService,27@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,28@IStorageService private readonly storageService: IStorageService,29@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,30) {31super();3233const defaultChatAgent = this.productService.defaultChatAgent;34const hideWelcomeView = this.storageService.getBoolean(ChatGettingStartedContribution.hideWelcomeView, StorageScope.APPLICATION, false);35if (!defaultChatAgent || hideWelcomeView) {36return;37}3839this.registerListeners(defaultChatAgent);40}4142private registerListeners(defaultChatAgent: IDefaultChatAgent): void {4344this._register(this.extensionManagementService.onDidInstallExtensions(async (result) => {45for (const e of result) {46if (ExtensionIdentifier.equals(defaultChatAgent.extensionId, e.identifier.id) && e.operation === InstallOperation.Install) {47this.recentlyInstalled = true;48return;49}50}51}));5253this._register(this.extensionService.onDidChangeExtensionsStatus(async (event) => {54for (const ext of event) {55if (ExtensionIdentifier.equals(defaultChatAgent.extensionId, ext.value)) {56const extensionStatus = this.extensionService.getExtensionsStatus();57if (extensionStatus[ext.value].activationTimes && this.recentlyInstalled) {58this.onDidInstallChat();59return;60}61}62}63}));64}6566private async onDidInstallChat() {6768// Open Copilot view69showCopilotView(this.viewsService, this.layoutService);7071// Only do this once72this.storageService.store(ChatGettingStartedContribution.hideWelcomeView, true, StorageScope.APPLICATION, StorageTarget.MACHINE);73this.recentlyInstalled = false;74}75}767778