If you want to know the detailed progress of add-on installations (not uninstalls), you can use listeners which you add with 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()
and the onInstalled
event.
This other answer of mine contains a complete Add-on SDK extension which shows the various events available through the AddonManager's addAddonListener()
method. It also shows the order the events are fired for an add-on which is already installed and one which is being installed and uninstalled (showing both what events you get for your own install/uninstall and when the add-on being installed/uninstalled is not your own add-on).
Editing that code down to just what is needed for what you asked results in the following code (Note: I hand edited the code here, but did not test it (i.e. there may be errors). The code in the answer I linked above was completely tested):
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();