2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-10-19 14:29:24 -07:00
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://services-sync/main.js");
|
|
|
|
|
|
|
|
let gProgressBar;
|
|
|
|
let gCounter = 0;
|
|
|
|
|
|
|
|
function onLoad(event) {
|
2011-10-24 12:24:00 -07:00
|
|
|
Services.obs.addObserver(onEngineSync, "weave:engine:sync:finish", false);
|
|
|
|
Services.obs.addObserver(onEngineSync, "weave:engine:sync:error", false);
|
|
|
|
Services.obs.addObserver(onServiceSync, "weave:service:sync:finish", false);
|
|
|
|
Services.obs.addObserver(onServiceSync, "weave:service:sync:error", false);
|
|
|
|
|
2011-10-19 14:29:24 -07:00
|
|
|
gProgressBar = document.getElementById('uploadProgressBar');
|
|
|
|
|
|
|
|
if (Services.prefs.getPrefType("services.sync.firstSync") != Ci.nsIPrefBranch.PREF_INVALID) {
|
2013-02-11 12:39:41 -08:00
|
|
|
gProgressBar.hidden = false;
|
2011-10-19 14:29:24 -07:00
|
|
|
}
|
|
|
|
else {
|
2013-02-11 12:39:41 -08:00
|
|
|
gProgressBar.hidden = true;
|
2011-10-19 14:29:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onUnload(event) {
|
2011-10-24 12:24:00 -07:00
|
|
|
cleanUpObservers();
|
2011-10-19 14:29:24 -07:00
|
|
|
}
|
|
|
|
|
2011-10-24 12:24:00 -07:00
|
|
|
function cleanUpObservers() {
|
|
|
|
try {
|
2013-04-06 11:46:35 -07:00
|
|
|
Services.obs.removeObserver(onEngineSync, "weave:engine:sync:finish");
|
|
|
|
Services.obs.removeObserver(onEngineSync, "weave:engine:sync:error");
|
|
|
|
Services.obs.removeObserver(onServiceSync, "weave:service:sync:finish");
|
|
|
|
Services.obs.removeObserver(onServiceSync, "weave:service:sync:error");
|
2011-10-24 12:24:00 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// may be double called by unload & exit. Ignore.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEngineSync(subject, topic, data) {
|
|
|
|
// The Clients engine syncs first. At this point we don't necessarily know
|
|
|
|
// yet how many engines will be enabled, so we'll ignore the Clients engine
|
|
|
|
// and evaluate how many engines are enabled when the first "real" engine
|
|
|
|
// syncs.
|
|
|
|
if (data == "clients") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gCounter &&
|
|
|
|
Services.prefs.getPrefType("services.sync.firstSync") != Ci.nsIPrefBranch.PREF_INVALID) {
|
2012-08-29 14:43:40 -07:00
|
|
|
gProgressBar.max = Weave.Service.engineManager.getEnabled().length;
|
2011-10-24 12:24:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-19 14:29:24 -07:00
|
|
|
gCounter += 1;
|
|
|
|
gProgressBar.setAttribute("value", gCounter);
|
|
|
|
}
|
|
|
|
|
2011-10-24 12:24:00 -07:00
|
|
|
function onServiceSync(subject, topic, data) {
|
|
|
|
// To address the case where 0 engines are synced, we will fill the
|
|
|
|
// progress bar so the user knows that the sync has finished.
|
|
|
|
gProgressBar.setAttribute("value", gProgressBar.max);
|
|
|
|
cleanUpObservers();
|
|
|
|
}
|
|
|
|
|
2011-10-19 14:29:24 -07:00
|
|
|
function closeTab() {
|
|
|
|
window.close();
|
|
|
|
}
|