kortina
kortina

Reputation: 6101

How can I display a message when someone updates to a new version of my extension?

I have seen extensions display an important notification in the bottom right when vscode auto-dates them, like this:

eg

How can I display a message like this the first time someone runs the new version of an extension I maintain?

Upvotes: 0

Views: 2974

Answers (2)

rioV8
rioV8

Reputation: 28663

I have looked at the source code of the Material Theme how they do it. It was the first extension to show me such a message and a theme extension would not have a lot of code.

What they do is: write a file in the directory of the extension that contains the version number of the extension the last time they showed the message. It is stored in JSON format because package.json is too.

On activation:

  • search for the file user_config.json in the extension directory (place where package.json is)
  • if not found => show message
  • read version numbers stored in file user_config.json and package.json
  • compare if package.json version is bigger (major - minor - patch)
  • if bigger => show message
  • if message shown => save package.json version in user_config.json

Upvotes: 1

sudo
sudo

Reputation: 943

You can use vscode.window.showInformationMessage API, to show buttons you can pass as many arguments you want after 1st one, which is title

const resp = await vscode.window.showInformationMessage(
  "There are multiple formatters for 'JSON' files...",
  "Configure..."
);

if (resp === "Configure...") {
  //your logic here
}

Upvotes: 1

Related Questions