Skip to content

Commit

Permalink
Refine conditions for displaying the install azd prompt (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwateratmsft committed Mar 14, 2023
1 parent 2066116 commit ef8c5f1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 37 deletions.
10 changes: 2 additions & 8 deletions ext/vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# Release History

## 0.5.0-alpha.1 (Unreleased)

### Features Added

### Breaking Changes

## 0.4.1 (2023-03-14)
### Bugs Fixed

### Other Changes
- [[#1724]](https://github.com/Azure/azure-dev/pull/1724) Refine conditions for displaying the prompt to install the CLI.

## 0.4.0 (2023-03-08)
### Added
Expand Down
4 changes: 2 additions & 2 deletions ext/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ext/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "azure-dev",
"displayName": "Azure Developer CLI",
"description": "Makes it easy to run, provision, and deploy Azure applications using the Azure Developer CLI",
"version": "0.5.0-alpha.1",
"version": "0.4.1",
"license": "MIT",
"icon": "resources/icon.png",
"preview": true,
Expand Down
39 changes: 13 additions & 26 deletions ext/vscode/src/utils/azureDevCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import { setVsCodeContext } from './setVsCodeContext';

// Twenty seconds: generous, but not infinite
export const DefaultAzCliInvocationTimeout: number = 20 * 1000;
const AzdInstallationUrl: string = 'https://aka.ms/azd-install';
const AzdLoginCheckCacheLifetime = 15 * 60 * 1000; // 15 minutes

let userWarnedAzdMissing: boolean = false;
let azdInstallAttempted: boolean = false;
const azdLoginChecker = new AsyncLazy<LoginStatus | undefined>(getAzdLoginStatus, AzdLoginCheckCacheLifetime);

Expand All @@ -39,7 +37,6 @@ export async function createAzureDevCli(context: IActionContext): Promise<AzureD
if (!loginStatus) {
context.errorHandling.suppressReportIssue = true;
context.errorHandling.buttons = azdNotInstalledUserChoices();
userWarnedAzdMissing = true;
throw new Error(azdNotInstalledMsg());
}

Expand All @@ -52,10 +49,14 @@ export function scheduleAzdSignInCheck(): void {
setTimeout(async () => {
const result = await azdLoginChecker.getValue();

if (!result && !userWarnedAzdMissing && !azdInstallAttempted) {
userWarnedAzdMissing = true;
const response = await vscode.window.showWarningMessage(azdNotInstalledMsg(), {}, ...azdNotInstalledUserChoices());
await response?.callback();
if (result !== undefined) {
// If we've reached this point, AZD is installed. We can set the VSCode context that the walk-through uses
await setVsCodeContext('hideAzdInstallStep', true);

// If the user is logged in, we can also set the login context
if (result.status === 'success') {
await setVsCodeContext('hideAzdLoginStep', true);
}
}
}, oneSecond);
}
Expand Down Expand Up @@ -143,14 +144,6 @@ async function getAzdLoginStatus(): Promise<LoginStatus | undefined> {
const stdout = (await execAsync(command, cli.spawnOptions())).stdout;
const result = JSON.parse(stdout) as LoginStatus;

// If we've reached this point, AZD is installed. We can set the VSCode context that the walk-through uses
await setVsCodeContext('hideAzdInstallStep', true);

// If the user is logged in, we can also set the login context
if (result?.status === 'success') {
await setVsCodeContext('hideAzdLoginStep', true);
}

return result;
} catch {
// If AZD is not installed, return `undefined`
Expand All @@ -171,26 +164,20 @@ function normalize(env: NodeJS.ProcessEnv): Environment {
}

function azdNotInstalledMsg(): string {
return localize("azure-dev.utils.azd.notInstalled", "Azure Developer CLI is not installed. Would you like to install it?.");
return localize("azure-dev.utils.azd.notInstalled", "Azure Developer CLI is not installed. Would you like to install it? [Learn More](https://aka.ms/azd-install)");
}

function azdNotInstalledUserChoices(): AzExtErrorButton[] {
const choices: AzExtErrorButton[] = [
{
"title": localize("azure-dev.utils.azd.installNow", "Install"),
"callback": async () => {
title: localize("azure-dev.utils.azd.installNow", "Install"),
callback: async () => {
await vscode.commands.executeCommand("azure-dev.commands.cli.install", /* shouldPrompt: */ false);
}
},
{
"title": localize("azure-dev.utils.azd.goToInstallUrl", "Learn More"),
"callback": async () => {
await vscode.env.openExternal(vscode.Uri.parse(AzdInstallationUrl));
}
},
{
"title": localize("azure-dev.utils.azd.later", "Later"),
"callback": () => { return Promise.resolve(); /* no-op */ }
title: localize("azure-dev.utils.azd.later", "Later"),
callback: () => { return Promise.resolve(); /* no-op */ }
}
];
return choices;
Expand Down

0 comments on commit ef8c5f1

Please sign in to comment.