Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/actions/chatGettingStarted.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { IWorkbenchContribution } from '../../../../common/contributions.js';
7
import { Disposable } from '../../../../../base/common/lifecycle.js';
8
import { IProductService } from '../../../../../platform/product/common/productService.js';
9
import { IExtensionService } from '../../../../services/extensions/common/extensions.js';
10
import { ExtensionIdentifier } from '../../../../../platform/extensions/common/extensions.js';
11
import { IExtensionManagementService, InstallOperation } from '../../../../../platform/extensionManagement/common/extensionManagement.js';
12
import { IStorageService, StorageScope, StorageTarget } from '../../../../../platform/storage/common/storage.js';
13
import { IDefaultChatAgent } from '../../../../../base/common/product.js';
14
import { IWorkbenchLayoutService } from '../../../../services/layout/browser/layoutService.js';
15
import { showCopilotView } from '../chat.js';
16
import { IViewsService } from '../../../../services/views/common/viewsService.js';
17
18
export class ChatGettingStartedContribution extends Disposable implements IWorkbenchContribution {
19
static readonly ID = 'workbench.contrib.chatGettingStarted';
20
private recentlyInstalled: boolean = false;
21
22
private static readonly hideWelcomeView = 'workbench.chat.hideWelcomeView';
23
24
constructor(
25
@IProductService private readonly productService: IProductService,
26
@IExtensionService private readonly extensionService: IExtensionService,
27
@IViewsService private readonly viewsService: IViewsService,
28
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
29
@IStorageService private readonly storageService: IStorageService,
30
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
31
) {
32
super();
33
34
const defaultChatAgent = this.productService.defaultChatAgent;
35
const hideWelcomeView = this.storageService.getBoolean(ChatGettingStartedContribution.hideWelcomeView, StorageScope.APPLICATION, false);
36
if (!defaultChatAgent || hideWelcomeView) {
37
return;
38
}
39
40
this.registerListeners(defaultChatAgent);
41
}
42
43
private registerListeners(defaultChatAgent: IDefaultChatAgent): void {
44
45
this._register(this.extensionManagementService.onDidInstallExtensions(async (result) => {
46
for (const e of result) {
47
if (ExtensionIdentifier.equals(defaultChatAgent.extensionId, e.identifier.id) && e.operation === InstallOperation.Install) {
48
this.recentlyInstalled = true;
49
return;
50
}
51
}
52
}));
53
54
this._register(this.extensionService.onDidChangeExtensionsStatus(async (event) => {
55
for (const ext of event) {
56
if (ExtensionIdentifier.equals(defaultChatAgent.extensionId, ext.value)) {
57
const extensionStatus = this.extensionService.getExtensionsStatus();
58
if (extensionStatus[ext.value].activationTimes && this.recentlyInstalled) {
59
this.onDidInstallChat();
60
return;
61
}
62
}
63
}
64
}));
65
}
66
67
private async onDidInstallChat() {
68
69
// Open Copilot view
70
showCopilotView(this.viewsService, this.layoutService);
71
72
// Only do this once
73
this.storageService.store(ChatGettingStartedContribution.hideWelcomeView, true, StorageScope.APPLICATION, StorageTarget.MACHINE);
74
this.recentlyInstalled = false;
75
}
76
}
77
78