2

Is it possible to show users of your extension or color theme notifications in Visual Studio Code? For someone who has my color theme or extension installed and is getting updates, I would like to possibly show this person a notification after they update the extension (That could be on launch of VSCode, or right after they go into the market to update & reload the extension and client themselves.)

For example: I think it would be beneficial to me and not invasive if they saw a notification after updating the extension saying "Feedback? Suggestions? Fixes?..on the theme?" OR notifying them of something changed in the theme that may not be favorable. So they can "opt out" of that change if they want (Like an extra set of borders around something or the color change of something.)

Obviously people with all notifications off would not be affected, but I thought an occasional notification after a rare update wouldn't be too bad. I have not been able to find info on if this is possible, and if it was, how to do it. Any info on this is appreciated. And if it is possible, those reading this, whether you've done it or not, would you recommend showing a notification to your theme users in that way?

Thanks :)

GorvGoyl
  • 42,508
  • 29
  • 229
  • 225
956MB
  • 135
  • 2
  • 12

2 Answers2

3

Show a notification on bottom-right corner, whenever your extension is updated. You can also control to show it only for major/minor releases.

That's how it looks: enter image description here

Add below code to extension.ts:

import { window, ExtensionContext, extensions, env, Uri } from "vscode";

const extensionId = "jerrygoyal.shortcut-menu-bar";

// this method is called when your extension is activated
export function activate(context: ExtensionContext) {
  showWhatsNew(context); // show notification in case of a major release i.e. 1.0.0 -> 2.0.0
}

// https://stackoverflow.com/a/66303259/3073272
function isMajorUpdate(previousVersion: string, currentVersion: string) {
  // rain-check for malformed string
  if (previousVersion.indexOf(".") === -1) {
    return true;
  }
  //returns int array [1,1,1] i.e. [major,minor,patch]
  var previousVerArr = previousVersion.split(".").map(Number);
  var currentVerArr = currentVersion.split(".").map(Number);

  if (currentVerArr[0] > previousVerArr[0]) {
    return true;
  } else {
    return false;
  }
}

async function showWhatsNew(context: ExtensionContext) {
  const previousVersion = context.globalState.get<string>(extensionId);
  const currentVersion = extensions.getExtension(extensionId)!.packageJSON
    .version;

  // store latest version
  context.globalState.update(extensionId, currentVersion);

  if (
    previousVersion === undefined ||
    isMajorUpdate(previousVersion, currentVersion)
  ) {
    // show whats new notificatin:
    const actions = [{ title: "See how" }];

    const result = await window.showInformationMessage(
      `Shortcut Menubar v${currentVersion} — Add your own buttons!`,
      ...actions
    );

    if (result !== null) {
      if (result === actions[0]) {
        await env.openExternal(
          Uri.parse(
            "https://github.com/GorvGoyl/Shortcut-Menu-Bar-VSCode-Extension#create-buttons-with-custom-commands"
          )
        );
      }
    }
  }
}

You can see this implementation in my VSCode extension repo Shortcut Menu Bar

GorvGoyl
  • 42,508
  • 29
  • 229
  • 225
-1

I think you can register the version during activation event and check for it on each activation. Then you can do whatever you want. For instance GitLens is migrating settings https://github.com/eamodio/vscode-gitlens/blob/master/src/extension.ts#L52 and i'm pretty sure I remember that they were opening a notification (but i have not found immediately in the code)

regards,

Aurélien Pupier
  • 724
  • 1
  • 8
  • 23
  • I found information on this from [vscode docs](https://code.visualstudio.com/api/get-started/extension-anatomy) getting me closer to what I'm looking for, like "vscode.window.showInformationMessage('Hello World!');" but this looks like its example is with a typescript extension rather than a simple color theme. Pretty hard to find articles or anything of people doing exactly what im trying to set up. Also, im a little out of my element with how this would be set up tbh. Do you know of any reference to color themes with notifications at startup? Any help appreciated :) – 956MB Mar 17 '19 at 01:59