Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/init.js

Issue 11037099: First run detection fix (Closed)
Patch Set: Cleaner version Created July 20, 2013, 8:33 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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;
23 24
24 function checkInitialized() 25 function checkInitialized()
25 { 26 {
26 if (prefsInitDone && filtersInitDone) 27 if (prefsInitDone && filtersInitDone)
27 { 28 {
28 checkInitialized = function() {}; 29 checkInitialized = function() {};
29 _triggerEvent("init"); 30 _triggerEvent("init", isFirstRun);
30 } 31 }
31 } 32 }
32 33
33 Prefs._initListener = function() 34 Prefs._initListener = function()
34 { 35 {
35 prefsInitDone = true; 36 prefsInitDone = true;
36 checkInitialized(); 37 checkInitialized();
37 }; 38 };
38 39
39 FilterNotifier.addListener(function(action) 40 FilterNotifier.addListener(function(action)
40 { 41 {
41 if (action === "load") 42 if (action === "load")
42 { 43 {
43 let {FilterStorage} = require("filterStorage"); 44 let {FilterStorage} = require("filterStorage");
44 if (FilterStorage.subscriptions.length == 0) 45 if (FilterStorage.subscriptions.length == 0)
45 { 46 {
46 // No data, must be a new user or someone with corrupted data - initialize 47 // No data, must be a new user or someone with corrupted data - initialize
47 // with default settings 48 // with default settings
49
50 isFirstRun = true;
51
48 let {Subscription, DownloadableSubscription} = require("subscriptionClasse s"); 52 let {Subscription, DownloadableSubscription} = require("subscriptionClasse s");
49 let {Synchronizer} = require("synchronizer"); 53 let {Synchronizer} = require("synchronizer");
50 let {Prefs} = require("prefs"); 54 let {Prefs} = require("prefs");
51 let {Utils} = require("utils"); 55 let {Utils} = require("utils");
52 56
53 // Choose default subscription and add it 57 // Choose default subscription and add it
54 let subscriptions = require("subscriptions.xml"); 58 let subscriptions = require("subscriptions.xml");
55 let node = Utils.chooseFilterSubscription(subscriptions); 59 let node = Utils.chooseFilterSubscription(subscriptions);
56 if (node) 60 if (node)
57 { 61 {
58 let subscription = Subscription.fromURL(node.url); 62 let subscription = Subscription.fromURL(node.url);
59 FilterStorage.addSubscription(subscription); 63 FilterStorage.addSubscription(subscription);
60 subscription.disabled = false; 64 subscription.disabled = false;
61 subscription.title = node.title; 65 subscription.title = node.title;
62 subscription.homepage = node.homepage; 66 subscription.homepage = node.homepage;
63 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload) 67 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload)
64 Synchronizer.execute(subscription); 68 Synchronizer.execute(subscription);
65 } 69 }
66 } 70 }
67 71
68 filtersInitDone = true; 72 filtersInitDone = true;
69 checkInitialized(); 73 checkInitialized();
70 } 74 }
71 }); 75 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld