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
5263 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 { IChatWidgetService } from '../chat.js';
15
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
16
17
export class ChatGettingStartedContribution extends Disposable implements IWorkbenchContribution {
18
static readonly ID = 'workbench.contrib.chatGettingStarted';
19
private recentlyInstalled: boolean = false;
20
21
private static readonly hideWelcomeView = 'workbench.chat.hideWelcomeView';
22
23
constructor(
24
@IProductService private readonly productService: IProductService,
25
@IExtensionService private readonly extensionService: IExtensionService,
26
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
27
@IStorageService private readonly storageService: IStorageService,
28
@IChatWidgetService private readonly chatWidgetService: IChatWidgetService,
29
@IConfigurationService private readonly configurationService: IConfigurationService,
30
) {
31
super();
32
33
const defaultChatAgent = this.productService.defaultChatAgent;
34
const hideWelcomeView = this.storageService.getBoolean(ChatGettingStartedContribution.hideWelcomeView, StorageScope.APPLICATION, false);
35
if (!defaultChatAgent || hideWelcomeView) {
36
return;
37
}
38
39
this.registerListeners(defaultChatAgent);
40
}
41
42
private registerListeners(defaultChatAgent: IDefaultChatAgent): void {
43
44
this._register(this.extensionManagementService.onDidInstallExtensions(async (result) => {
45
for (const e of result) {
46
if (ExtensionIdentifier.equals(defaultChatAgent.extensionId, e.identifier.id) && e.operation === InstallOperation.Install) {
47
this.recentlyInstalled = true;
48
return;
49
}
50
}
51
}));
52
53
this._register(this.extensionService.onDidChangeExtensionsStatus(async (event) => {
54
for (const ext of event) {
55
if (ExtensionIdentifier.equals(defaultChatAgent.extensionId, ext.value)) {
56
const extensionStatus = this.extensionService.getExtensionsStatus();
57
if (extensionStatus[ext.value].activationTimes && this.recentlyInstalled) {
58
this.onDidInstallChat();
59
return;
60
}
61
}
62
}
63
}));
64
}
65
66
private async onDidInstallChat() {
67
68
// Don't reveal if user prefers the agent sessions welcome page
69
const startupEditor = this.configurationService.getValue<string>('workbench.startupEditor');
70
if (startupEditor !== 'agentSessionsWelcomePage') {
71
// Open Chat view
72
this.chatWidgetService.revealWidget();
73
}
74
75
// Only do this once
76
this.storageService.store(ChatGettingStartedContribution.hideWelcomeView, true, StorageScope.APPLICATION, StorageTarget.MACHINE);
77
this.recentlyInstalled = false;
78
}
79
}
80
81