summaryrefslogtreecommitdiffstats
path: root/application/palemoon/base/content/sync/progress.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-02 03:35:06 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-02 03:35:06 -0500
commit49ee0794b5d912db1f95dce6eb52d781dc210db5 (patch)
tree6efefe6a09feb09d965932b24e10436b9ac8189c /application/palemoon/base/content/sync/progress.js
parente72ef92b5bdc43cd2584198e2e54e951b70299e8 (diff)
downloadUXP-49ee0794b5d912db1f95dce6eb52d781dc210db5.tar
UXP-49ee0794b5d912db1f95dce6eb52d781dc210db5.tar.gz
UXP-49ee0794b5d912db1f95dce6eb52d781dc210db5.tar.lz
UXP-49ee0794b5d912db1f95dce6eb52d781dc210db5.tar.xz
UXP-49ee0794b5d912db1f95dce6eb52d781dc210db5.zip
Add Pale Moon
Diffstat (limited to 'application/palemoon/base/content/sync/progress.js')
-rw-r--r--application/palemoon/base/content/sync/progress.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/application/palemoon/base/content/sync/progress.js b/application/palemoon/base/content/sync/progress.js
new file mode 100644
index 000000000..2063f612a
--- /dev/null
+++ b/application/palemoon/base/content/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");
+
+let gProgressBar;
+let 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();
+}