Skip to content

FreHu/vscode-update-notification

Repository files navigation

Update Notification

This is an example vscode extension that demonstrates a pattern. It is not published anywhere.

Core concept

Show a one-time notification when your extension updates, with a "What's New" button that opens your CHANGELOG.md in VS Code's built-in Markdown preview.

On activation, compare the running version against the last version you told the user about. The "last notified" version is persisted in globalState, which is shared across all windows and survives restarts.

stored == none     → fresh install   → store silently, never notify
stored == current  → reload/restart  → silent
current  > stored  → update          → store, notify if the bump clears the threshold
current  < stored  → downgrade       → store, stay silent

Threshold knob

Not every bump deserves a toast. A updateNotification.notifyOn setting lets the user pick the smallest change worth interrupting them for:

Setting Notifies on
patch any bump (default)
minor minor and major bumps
major major bumps only

The version math lives in src/versionGate.ts. The VS Code wiring lives in src/updateNotifier.ts.

Changelog preview

No custom webview — the changelog is just Markdown, so hand it to the built-in preview:

const uri = vscode.Uri.joinPath(context.extensionUri, 'CHANGELOG.md');
await vscode.commands.executeCommand('markdown.showPreview', uri);

Bundle CHANGELOG.md with the extension (it's not in .vscodeignore) so the URI resolves at runtime.

Run

npm install
F5

To see the toast in the Extension Development Host:

  • run it once
  • bump version in package.json
  • run it again

About

Sample extension to demonstrate a notification on update

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors