LEFT | RIGHT |
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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 data_directory: "", | 28 data_directory: "", |
29 savestats: false, | 29 savestats: false, |
30 privateBrowsing: false, | 30 privateBrowsing: false, |
31 subscriptions_fallbackerrors: 5, | 31 subscriptions_fallbackerrors: 5, |
32 subscriptions_fallbackurl: "https://adblockplus.org/getSubscription?version=%V
ERSION%&url=%SUBSCRIPTION%&downloadURL=%URL%&error=%ERROR%&channelStatus=%CHANNE
LSTATUS%&responseStatus=%RESPONSESTATUS%", | 32 subscriptions_fallbackurl: "https://adblockplus.org/getSubscription?version=%V
ERSION%&url=%SUBSCRIPTION%&downloadURL=%URL%&error=%ERROR%&channelStatus=%CHANNE
LSTATUS%&responseStatus=%RESPONSESTATUS%", |
33 subscriptions_autoupdate: true, | 33 subscriptions_autoupdate: true, |
34 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/excep
tionrules.txt", | 34 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/excep
tionrules.txt", |
35 documentation_link: "https://adblockplus.org/redirect?link=%LINK%&lang=%LANG%"
, | 35 documentation_link: "https://adblockplus.org/redirect?link=%LINK%&lang=%LANG%"
, |
36 update_url_release: "https://update.adblockplus.org/%NAME%/update.json?id=%ID%
&version=%VERSION%&app=%APP%&type=%TYPE%", | 36 update_url_release: "https://update.adblockplus.org/%NAME%/update.json?id=%ID%
&version=%VERSION%&app=%APP%&type=%TYPE%", |
37 update_url_devbuild: "https://adblockplus.org/devbuilds/%NAME%/update.json?id=
%ID%&version=%VERSION%&app=%APP%&type=%TYPE%", | 37 update_url_devbuild: "https://adblockplus.org/devbuilds/%NAME%/update.json?id=
%ID%&version=%VERSION%&app=%APP%&type=%TYPE%", |
38 next_update_check: 0 | 38 next_update_check: 0, |
| 39 statusbarasked: false |
39 }; | 40 }; |
40 | 41 |
41 let values = Object.create(defaults); | 42 let values = Object.create(defaults); |
42 let path = _fileSystem.resolve("prefs.json"); | 43 let path = _fileSystem.resolve("prefs.json"); |
43 let listeners = []; | 44 let listeners = []; |
44 let isDirty = false; | 45 let isDirty = false; |
45 let isSaving = false; | 46 let isSaving = false; |
46 | 47 |
47 function defineProperty(key) | 48 function defineProperty(key) |
48 { | 49 { |
(...skipping 18 matching lines...) Expand all Loading... |
67 { | 68 { |
68 _fileSystem.read(path, function(result) | 69 _fileSystem.read(path, function(result) |
69 { | 70 { |
70 // prefs.json is expected to be missing, ignore errors reading file | 71 // prefs.json is expected to be missing, ignore errors reading file |
71 if (!result.error) | 72 if (!result.error) |
72 { | 73 { |
73 try | 74 try |
74 { | 75 { |
75 let data = JSON.parse(result.content); | 76 let data = JSON.parse(result.content); |
76 for (let key in data) | 77 for (let key in data) |
| 78 if (key in defaults) |
77 values[key] = data[key]; | 79 values[key] = data[key]; |
78 } | 80 } |
79 catch (e) | 81 catch (e) |
80 { | 82 { |
81 Cu.reportError(e); | 83 Cu.reportError(e); |
82 } | 84 } |
83 } | 85 } |
84 | 86 |
85 if (typeof Prefs._initListener == "function") | 87 if (typeof Prefs._initListener == "function") |
86 Prefs._initListener(); | 88 Prefs._initListener(); |
87 }); | 89 }); |
88 } | 90 } |
89 | 91 |
90 function save() | 92 function save() |
91 { | 93 { |
92 if (isSaving) | 94 if (isSaving) |
93 { | 95 { |
94 isDirty = true; | 96 isDirty = true; |
95 return; | 97 return; |
96 } | 98 } |
| 99 |
97 isDirty = false; | 100 isDirty = false; |
98 isSaving = true; | 101 isSaving = true; |
99 _fileSystem.write(path, JSON.stringify(values), function() | 102 _fileSystem.write(path, JSON.stringify(values), function() |
100 { | 103 { |
101 isSaving = false; | 104 isSaving = false; |
102 if (isDirty) | 105 if (isDirty) |
103 save(); | 106 save(); |
104 }); | 107 }); |
105 } | 108 } |
106 | 109 |
107 let Prefs = exports.Prefs = { | 110 let Prefs = exports.Prefs = { |
108 addListener: function(listener) | 111 addListener: function(listener) |
109 { | 112 { |
110 if (listeners.indexOf(listener) < 0) | 113 if (listeners.indexOf(listener) < 0) |
111 listeners.push(listener); | 114 listeners.push(listener); |
112 }, | 115 }, |
113 | 116 |
114 removeListener: function(listener) | 117 removeListener: function(listener) |
115 { | 118 { |
116 let index = listeners.indexOf(listener); | 119 let index = listeners.indexOf(listener); |
117 if (index >= 0) | 120 if (index >= 0) |
118 listeners.splice(index, 1); | 121 listeners.splice(index, 1); |
119 }, | 122 }, |
120 save: save, | |
121 values: values, | |
122 }; | 123 }; |
123 | 124 |
124 for (let key in defaults) | 125 for (let key in defaults) |
125 defineProperty(key); | 126 defineProperty(key); |
126 | 127 |
127 load(); | 128 load(); |
LEFT | RIGHT |