Skip to content

Commit

Permalink
Add a toast for GHCP4A (#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroFish91 authored Oct 23, 2024
1 parent 4f7feab commit cbc62dd
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { registerCommands } from './commands/registerCommands';
import { TagFileSystem } from './commands/tags/TagFileSystem';
import { registerTagDiagnostics } from './commands/tags/registerTagDiagnostics';
import { ext } from './extensionVariables';
import { gitHubCopilotForAzureToast } from './gitHubCopilotForAzure';
import { AzureResourcesApiInternal } from './hostapi.v2.internal';
import { survey } from './nps';
import { getSubscriptionProviderFactory } from './services/getSubscriptionProviderFactory';
Expand Down Expand Up @@ -99,6 +100,7 @@ export async function activate(context: vscode.ExtensionContext, perfStats: { lo
}));

registerCommands();
gitHubCopilotForAzureToast(context);
survey(context);
});

Expand Down
71 changes: 71 additions & 0 deletions src/gitHubCopilotForAzure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { callWithTelemetryAndErrorHandling, IActionContext, openUrl } from "@microsoft/vscode-azext-utils";
import { commands, Extension, ExtensionContext, extensions, window } from "vscode";
import { localize } from "./utils/localize";

const ghcpExtensionId = 'github.copilot';
const ghcpChatExtensionId = 'github.copilot-chat';
const ghcp4aExtensionId = 'ms-azuretools.vscode-azure-github-copilot';
const ghcp4aLearnPage = 'https://aka.ms/GetGitHubCopilotForAzure';
const dontShowKey = 'ghcp4a/dontShow';

/**
* Conditionally show an install toast for the GitHub Copilot for Azure extension
*/
export function gitHubCopilotForAzureToast({ globalState }: ExtensionContext): void {
void callWithTelemetryAndErrorHandling('ghcp4aToast', async (context: IActionContext) => {
context.telemetry.properties.isActivationEvent = 'true';

const arePrecursorExtensionsInstalled: boolean = isExtensionInstalled(ghcpExtensionId) && isExtensionInstalled(ghcpChatExtensionId);
if (!arePrecursorExtensionsInstalled || isExtensionInstalled(ghcp4aExtensionId)) {
return;
}

const dontShow: boolean = globalState.get<boolean>(dontShowKey, false);
if (dontShow) {
return;
}

const install = {
title: localize('install', 'Install'),
run: async () => {
context.telemetry.properties.toastChoice = 'install';
await commands.executeCommand('extension.open', ghcp4aExtensionId);
await commands.executeCommand('workbench.extensions.installExtension', ghcp4aExtensionId);
},
};

const learnMore = {
title: localize('learnMore', 'Learn More'),
run: async () => {
context.telemetry.properties.toastChoice = 'learnMore';
await openUrl(ghcp4aLearnPage);
},
};

const never = {
title: localize('dontShowAgain', "Don't Show Again"),
run: async () => {
context.telemetry.properties.toastChoice = 'dontShowAgain';
await globalState.update(dontShowKey, true);
},
};

context.telemetry.properties.userAsked = 'true';

const message: string = localize('ghcpToastMessage', 'Get help with Azure questions and tasks in Copilot Chat by installing the GitHub Copilot for Azure extension.');
const button = await window.showInformationMessage(message, install, learnMore, never);
await button?.run();
});
}


function isExtensionInstalled(extensionId: string): boolean {
const extension: Extension<unknown> | undefined = extensions.getExtension(extensionId);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return !!extension?.packageJSON?.version;
}

0 comments on commit cbc62dd

Please sign in to comment.