From 05151685c645d1551a7a0036985695fb49e8674e Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Tue, 10 Sep 2024 00:45:37 +0200 Subject: [PATCH] Show a "What's new?" teaser after installation (once) --- src/extension.ts | 3 +++ src/settings.ts | 15 +++++++++++++++ src/whatsNewTeaser.ts | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/whatsNewTeaser.ts diff --git a/src/extension.ts b/src/extension.ts index ef31fe0..c4dc60a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,6 +2,7 @@ import * as vscode from "vscode"; import { registerShebangCompletionProviders } from "./createShebangCompletionProvider"; import OutputWindowLogger from "./OutputWindowLogger"; import { registerHandleSnippetCompletionCommand } from "./handleSnippetCompletionCommand"; +import { showWhatsNewTeaserIfNeeded } from "./whatsNewTeaser"; export function activate(context: vscode.ExtensionContext) { const logger = new OutputWindowLogger(); @@ -9,6 +10,8 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.concat(registerShebangCompletionProviders(context)); context.subscriptions.push(registerHandleSnippetCompletionCommand(context)); + + showWhatsNewTeaserIfNeeded(context); } export function deactivate() {} diff --git a/src/settings.ts b/src/settings.ts index 647113f..ea39658 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -18,3 +18,18 @@ export function setLastShebang( ]; extensionContext.globalState.update("lastShebangs", newLastShebangs); } + +export function getLastExecutedVersion( + extensionContext: vscode.ExtensionContext +) { + return extensionContext.globalState.get("lastExecutedVersion"); +} + +export function setLastExecutedVersion( + extensionContext: vscode.ExtensionContext +) { + extensionContext.globalState.update( + "lastExecutedVersion", + extensionContext.extension.packageJSON.version ?? "" + ); +} \ No newline at end of file diff --git a/src/whatsNewTeaser.ts b/src/whatsNewTeaser.ts new file mode 100644 index 0000000..7673761 --- /dev/null +++ b/src/whatsNewTeaser.ts @@ -0,0 +1,38 @@ +import * as vscode from "vscode"; +import { getLastExecutedVersion, setLastExecutedVersion } from "./settings"; + +export async function showWhatsNewTeaserIfNeeded( + extensionContext: vscode.ExtensionContext +) { + const currentVersion = extensionContext.extension.packageJSON.version; + if ( + wasExtensionUpdatedSinceLastStart(extensionContext) && + currentVersion === "1.0.0" + ) { + const message = "Welcome to Shebang Snippets"; + const versionInMessage = + currentVersion !== undefined ? ` ${currentVersion}` : ""; + const result = await vscode.window.showInformationMessage( + `${message}${versionInMessage}!`, + "What's new?" + ); + if (result === "What's new?") { + vscode.env.openExternal( + vscode.Uri.parse( + "https://github.com/Rpinski/vscode-shebang-snippets/blob/master/CHANGELOG.md" + ) + ); + } + + setLastExecutedVersion(extensionContext); + } +} + +function wasExtensionUpdatedSinceLastStart( + extensionContext: vscode.ExtensionContext +) { + return ( + extensionContext.extension.packageJSON.version !== + getLastExecutedVersion(extensionContext) + ); +}