get activedownloadCount in FF 30

35 Aufrufe
Direkt zur ersten ungelesenen Nachricht

VideosProva

ungelesen,
05.08.2014, 15:31:2005.08.14
an moz...@googlegroups.com
In older Firefox I used something like:

Components.classes["@mozilla.org/download-manager;1"].getService(Components.interfaces.nsIDownloadManager).activeDownloadCount

Now, with Firefox 30, which command should I use to get how many downloads are active?

Luca Greco

ungelesen,
06.08.2014, 10:04:1506.08.14
an moz...@googlegroups.com
nsIDownloadManager is going to be decommissioned:
I have never used the new API, but I think that this could be useful:

- http://mxr.mozilla.org/mozilla-central/source/toolkit/components/jsdownloads/test/unit/test_Downloads.js#104

e.g. I tried this in the "Browser Toolbox WebConsole" and it returns the list of my downloads as expected:

```
// Downloads object is already loaded in the chrome window context, or you can import it
// using Cu.import("resource://gre/modules/Downloads.jsm");

Downloads.getSummary(Downloads.PUBLIC).then((public_list) => console.log(public_list));
Downloads.getSummary(Downloads.PUBLIC).then((private_list) => console.log(private_list));
```

--
Luca Greco @ Alca Società Cooperativa
Follow me on http://twitter.com/lucagreco

VideosProva

ungelesen,
07.08.2014, 05:24:2407.08.14
an moz...@googlegroups.com, luca....@alcacoop.it
Thank you, Luca.
I'm not expert of the "Browser Toolbox WebConsole", but I tried your lines and doesn't work:
(I put in the advanced settings the option to debug chrome)

I get:
ReferenceError: Downloads is not defined
or
ReferenceError: Cu is not defined

So, I can't test.

What should I do?

VideosProva

ungelesen,
07.08.2014, 11:18:1807.08.14
an moz...@googlegroups.com, luca....@alcacoop.it
(I have received your answer through mail, but ther isn't in the browser... (??) )

I'm using FF30 too.
Anyway I tried the scratchpad in FF30 (Shift+F4) and there is the option of environment browser: so Cu and Downloads work. In Web Console nothing...

But with your lines I can't get the console answer because I'm in browser env (I should go into content env but then I don't get Cu and Downloads...)

It gives me [object Object]  answer with this:
Downloads.getSummary(Downloads.PUBLIC)


I tried MozRepl connection and I get this answer:

[object Object] - {then: function() {...}}


So, I can't actually test anything.

BTW:
The real purpose I want to, is modify to the new syntax, FF.au3 autoit wrapper that has something like the old:
Local $RetVal = _FFCmd('try{FFau3.obj = Components.classes["@mozilla.org/download-manager;1"].getService(Components.interfaces.nsIDownloadManager).' & "activeDownloadCount" & "" & "" & ';}catch(e){-3;};')




Il giorno giovedì 7 agosto 2014 11:24:24 UTC+2, VideosProva ha scritto:

It seems you are not using a chrome privileged console ("Downloads" and "Cu" should already be defined,
"Cu" is an alias for "Components.utils")

Have you tried in a MozREPL connection?

I'm trying on Firefox 30.0 and I can access the Downloads API from MozREPL using the above code snippets.

 

Luca Greco

ungelesen,
07.08.2014, 11:44:3407.08.14
an VideosProva, moz...@googlegroups.com
On Thu, Aug 7, 2014 at 5:18 PM, VideosProva <franc...@gmail.com> wrote:
(I have received your answer through mail, but ther isn't in the browser... (??) )

It gives me [object Object]  answer with this:
Downloads.getSummary(Downloads.PUBLIC)


I tried MozRepl connection and I get this answer:

[object Object] - {then: function() {...}}


The new "Downloads.jsm" API is "Promise based" (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), so you need to pass a callback to the "then" function to get the real value, from MozREPL we can print the summary content using something like:

  Downloads.getSummary(Downloads.PUBLIC).then( function(summary) {
    repl.print(JSON.stringify(summary));
  });
 
So, I can't actually test anything.

BTW:
The real purpose I want to, is modify to the new syntax, FF.au3 autoit wrapper that has something like the old:
Local $RetVal = _FFCmd('try{FFau3.obj = Components.classes["@mozilla.org/download-manager;1"].getService(Components.interfaces.nsIDownloadManager).' & "activeDownloadCount" & "" & "" & ';}catch(e){-3;};')


I don't know how it works FF.au3 autoit wrapper and how it use the nsIDownloadManager, but the old "nsIDownloadManager" and the new "Downloads.jsm" have different APIs (eg. nsIDownloadManager is synchronous, and Download.jsm is async and Promise based), I'm not sure the wrapper can be adapted without changes to its assumptions about Firefox internals and its API.

Best,
Luca

--
Luca Greco @ Alca Società Cooperativa

VideosProva

ungelesen,
07.08.2014, 11:57:5007.08.14
an moz...@googlegroups.com, franc...@gmail.com, luca....@alcacoop.it
Thank you Luca.

I tried your   then (){}   code in MozREPL, but it gives me the same:


[object Object] - {then: function() {...}}

Best regards
frank




Il giorno giovedì 7 agosto 2014 17:44:34 UTC+2, Luca Greco ha scritto:

The new "Downloads.jsm" API is "Promise based" (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), so you need to pass a callback to the "then" function to get the real value, from MozREPL we can print the summary content using something like:

  Downloads.getSummary(Downloads.PUBLIC).then( function(summary) {
    repl.print(JSON.stringify(summary));
  });
 

Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten