Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 23 matching lines...) Expand all Loading... | |
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?type=%T YPE%", | 36 update_url_release: "https://update.adblockplus.org/%NAME%/update.json?type=%T YPE%", |
37 update_url_devbuild: "https://adblockplus.org/devbuilds/%NAME%/update.json?typ e=%TYPE%", | 37 update_url_devbuild: "https://adblockplus.org/devbuilds/%NAME%/update.json?typ e=%TYPE%", |
38 update_last_check: 0, | 38 update_last_check: 0, |
39 update_last_error: 0, | 39 update_last_error: 0, |
40 update_soft_expiration: 0, | 40 update_soft_expiration: 0, |
41 update_hard_expiration: 0, | 41 update_hard_expiration: 0, |
42 currentVersion: "0.0", | 42 currentVersion: "0.0", |
43 notificationdata: {}, | 43 notificationdata: {}, |
44 notificationurl: "https://notification.adblockplus.org/notification.json" | 44 notificationurl: "https://notification.adblockplus.org/notification.json", |
45 suppress_first_run_page: false, | |
46 disable_auto_updates: false | |
45 }; | 47 }; |
46 | 48 |
49 let preconfigurable = ["suppress_first_run_page", "disable_auto_updates"]; | |
50 | |
47 let values = Object.create(defaults); | 51 let values = Object.create(defaults); |
48 let path = _fileSystem.resolve("prefs.json"); | 52 let path = _fileSystem.resolve("prefs.json"); |
49 let listeners = []; | 53 let listeners = []; |
50 let isDirty = false; | 54 let isDirty = false; |
51 let isSaving = false; | 55 let isSaving = false; |
52 | 56 |
53 function defineProperty(key) | 57 function defineProperty(key) |
54 { | 58 { |
55 Object.defineProperty(Prefs, key, | 59 Object.defineProperty(Prefs, key, |
56 { | 60 { |
(...skipping 11 matching lines...) Expand all Loading... | |
68 | 72 |
69 for (let listener of listeners) | 73 for (let listener of listeners) |
70 listener(key); | 74 listener(key); |
71 }, | 75 }, |
72 enumerable: true | 76 enumerable: true |
73 }); | 77 }); |
74 } | 78 } |
75 | 79 |
76 function load() | 80 function load() |
77 { | 81 { |
82 // Set default prefs based on _preconfiguredPrefs | |
83 for (let key in _preconfiguredPrefs) | |
84 { | |
85 if (preconfigurable.indexOf(key) != -1) | |
86 { | |
87 if (typeof _preconfiguredPrefs[key] != typeof defaults[key]) | |
Felix Dahlke
2015/06/12 11:55:35
Don't think we need to check for this - we don't d
Oleksandr
2015/06/12 12:29:59
Done.
| |
88 throw new Error("Attempt to change preference type through preconfigurat ion"); | |
89 defaults[key] = _preconfiguredPrefs[key]; | |
Felix Dahlke
2015/06/12 11:55:35
Was about to complain that this isn't necessary, b
Oleksandr
2015/06/12 12:29:59
Done.
| |
90 values[key] = _preconfiguredPrefs[key]; | |
91 } | |
92 } | |
93 | |
78 _fileSystem.read(path, function(result) | 94 _fileSystem.read(path, function(result) |
79 { | 95 { |
80 // prefs.json is expected to be missing, ignore errors reading file | 96 // prefs.json is expected to be missing, ignore errors reading file |
81 if (!result.error) | 97 if (!result.error) |
82 { | 98 { |
83 try | 99 try |
84 { | 100 { |
85 let data = JSON.parse(result.content); | 101 let data = JSON.parse(result.content); |
86 for (let key in data) | 102 for (let key in data) |
87 if (key in defaults) | 103 if (key in defaults) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 let index = listeners.indexOf(listener); | 144 let index = listeners.indexOf(listener); |
129 if (index >= 0) | 145 if (index >= 0) |
130 listeners.splice(index, 1); | 146 listeners.splice(index, 1); |
131 }, | 147 }, |
132 }; | 148 }; |
133 | 149 |
134 for (let key in defaults) | 150 for (let key in defaults) |
135 defineProperty(key); | 151 defineProperty(key); |
136 | 152 |
137 load(); | 153 load(); |
OLD | NEW |