visual-studio-code - 可以在更新时向 VSCode 扩展/颜色主题的用户显示通知吗?

标签 visual-studio-code notifications vscode-extensions

是否可以在 Visual Studio Code 中向您的扩展程序或颜色主题通知的用户显示?对于安装了我的颜色主题或扩展并正在获取更新的人,我希望可能在他们更新扩展后向此人显示通知(可能是在 VSCode 启动时,或者在他们进入市场更新后)重新加载扩展和客户端本身。)

例如:我认为,如果他们在更新扩展程序后看到一条通知,上面写着“反馈?建议?修复?......关于主题?”,这对我来说是有益的,而不是侵入性的。 通知他们主题发生了可能不利的变化。因此,如果他们愿意,他们可以“选择退出”该更改(例如某物周围的一组额外边框或某物的颜色变化。)

显然,关闭所有通知的人不会受到影响,但我认为在罕见的更新后偶尔出现通知也不会太糟糕。我无法找到有关这是否可能的信息,如果可能的话,如何做到这一点。任何有关这方面的信息都将受到赞赏。如果可能的话,那些阅读本文的人,无论您是否已经这样做,您是否会建议以这种方式向您的主题用户显示通知?

谢谢:)

最佳答案

每当您的扩展程序更新时,都会在右下角显示通知。您还可以控制仅在主要/次要版本中显示它。

看起来就是这样: enter image description here

将以下代码添加到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"
          )
        );
      }
    }
  }
}

您可以在我的 VSCode 扩展存储库 Shortcut Menu Bar 中看到此实现

关于visual-studio-code - 可以在更新时向 VSCode 扩展/颜色主题的用户显示通知吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54878347/

相关文章:

visual-studio-code - 如何更改vs代码中关键字的颜色(setting.json)

ios - 在没有 Storyboard的情况下点击通知时访问特定的 ViewController(以编程方式)

visual-studio-code - VSCode 扩展 : How to render colored output in output channel?

visual-studio-code - 在 VS Code Ubuntu 中更改终端的复制和粘贴快捷方式

c++ - 如何在 VSCode 上自动创建 C++ 类

javascript - Visual Studio Code JSON 对象在新函数中丢失智能感知

visual-studio-code - 我的语法高亮语法注入(inject)有什么问题?

java - OneSignal 操作按钮

python - gmailR错误 "Only AF_INET sockets are currently supported on jython"

node.js - 如何从github编译第三方扩展?