X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Fdownloads.jsm;fp=common%2Fmodules%2Fdownloads.jsm;h=03ab19909e70014be9dc9d313c329331359d0581;hb=9044153cb63835e39b9de8ec4ade237c03e3888a;hp=faee6e22a7a1ce5a28bcda6019c2e99dc9c05a68;hpb=70740024f9c028c1fd63e1a1850ab062ff956054;p=dactyl.git diff --git a/common/modules/downloads.jsm b/common/modules/downloads.jsm index faee6e2..03ab199 100644 --- a/common/modules/downloads.jsm +++ b/common/modules/downloads.jsm @@ -2,12 +2,11 @@ // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -"use strict"; +/* use strict */ Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("downloads", { - exports: ["Download", "Downloads", "downloads"], - use: ["io", "messages", "prefs", "services", "util"] + exports: ["Download", "Downloads", "downloads"] }, this); Cu.import("resource://gre/modules/DownloadUtils.jsm", this); @@ -20,9 +19,8 @@ var states = iter([v, k.slice(prefix.length).toLowerCase()] var Download = Class("Download", { init: function init(id, list) { - let self = XPCSafeJSObjectWrapper(services.downloadManager.getDownload(id)); - self.__proto__ = this; - this.instance = this; + let self = this; + this.download = services.downloadManager.getDownload(id); this.list = list; this.nodes = { @@ -74,7 +72,7 @@ var Download = Class("Download", { get alive() this.inState(["downloading", "notstarted", "paused", "queued", "scanning"]), - allowedCommands: Class.memoize(function () let (self = this) ({ + allowedCommands: Class.Memoize(function () let (self = this) ({ get cancel() self.cancelable && self.inState(["downloading", "paused", "starting"]), get delete() !this.cancel && self.targetFile.exists(), get launch() self.targetFile.exists() && self.inState(["finished"]), @@ -172,7 +170,8 @@ var Download = Class("Download", { } } - let total = this.nodes.progressTotal.textContent = this.size ? util.formatBytes(this.size, 1, true) : _("download.unknown"); + let total = this.nodes.progressTotal.textContent = this.size || !this.nActive ? util.formatBytes(this.size, 1, true) + : _("download.unknown"); let suffix = RegExp(/( [a-z]+)?$/i.exec(total)[0] + "$"); this.nodes.progressHave.textContent = util.formatBytes(this.amountTransferred, 1, true).replace(suffix, ""); @@ -193,6 +192,14 @@ var Download = Class("Download", { this.updateProgress(); } }); +Object.keys(XPCOMShim([Ci.nsIDownload])).forEach(function (key) { + if (!(key in Download.prototype)) + Object.defineProperty(Download.prototype, key, { + get: function get() this.download[key], + set: function set(val) this.download[key] = val, + configurable: true + }); +}); var DownloadList = Class("DownloadList", XPCOM([Ci.nsIDownloadProgressListener, @@ -213,7 +220,7 @@ var DownloadList = Class("DownloadList", services.downloadManager.removeListener(this); }, - message: Class.memoize(function () { + message: Class.Memoize(function () { util.xmlToDom(