有人可以告诉我如何注册Mozilla / Firefox DownloadList视图吗?
这就是我正在使用的:但它完全破坏了下载管理器:
const {Cc,Ci,Cu} = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm");
let view = {
onDownloadAdded: download => console.log("Added", download),
onDownloadChanged: download => console.log("Changed", download),
onDownloadRemoved: download => console.log("Removed", download),
};
console.log('Test1');
Downloads.getList(Downloads.ALL)
.then(list => {
console.log('Test2');
list.addView(view);
console.log('Test3');
});
不幸的是,执行此代码后,下载似乎彻底破坏了:它甚至不允许再下载。
一切似乎进展顺利:
I/GeckoConsole( 8723): Test1
I/GeckoConsole( 8723): Test2
I/GeckoConsole( 8723): Test3
但我没有看到Downloads
中的DownloadList
也应该记录下来。
当我尝试下载另一个文件时,我得到:
W/GeckoConsole( 8723): [JavaScript Error: "[Exception... "Component returned fai
lure code: 0x80004005 (NS_ERROR_FAILURE) [nsITransfer.init]" nsresult: "0x80004
005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://global/content/contentA
reaUtils.js :: internalPersist :: line 47" data: no]" {file: "resource://gre/mo
dules/Promise.jsm -> resource://gre/modules/Promise-backend.js" line: 79}]