diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-04-17 20:22:59 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-04-17 20:22:59 +0200 |
commit | 3eb4310cd889e6c8d22c27f0326273acf0a3e8bf (patch) | |
tree | 508827a64a5ad5c2d465535afea68eee39775a11 /application/basilisk/components/sync/progress.js | |
parent | 07381c3edad8ec24b5d820ec0592e0cafa7d73fa (diff) | |
parent | 1e868fadf94935bcb4a49ea5eec776d84fe2d1e7 (diff) | |
download | UXP-3eb4310cd889e6c8d22c27f0326273acf0a3e8bf.tar UXP-3eb4310cd889e6c8d22c27f0326273acf0a3e8bf.tar.gz UXP-3eb4310cd889e6c8d22c27f0326273acf0a3e8bf.tar.lz UXP-3eb4310cd889e6c8d22c27f0326273acf0a3e8bf.tar.xz UXP-3eb4310cd889e6c8d22c27f0326273acf0a3e8bf.zip |
Merge branch 'Sync-weave'
Diffstat (limited to 'application/basilisk/components/sync/progress.js')
-rw-r--r-- | application/basilisk/components/sync/progress.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/application/basilisk/components/sync/progress.js b/application/basilisk/components/sync/progress.js new file mode 100644 index 000000000..101160fa8 --- /dev/null +++ b/application/basilisk/components/sync/progress.js @@ -0,0 +1,71 @@ +/* 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/. */ + +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://services-sync/main.js"); + +var gProgressBar; +var gCounter = 0; + +function onLoad(event) { + 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); + + gProgressBar = document.getElementById('uploadProgressBar'); + + if (Services.prefs.getPrefType("services.sync.firstSync") != Ci.nsIPrefBranch.PREF_INVALID) { + gProgressBar.hidden = false; + } + else { + gProgressBar.hidden = true; + } +} + +function onUnload(event) { + cleanUpObservers(); +} + +function cleanUpObservers() { + try { + 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"); + } + 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) { + gProgressBar.max = Weave.Service.engineManager.getEnabled().length; + } + + gCounter += 1; + gProgressBar.setAttribute("value", gCounter); +} + +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(); +} + +function closeTab() { + window.close(); +} |