LEFT | RIGHT |
1 var _prefsInitDone = false; | 1 let {Prefs} = require("prefs"); |
2 var _filtersInitDone = false; | 2 let {FilterNotifier} = require("filterNotifier"); |
3 | 3 |
4 require("prefs").Prefs._initListener = function() | 4 let prefsInitDone = false; |
| 5 let filtersInitDone = false; |
| 6 |
| 7 function checkInitialized() |
5 { | 8 { |
6 _prefsInitDone = true; | 9 if (prefsInitDone && filtersInitDone) |
7 _checkInitialized(); | |
8 }; | |
9 | |
10 function _checkInitialized() | |
11 { | |
12 if (_prefsInitDone && _filtersInitDone) | |
13 { | 10 { |
14 _checkInitialized = function() {}; | 11 checkInitialized = function() {}; |
15 _triggerEvent("init"); | 12 _triggerEvent("init"); |
16 } | 13 } |
17 } | 14 } |
18 | 15 |
19 require("filterNotifier").FilterNotifier.addListener(function(action) | 16 Prefs._initListener = function() |
| 17 { |
| 18 prefsInitDone = true; |
| 19 checkInitialized(); |
| 20 }; |
| 21 |
| 22 FilterNotifier.addListener(function(action) |
20 { | 23 { |
21 if (action === "load") | 24 if (action === "load") |
22 { | 25 { |
23 let {FilterStorage} = require("filterStorage"); | 26 let {FilterStorage} = require("filterStorage"); |
24 if (FilterStorage.subscriptions.length == 0) | 27 if (FilterStorage.subscriptions.length == 0) |
25 { | 28 { |
26 // No data, must be a new user or someone with corrupted data - initialize | 29 // No data, must be a new user or someone with corrupted data - initialize |
27 // with default settings | 30 // with default settings |
28 let {Subscription, DownloadableSubscription} = require("subscriptionClasse
s"); | 31 let {Subscription, DownloadableSubscription} = require("subscriptionClasse
s"); |
29 let {Synchronizer} = require("synchronizer"); | 32 let {Synchronizer} = require("synchronizer"); |
30 let {Prefs} = require("prefs"); | 33 let {Prefs} = require("prefs"); |
31 let {Utils} = require("utils"); | 34 let {Utils} = require("utils"); |
32 | 35 |
33 // Choose default subscription and add it | 36 // Choose default subscription and add it |
34 let subscriptions = require("subscriptions.xml"); | 37 let subscriptions = require("subscriptions.xml"); |
35 let node = Utils.chooseFilterSubscription(subscriptions); | 38 let node = Utils.chooseFilterSubscription(subscriptions); |
36 if (node) | 39 if (node) |
37 { | 40 { |
38 let subscription = Subscription.fromURL(node.url); | 41 let subscription = Subscription.fromURL(node.url); |
39 FilterStorage.addSubscription(subscription); | 42 FilterStorage.addSubscription(subscription); |
40 subscription.disabled = false; | 43 subscription.disabled = false; |
41 subscription.title = node.title; | 44 subscription.title = node.title; |
42 subscription.homepage = node.homepage; | 45 subscription.homepage = node.homepage; |
43 if (subscription instanceof DownloadableSubscription && !subscription.la
stDownload) | 46 if (subscription instanceof DownloadableSubscription && !subscription.la
stDownload) |
44 Synchronizer.execute(subscription); | 47 Synchronizer.execute(subscription); |
45 } | 48 } |
46 } | 49 } |
47 | 50 |
48 _filtersInitDone = true; | 51 filtersInitDone = true; |
49 _checkInitialized(); | 52 checkInitialized(); |
50 } | 53 } |
51 }); | 54 }); |
LEFT | RIGHT |