Firefox Add-on SDK如何知道其他插件的安装
How to know the installation of other add-on in Firefox Add-on SDK
知道任何带有 SDK 插件的插件安装(Firefox 浏览器)的代码是什么?
我知道应该用AddonManager.addInstallListener()
和onNewInstall()
的方法来写。我无法将它们组合起来并编写代码。请帮我看看代码。
如果您想知道附加组件安装(不是卸载)的详细进度,您可以使用您通过 AddonManager.addInstallListener()
. However, for what you have asked, receiving events when an and-on is installed (i.e. not monitoring the progress of the installation, just that it happened), you can use AddonManager.addAddonListener()
和 onInstalled
事件添加的侦听器。
contains a complete Add-on SDK extension which shows the various events available through the AddonManager's addAddonListener()
方法。它还显示了为已安装的加载项和正在安装和卸载的加载项触发事件的顺序(显示您为自己的 install/uninstall 获得的事件以及加载项何时 installed/uninstalled 不是您自己的附加组件)。
将该代码编辑为您所要求的内容,得到以下代码(注意:我在这里手动编辑了代码,但没有对其进行测试(即可能存在错误)。代码中的我上面链接的答案已经过完全测试):
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();
知道任何带有 SDK 插件的插件安装(Firefox 浏览器)的代码是什么?
我知道应该用AddonManager.addInstallListener()
和onNewInstall()
的方法来写。我无法将它们组合起来并编写代码。请帮我看看代码。
如果您想知道附加组件安装(不是卸载)的详细进度,您可以使用您通过 AddonManager.addInstallListener()
. However, for what you have asked, receiving events when an and-on is installed (i.e. not monitoring the progress of the installation, just that it happened), you can use AddonManager.addAddonListener()
和 onInstalled
事件添加的侦听器。
addAddonListener()
方法。它还显示了为已安装的加载项和正在安装和卸载的加载项触发事件的顺序(显示您为自己的 install/uninstall 获得的事件以及加载项何时 installed/uninstalled 不是您自己的附加组件)。
将该代码编辑为您所要求的内容,得到以下代码(注意:我在这里手动编辑了代码,但没有对其进行测试(即可能存在错误)。代码中的我上面链接的答案已经过完全测试):
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();