This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from crdlc/bug-1067614-v2
Bug 1067614 - [User Story] Ensure users are always on the latest loop mo...(cherry picked from commit 6face3a)
- Loading branch information
Cristian Rodriguez
committed
Oct 29, 2014
1 parent
7fc9307
commit a8e1120
Showing
4 changed files
with
126 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use strict'; | ||
|
||
(function(exports) { | ||
|
||
/* | ||
* This variable indicates the number of retries when there was a connection | ||
* problem. | ||
*/ | ||
var retries = Config.maxVersionCheckAttempts; | ||
|
||
function closeApp() { | ||
window.close(); | ||
} | ||
|
||
function showUpdateDialog(app) { | ||
var onMozL10nReady = function() { | ||
(new OptionMenu({ | ||
section: Branding.getTranslation('newUpdateAvailable'), | ||
type: 'confirm', | ||
items: [{ | ||
name: 'Cancel', | ||
l10nId: 'cancel', | ||
method: closeApp | ||
}, { | ||
name: 'Download', | ||
l10nId:'download', | ||
class: 'recommend', | ||
method: function onDownload() { | ||
app.download(); | ||
closeApp(); | ||
} | ||
}] | ||
})).show(); | ||
}; | ||
|
||
if (navigator.mozL10n.readyState === 'complete') { | ||
onMozL10nReady(); | ||
} else { | ||
navigator.mozL10n.ready(onMozL10nReady); | ||
} | ||
} | ||
|
||
function connected() { | ||
return new Promise(function(resolve, reject) { | ||
if (navigator.onLine) { | ||
resolve(); | ||
} else { | ||
window.addEventListener('online', function onConnect() { | ||
window.removeEventListener('online', onConnect); | ||
resolve(); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
function checkForUpdate(app) { | ||
if (--retries < 0) { | ||
return; | ||
} | ||
|
||
var req = app.checkForUpdate(); | ||
|
||
req.onsuccess = function(event) { | ||
app.downloadAvailable && showUpdateDialog(app); | ||
}; | ||
|
||
req.onerror = function(error) { | ||
if (error.name === 'NETWORK_ERROR') { | ||
connected().then(checkForUpdate.bind(null, app)); | ||
} | ||
}; | ||
} | ||
|
||
exports.UpdateChecker = { | ||
check: function() { | ||
navigator.mozApps.getSelf().onsuccess = function(evt) { | ||
var app = evt.target.result; | ||
connected().then(checkForUpdate.bind(null, app)); | ||
}; | ||
} | ||
}; | ||
|
||
})(window); |