make pause/resume work properly

This commit is contained in:
ben%bengoodger.com 2005-06-16 00:02:10 +00:00
Родитель e607918600
Коммит eb10f3919a
5 изменённых файлов: 59 добавлений и 23 удалений

Просмотреть файл

@ -38,7 +38,7 @@
<!ENTITY details.link "Details"> <!ENTITY details.link "Details">
<!ENTITY pause.label "Pause"> <!ENTITY pause.label "Pause">
<!ENTITY pause.accesskey "P"> <!ENTITY pause.accesskey "e">
<!ENTITY close.label "Close"> <!ENTITY close.label "Close">
<!ENTITY close.accesskey "C"> <!ENTITY close.accesskey "C">

Просмотреть файл

@ -10,6 +10,8 @@ license404Error=The license file could not be found. Please contact the distribu
downloadingLicense=Downloading license text... downloadingLicense=Downloading license text...
statusSucceededFormat=Installed on: %S statusSucceededFormat=Installed on: %S
statusFailed=Install Failed statusFailed=Install Failed
pauseButtonPause=Pause
pauseButtonResume=Resume
# The prefix /update2/0/ uniquely identifies the format of this URL. If you # The prefix /update2/0/ uniquely identifies the format of this URL. If you
# change the format of this URL, then you MUST change the prefix (i.e., # change the format of this URL, then you MUST change the prefix (i.e.,
# increment 0 to 1). # increment 0 to 1).

Просмотреть файл

@ -318,6 +318,7 @@ var gDownloadingPage = {
else else
updates.pauseDownload(); updates.pauseDownload();
this._paused = !this._paused; this._paused = !this._paused;
document.getElementById("activeDownloadItem").paused = this._paused;
}, },
onClose: function() { onClose: function() {
@ -361,31 +362,35 @@ var gDownloadingPage = {
// Flip the progressmeter back to "undetermined" mode in case we need to // Flip the progressmeter back to "undetermined" mode in case we need to
// download a new (complete) update patch. // download a new (complete) update patch.
var active = document.getElementById("activeDownloadItem"); var active = document.getElementById("activeDownloadItem");
active.stopDownload(); active.state = gUpdates.update.state;
var state = STATE_FAILED;
const NS_BINDING_ABORTED = 0x804b0002; const NS_BINDING_ABORTED = 0x804b0002;
var updates = switch (status) {
Components.classes["@mozilla.org/updates/update-service;1"] case Components.results.NS_ERROR_UNEXPECTED:
.getService(Components.interfaces.nsIApplicationUpdateService); LOG("DLP:STATE = " + gUpdates.update.state);
if (status == Components.results.NS_ERROR_UNEXPECTED) { if (gUpdates.update.state == STATE_FAILED)
if (!gUpdates.update.isCompleteUpdate) {
// If we were downloading a patch and the patch verification phase
// failed, log this and then commence downloading the complete update.
LOG("Verification of patch failed, downloading complete update");
gUpdates.update.isCompleteUpdate = true;
state = updates.downloadUpdate(gUpdates.update, false);
}
if (state == STATE_FAILED)
this.showVerificationError(); this.showVerificationError();
else else {
// Verification failed for a partial patch, complete patch is now
// downloading so return early and do NOT remove the download listener!
// Reset the progress meter to "undertermined" mode so that we don't
// show old progress for the new download of the "complete" patch.
active.stopDownload();
return; return;
} }
else if (status == NS_BINDING_ABORTED) { break;
state = gUpdates.update.state; case NS_BINDING_ABORTED:
LOG("gDownloadingPage.onStopRequest: Pausing Download"); LOG("gDownloadingPage.onStopRequest: Pausing Download");
// Return early, do not remove UI listener since the user may resume
// downloading again.
return;
} }
active.state = state;
LOG("Removing Listener");
var updates =
Components.classes["@mozilla.org/updates/update-service;1"].
getService(Components.interfaces.nsIApplicationUpdateService);
updates.removeDownloadListener(this); updates.removeDownloadListener(this);
}, },

Просмотреть файл

@ -66,7 +66,7 @@
mode="undetermined"/> mode="undetermined"/>
<xul:hbox align="center"> <xul:hbox align="center">
<xul:label class="update-item-status" xbl:inherits="value=status" flex="1" crop="right"/> <xul:label class="update-item-status" xbl:inherits="value=status" flex="1" crop="right"/>
<xul:button class="update-item-pause" anonid="pause-button" <xul:button class="update-item-pause" anonid="pauseButton"
label="&pause.label;" accesskey="&pause.accesskey;"/> label="&pause.label;" accesskey="&pause.accesskey;"/>
</xul:hbox> </xul:hbox>
</xul:vbox> </xul:vbox>
@ -85,6 +85,9 @@
<field name="_modeDeck"> <field name="_modeDeck">
document.getAnonymousElementByAttribute(this, "anonid", "modeDeck"); document.getAnonymousElementByAttribute(this, "anonid", "modeDeck");
</field> </field>
<field name="_pauseButton">
document.getAnonymousElementByAttribute(this, "anonid", "pauseButton");
</field>
<method name="setUpdate"> <method name="setUpdate">
<parameter name="update"/> <parameter name="update"/>
<body><![CDATA[ <body><![CDATA[
@ -110,6 +113,7 @@
<body><![CDATA[ <body><![CDATA[
if (!this._started) { if (!this._started) {
this._progressBar.setAttribute("mode", "normal"); this._progressBar.setAttribute("mode", "normal");
this._pauseButton.disabled = false;
this._started = true; this._started = true;
} }
]]></body> ]]></body>
@ -119,11 +123,25 @@
<body><![CDATA[ <body><![CDATA[
if (this._started) { if (this._started) {
this._progressBar.setAttribute("mode", "undetermined"); this._progressBar.setAttribute("mode", "undetermined");
this._pauseButton.disabled = true;
this._started = false; this._started = false;
} }
]]></body> ]]></body>
</method> </method>
<field name="_paused">false</field>
<property name="paused">
<getter><![CDATA[
return this._paused;
]]></getter>
<setter><![CDATA[
this._paused = val;
var key = val ? "pauseButtonResume" : "pauseButtonPause";
this._pauseButton.label = this._strings.getString(key);
return val;
]]></setter>
</property>
<property name="state"> <property name="state">
<getter><![CDATA[ <getter><![CDATA[
return this.getAttribute("state"); return this.getAttribute("state");
@ -159,7 +177,7 @@
</implementation> </implementation>
<handlers> <handlers>
<handler event="command"><![CDATA[ <handler event="command"><![CDATA[
if (event.originalTarget.getAttribute("anonid") == "pause-button") if (event.originalTarget.getAttribute("anonid") == "pauseButton")
this.fireEvent("pause"); this.fireEvent("pause");
]]></handler> ]]></handler>
</handlers> </handlers>

Просмотреть файл

@ -1489,6 +1489,17 @@ Downloader.prototype = {
state = STATE_FAILED; state = STATE_FAILED;
// TODO: use more informative error code here // TODO: use more informative error code here
status = Components.results.NS_ERROR_UNEXPECTED; status = Components.results.NS_ERROR_UNEXPECTED;
if (!this._update.isCompleteUpdate) {
// If we were downloading a patch and the patch verification phase
// failed, log this and then commence downloading the complete update.
LOG("Downloader.onStopRequest: Verification of patch failed, downloading complete update");
this._update.isCompleteUpdate = true;
var rv = this.downloadUpdate(this._update);
LOG("US:STATE = " + rv);
// This will reset the |.state| property on this._update if a new
// download initiates.
}
} }
this._writeStatusFile(this._getUpdatesDir(), state); this._writeStatusFile(this._getUpdatesDir(), state);
this._update.state = state; this._update.state = state;