Skip to content

Commit 9a7d150

Browse files
authored
Add a toast to direct users to Container Tools (#4562)
1 parent 4305e3c commit 9a7d150

4 files changed

Lines changed: 81 additions & 6 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vscode-docker",
3-
"version": "1.29.5",
3+
"version": "1.29.6",
44
"publisher": "ms-azuretools",
55
"displayName": "Docker",
66
"description": "Makes it easy to create, manage, and debug containerized applications.",
@@ -2990,9 +2990,6 @@
29902990
"vscode.docker",
29912991
"vscode.yaml"
29922992
],
2993-
"extensionPack": [
2994-
"docker.docker"
2995-
],
29962993
"devDependencies": {
29972994
"@azure/arm-appservice": "^15.0.0",
29982995
"@types/fs-extra": "^11.0.1",

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { AzExtLogOutputChannelWrapper } from './utils/AzExtLogOutputChannelWrapp
2828
import { logDockerEnvironment, logSystemInfo } from './utils/diagnostics';
2929
import { DocumentSettingsClientFeature } from './utils/DocumentSettingsClientFeature';
3030
import { migrateOldEnvironmentSettingsIfNeeded } from './utils/migrateOldEnvironmentSettingsIfNeeded';
31+
import { migrateToContainerTools } from './utils/migrateToContainerTools';
3132
import { registerDockerContextStatusBarEvent } from './utils/registerDockerContextStatusBarItems';
3233

3334
export type KeyInfo = { [keyName: string]: string };
@@ -137,6 +138,9 @@ export async function activateInternal(ctx: vscode.ExtensionContext, perfStats:
137138
// Don't wait
138139
void vscode.commands.executeCommand('vscode-docker.activateRegistryProviders');
139140

141+
// Migration to Container Tools
142+
void migrateToContainerTools();
143+
140144
return new DockerExtensionApi(ctx);
141145
}
142146

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { callWithTelemetryAndErrorHandling, IActionContext } from '@microsoft/vscode-azext-utils';
7+
import * as vscode from 'vscode';
8+
import { ext } from '../extensionVariables';
9+
10+
const dontShowAgainKey = 'vscode-docker.migrateToContainerTools.dontShowAgain';
11+
12+
const reminderIntervalMs = 60 * 60 * 60 * 1000; // 60 hours (2.5 days) in milliseconds
13+
const lastShownKey = 'vscode-docker.migrateToContainerTools.lastShown';
14+
15+
export async function migrateToContainerTools(): Promise<void> {
16+
const shouldInstall = await callWithTelemetryAndErrorHandling<boolean>('vscode-docker.migrateToContainerTools', async (context: IActionContext) => {
17+
context.telemetry.properties.isActivationEvent = 'true';
18+
19+
// Check if the user has already opted out of the notification
20+
const dontShowAgain = ext.context.globalState.get<boolean>(dontShowAgainKey, false);
21+
22+
if (dontShowAgain) {
23+
context.telemetry.suppressAll = true;
24+
return false;
25+
}
26+
27+
// Check if the user has already seen the notification within the reminder interval
28+
const lastShown = ext.context.globalState.get<number>(lastShownKey, 0);
29+
const now = Date.now();
30+
if (lastShown && now - lastShown < reminderIntervalMs) {
31+
context.telemetry.suppressAll = true;
32+
return false;
33+
}
34+
35+
// Update the last shown time to now
36+
await ext.context.globalState.update(lastShownKey, now);
37+
38+
const message = vscode.l10n.t('The Docker extension is becoming the Container Tools extension, which you can install and try now. Installing the Container Tools extension will uninstall the Docker extension and the window will be reloaded. Make sure to save your changes before proceeding. [Learn More](https://aka.ms/vscode-container-tools-learn-more)');
39+
40+
const tryNowButton = vscode.l10n.t('Install and Reload');
41+
const remindMeButton = vscode.l10n.t('Remind Me');
42+
const dontShowAgainButton = vscode.l10n.t('Don\'t Show Again');
43+
44+
// Show the notification
45+
const result = await vscode.window.showInformationMessage(message, tryNowButton, remindMeButton, dontShowAgainButton);
46+
47+
if (result === tryNowButton) {
48+
context.telemetry.properties.choice = 'install';
49+
return true;
50+
} else if (result === remindMeButton) {
51+
context.telemetry.properties.choice = 'remindMe';
52+
return false;
53+
} else if (result === dontShowAgainButton) {
54+
context.telemetry.properties.choice = 'dontShowAgain';
55+
await ext.context.globalState.update(dontShowAgainKey, true);
56+
return false;
57+
} else {
58+
// User closed the notification
59+
context.telemetry.properties.choice = 'closed';
60+
return false;
61+
}
62+
});
63+
64+
if (shouldInstall) {
65+
// Install the Container Tools extension
66+
await vscode.commands.executeCommand('workbench.extensions.installExtension', 'ms-azuretools.vscode-containers');
67+
68+
// Uninstall the Docker extension
69+
await vscode.commands.executeCommand('workbench.extensions.uninstallExtension', 'ms-azuretools.vscode-docker');
70+
71+
// Reload the window to apply changes
72+
await vscode.commands.executeCommand('workbench.action.reloadWindow');
73+
}
74+
}

0 commit comments

Comments
 (0)