|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
|
6 Cu.import("resource://gre/modules/Services.jsm"); |
|
7 Cu.import("resource://services-sync/main.js"); |
|
8 |
|
9 let gProgressBar; |
|
10 let gCounter = 0; |
|
11 |
|
12 function onLoad(event) { |
|
13 Services.obs.addObserver(onEngineSync, "weave:engine:sync:finish", false); |
|
14 Services.obs.addObserver(onEngineSync, "weave:engine:sync:error", false); |
|
15 Services.obs.addObserver(onServiceSync, "weave:service:sync:finish", false); |
|
16 Services.obs.addObserver(onServiceSync, "weave:service:sync:error", false); |
|
17 |
|
18 gProgressBar = document.getElementById('uploadProgressBar'); |
|
19 |
|
20 if (Services.prefs.getPrefType("services.sync.firstSync") != Ci.nsIPrefBranch.PREF_INVALID) { |
|
21 gProgressBar.hidden = false; |
|
22 } |
|
23 else { |
|
24 gProgressBar.hidden = true; |
|
25 } |
|
26 } |
|
27 |
|
28 function onUnload(event) { |
|
29 cleanUpObservers(); |
|
30 } |
|
31 |
|
32 function cleanUpObservers() { |
|
33 try { |
|
34 Services.obs.removeObserver(onEngineSync, "weave:engine:sync:finish"); |
|
35 Services.obs.removeObserver(onEngineSync, "weave:engine:sync:error"); |
|
36 Services.obs.removeObserver(onServiceSync, "weave:service:sync:finish"); |
|
37 Services.obs.removeObserver(onServiceSync, "weave:service:sync:error"); |
|
38 } |
|
39 catch (e) { |
|
40 // may be double called by unload & exit. Ignore. |
|
41 } |
|
42 } |
|
43 |
|
44 function onEngineSync(subject, topic, data) { |
|
45 // The Clients engine syncs first. At this point we don't necessarily know |
|
46 // yet how many engines will be enabled, so we'll ignore the Clients engine |
|
47 // and evaluate how many engines are enabled when the first "real" engine |
|
48 // syncs. |
|
49 if (data == "clients") { |
|
50 return; |
|
51 } |
|
52 |
|
53 if (!gCounter && |
|
54 Services.prefs.getPrefType("services.sync.firstSync") != Ci.nsIPrefBranch.PREF_INVALID) { |
|
55 gProgressBar.max = Weave.Service.engineManager.getEnabled().length; |
|
56 } |
|
57 |
|
58 gCounter += 1; |
|
59 gProgressBar.setAttribute("value", gCounter); |
|
60 } |
|
61 |
|
62 function onServiceSync(subject, topic, data) { |
|
63 // To address the case where 0 engines are synced, we will fill the |
|
64 // progress bar so the user knows that the sync has finished. |
|
65 gProgressBar.setAttribute("value", gProgressBar.max); |
|
66 cleanUpObservers(); |
|
67 } |
|
68 |
|
69 function closeTab() { |
|
70 window.close(); |
|
71 } |