gpt4 book ai didi

javascript - 如何了解 Firefox Add-on SDK 中其他插件的安装情况

转载 作者:行者123 更新时间:2023-11-28 05:17:17 25 4
gpt4 key购买 nike

用于了解带有 SDK 插件的任何插件安装(Firefox 浏览器)的代码是什么?

我知道应该用AddonManager.addInstallListener()来写和 onNewInstall() 方法。我无法将它们组合起来并编写代码。请帮我编写代码。

最佳答案

如果您想了解附加组件安装(而不是卸载)的详细进度,您可以使用通过 AddonManager.addInstallListener() 添加的监听器。但是,对于您所要求的,在安装 and-on 时接收事件(即不监视安装进度,只是安装发生),您可以使用 AddonManager.addAddonListener()onInstalled 事件。

This other answer of mine包含一个完整的附加 SDK 扩展,它显示了通过 AddonManager's 可用的各种事件。 addAddonListener()方法。它还显示了已安装的附加组件以及正在安装和卸载的附加组件触发事件的顺序(显示您自己安装/卸载时获得的事件以及正在安装/卸载的附加组件的时间)不是您自己的附加组件)。

将该代码编辑为您所要求的内容所需的结果会产生以下代码(注意:我在这里手动编辑了代码,但没有对其进行测试(即可能存在错误)。答案中的代码我上面的链接已经过完全测试):

const { AddonManager } = require("resource://gre/modules/AddonManager.jsm");

var addonListener = {
onInstalled: function(addon){
console.log('AddonManager Event: Installed addon ID: ' + addon.id
+ ' ::addon object:', addon);
}
}

exports.onUnload = function (reason) {
//Your add-on listeners are NOT automatically removed when
// your add-on is disabled/uninstalled.
//You MUST remove them in exports.onUnload if the reason is
// not 'shutdown'. If you don't, errors will be shown in the
// console for all events for which you registered a listener.
if(reason !== 'shutdown') {
uninstallAddonListener();
}
};

function installAddonListener(){
//Using an AddonManager listener is not effective to listen for your own add-on's
// install event. The event happens prior to you adding the listener.
//console.log('In installAddonListener: Adding add-on listener');
AddonManager.addAddonListener(addonListener);
}

function uninstallAddonListener(){
//console.log('In removeAddonListener: Removing add-on listener');
AddonManager.removeAddonListener(addonListener);
}

installAddonListener();

关于javascript - 如何了解 Firefox Add-on SDK 中其他插件的安装情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40874208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com