Hello Mozilla Community!
I need help. I have to develop an Addon for Firefox Version 24.4.0 in which I have to monitor downloads. The basic functionality is as follows: When no downloads are in the queue, do something.
I searched in the Web and there seem to be two Interfaces:
###1) Downloads.jsm
const {Cu} = require("chrome");
Cu.import("resource://gre/modules/Downloads.jsm");
var dlmgrSummary = null;
Downloads.getSummary(Downloads.ALL).then(summary => {
dlmgrSummary = summary;
return summary.addView({
onSummaryChanged: () => doSomething()
})
}, Cu.reportError);
I also included this bit in my bootstrap.js startup:
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar)
.registerFactory(Components.ID("{1b4c85df-cbdd-4bb6-b04e-613caece083c}"), "", "@mozilla.org/transfer;1", null);
and added browser.download.useJSTransfer true
to about:config
as described here.
Nevertheless I get the exception:
TypeError: Downloads.getSummary is not a function
###2) nsIDownloadManager
const {Cc, Ci} = require("chrome");
const dlmgr = Cc['@mozilla.org/download-manager;1'].getService(Ci.nsIDownloadManager);
listener = {
onSecurityChange : function(prog, req, state, dl) { },
onProgressChange : function(prog, req, prog, progMax, tProg, tProgMax, dl) { },
onStateChange : function(prog, req, flags, status, dl) { },
onDownloadStateChange : function(state, dl) {
console.log("Is not called :-(");
doSomething();
}
}
dlmgr.addListener(listener);
In this example the function onDownloadStateChange
is not called.
Is this a problem with the Version or did I do something wrong?
Thanks for any help!