Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 let {Prefs} = require("prefs"); | 18 let {Prefs} = require("prefs"); |
19 let {FilterNotifier} = require("filterNotifier"); | 19 let {FilterNotifier} = require("filterNotifier"); |
20 | 20 |
21 let prefsInitDone = false; | 21 let prefsInitDone = false; |
22 let filtersInitDone = false; | 22 let filtersInitDone = false; |
23 let isFirstRun = false; | |
24 | 23 |
25 function checkInitialized() | 24 function checkInitialized() |
26 { | 25 { |
27 if (prefsInitDone && filtersInitDone) | 26 if (prefsInitDone && filtersInitDone) |
28 { | 27 { |
29 checkInitialized = function() {}; | 28 checkInitialized = function() {}; |
30 _triggerEvent("init", isFirstRun); | 29 _triggerEvent("init", require("filterStorage").FilterStorage.firstRun); |
Felix Dahlke
2014/04/23 09:43:22
Also required below, I'd vote for doing this once
Wladimir Palant
2014/04/23 10:40:36
This isn't a real module loading mechanism here, m
Felix Dahlke
2014/04/24 11:11:41
Well, that's a leaky abstraction if there ever was
| |
31 } | 30 } |
32 } | 31 } |
33 | 32 |
34 Prefs._initListener = function() | 33 Prefs._initListener = function() |
35 { | 34 { |
36 prefsInitDone = true; | 35 prefsInitDone = true; |
37 checkInitialized(); | 36 checkInitialized(); |
38 }; | 37 }; |
39 | 38 |
40 FilterNotifier.addListener(function(action) | 39 FilterNotifier.addListener(function(action) |
41 { | 40 { |
42 if (action === "load") | 41 if (action === "load") |
43 { | 42 { |
44 let {FilterStorage} = require("filterStorage"); | 43 let {FilterStorage} = require("filterStorage"); |
45 if (FilterStorage.subscriptions.length == 0) | 44 if (FilterStorage.firstRun) |
46 { | 45 { |
47 // No data, must be a new user or someone with corrupted data - initialize | 46 // No data, must be a new user or someone with corrupted data - initialize |
48 // with default settings | 47 // with default settings |
49 | 48 |
50 isFirstRun = true; | |
51 | |
52 let {Subscription, DownloadableSubscription} = require("subscriptionClasse s"); | 49 let {Subscription, DownloadableSubscription} = require("subscriptionClasse s"); |
53 let {Synchronizer} = require("synchronizer"); | 50 let {Synchronizer} = require("synchronizer"); |
54 let {Prefs} = require("prefs"); | 51 let {Prefs} = require("prefs"); |
55 let {Utils} = require("utils"); | 52 let {Utils} = require("utils"); |
56 | 53 |
57 // Choose default subscription and add it | 54 // Choose default subscription and add it |
58 let subscriptions = require("subscriptions.xml"); | 55 let subscriptions = require("subscriptions.xml"); |
59 let node = Utils.chooseFilterSubscription(subscriptions); | 56 let node = Utils.chooseFilterSubscription(subscriptions); |
60 if (node) | 57 if (node) |
61 { | 58 { |
62 let subscription = Subscription.fromURL(node.url); | 59 let subscription = Subscription.fromURL(node.url); |
63 FilterStorage.addSubscription(subscription); | 60 FilterStorage.addSubscription(subscription); |
64 subscription.disabled = false; | 61 subscription.disabled = false; |
65 subscription.title = node.title; | 62 subscription.title = node.title; |
66 subscription.homepage = node.homepage; | 63 subscription.homepage = node.homepage; |
67 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload) | 64 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload) |
68 Synchronizer.execute(subscription); | 65 Synchronizer.execute(subscription); |
69 } | 66 } |
70 } | 67 } |
71 | 68 |
72 filtersInitDone = true; | 69 filtersInitDone = true; |
73 checkInitialized(); | 70 checkInitialized(); |
74 } | 71 } |
75 }); | 72 }); |
OLD | NEW |