当有人更新到我的扩展程序的新版本时,我如何显示消息? [英] How can I display a message when someone updates to a new version of my extension?

查看:26
本文介绍了当有人更新到我的扩展程序的新版本时,我如何显示消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到扩展程序在 vscode 自动更新日期时会在右下角显示重要通知,如下所示:

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

如何在有人运行我维护的扩展程序的新版本时第一次显示这样的消息?

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

推荐答案

我已经查看了Material Theme 的源代码,他们是如何做到的.这是第一个向我展示这种消息的扩展程序,主题扩展程序不会有很多代码.

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.

他们所做的是:在扩展的目录中写入一个文件,其中包含他们上次显示消息时的扩展版本号.它以 JSON 格式存储,因为 package.json 也是.

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.

激活时:

  • 在扩展目录(package.json所在的位置)中搜索user_config.json文件
  • 如果没有找到=>显示消息
  • 读取存储在文件 user_config.jsonpackage.json
  • 中的版本号
  • 比较 package.json 版本是否更大(主要 - 次要 - 补丁)
  • 如果更大 =>显示消息
  • 如果显示消息=>将 package.json 版本保存在 user_config.json
  • 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

这篇关于当有人更新到我的扩展程序的新版本时,我如何显示消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆