|
| 1 | +/* |
| 2 | + * Project: ESP-IDF VSCode Extension |
| 3 | + * File Created: Thursday, 7th August 2025 |
| 4 | + * Copyright 2024 Espressif Systems (Shanghai) CO LTD |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +import { ExtensionContext, window, env, Uri, l10n } from "vscode"; |
| 20 | +import { ESP } from "./config"; |
| 21 | +import { Logger } from "./logger/logger"; |
| 22 | +import { packageJson } from "./utils"; |
| 23 | +import { NotificationMode, readParameter } from "./idfConfiguration"; |
| 24 | +import { Telemetry } from "./telemetry"; |
| 25 | + |
| 26 | +export namespace PreReleaseNotification { |
| 27 | + export async function showPreReleaseNotification(context: ExtensionContext) { |
| 28 | + // Check if this specific campaign was already shown |
| 29 | + const campaignKey = ESP.PreReleaseNotification.EIM_SETUP_CAMPAIGN; |
| 30 | + const shownCampaigns = context.globalState.get<string[]>( |
| 31 | + ESP.PreReleaseNotification.SHOWN_KEY, |
| 32 | + [] |
| 33 | + ); |
| 34 | + |
| 35 | + // Check notification settings |
| 36 | + const notificationMode = readParameter("idf.notificationMode") as string; |
| 37 | + const enableNotification = |
| 38 | + notificationMode === NotificationMode.All || |
| 39 | + notificationMode === NotificationMode.Notifications; |
| 40 | + |
| 41 | + // Only show if this campaign hasn't been shown and notifications are enabled |
| 42 | + if (!shownCampaigns.includes(campaignKey) && enableNotification) { |
| 43 | + // Track that the notification was shown |
| 44 | + Telemetry.sendEvent("preReleaseNotification", { |
| 45 | + campaign: campaignKey, |
| 46 | + action: "shown", |
| 47 | + extensionVersion: packageJson.version, |
| 48 | + }); |
| 49 | + |
| 50 | + const message = l10n.t( |
| 51 | + "🎉 New ESP-IDF Extension setup available! We've completely redesigned the installation process with the ESP-IDF Installer Manager (EIM) for a smoother, more reliable setup experience. Help us improve by trying the pre-release!" |
| 52 | + ); |
| 53 | + |
| 54 | + const tryPreRelease = l10n.t("Try New Pre-Release"); |
| 55 | + const learnMore = l10n.t("Learn More"); |
| 56 | + const notNow = l10n.t("Not Now"); |
| 57 | + |
| 58 | + const response = await window.showInformationMessage( |
| 59 | + message, |
| 60 | + { modal: false }, |
| 61 | + tryPreRelease, |
| 62 | + learnMore, |
| 63 | + notNow |
| 64 | + ); |
| 65 | + |
| 66 | + if (response === tryPreRelease) { |
| 67 | + // Track user clicked to try pre-release |
| 68 | + Telemetry.sendEvent("preReleaseNotification", { |
| 69 | + campaign: campaignKey, |
| 70 | + action: "tryPreRelease", |
| 71 | + extensionVersion: packageJson.version, |
| 72 | + }); |
| 73 | + |
| 74 | + // Open the extension in Extensions view |
| 75 | + const extensionUri = Uri.parse( |
| 76 | + "vscode:extension/espressif.esp-idf-extension" |
| 77 | + ); |
| 78 | + await env.openExternal(extensionUri); |
| 79 | + |
| 80 | + // Show additional guidance for enabling pre-release |
| 81 | + const preReleaseInfo = await window.showInformationMessage( |
| 82 | + l10n.t( |
| 83 | + "To install the pre-release version, click the 'Switch to Pre-Release Version' button." |
| 84 | + ), |
| 85 | + { modal: false }, |
| 86 | + l10n.t("Got it") |
| 87 | + ); |
| 88 | + |
| 89 | + Logger.info("User clicked to try pre-release from notification"); |
| 90 | + |
| 91 | + // Mark this campaign as shown when user tries pre-release |
| 92 | + const updatedCampaigns = [...shownCampaigns, campaignKey]; |
| 93 | + await context.globalState.update( |
| 94 | + ESP.PreReleaseNotification.SHOWN_KEY, |
| 95 | + updatedCampaigns |
| 96 | + ); |
| 97 | + } else if (response === learnMore) { |
| 98 | + // Track user clicked to learn more |
| 99 | + Telemetry.sendEvent("preReleaseNotification", { |
| 100 | + campaign: campaignKey, |
| 101 | + action: "learnMore", |
| 102 | + extensionVersion: packageJson.version, |
| 103 | + }); |
| 104 | + |
| 105 | + // Open documentation about the new setup experience |
| 106 | + const docsUri = Uri.parse( |
| 107 | + "https://docs.espressif.com/projects/idf-im-ui/en/latest/" |
| 108 | + ); |
| 109 | + await env.openExternal(docsUri); |
| 110 | + Logger.info("User clicked to learn more from pre-release notification"); |
| 111 | + |
| 112 | + // Re-show the notification after viewing docs |
| 113 | + setTimeout(() => { |
| 114 | + showPreReleaseNotification(context); |
| 115 | + }, 2000); // Small delay to let the external browser open |
| 116 | + } else { |
| 117 | + // Track user dismissed the notification (clicked "Not Now" or dismissed) |
| 118 | + Telemetry.sendEvent("preReleaseNotification", { |
| 119 | + campaign: campaignKey, |
| 120 | + action: response ? "notNow" : "dismissed", |
| 121 | + extensionVersion: packageJson.version, |
| 122 | + }); |
| 123 | + Logger.info("User dismissed pre-release notification"); |
| 124 | + |
| 125 | + // Mark this campaign as shown only when dismissed or "Not Now" |
| 126 | + const updatedCampaigns = [...shownCampaigns, campaignKey]; |
| 127 | + await context.globalState.update( |
| 128 | + ESP.PreReleaseNotification.SHOWN_KEY, |
| 129 | + updatedCampaigns |
| 130 | + ); |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | +} |
0 commit comments