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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 for (let listener of listeners) | 78 for (let listener of listeners) |
79 listener(key); | 79 listener(key); |
80 }, | 80 }, |
81 enumerable: true | 81 enumerable: true |
82 }); | 82 }); |
83 } | 83 } |
84 | 84 |
85 function load() | 85 function load() |
86 { | 86 { |
87 _fileSystem.read(prefsFileName, result => | 87 new Promise((resolve, reject) => |
88 { | 88 { |
89 // prefs.json is expected to be missing, ignore errors reading file | 89 _fileSystem.read(prefsFileName, resolve, reject); |
90 if (!result.error) | 90 }).then((result) => |
| 91 { |
| 92 try |
91 { | 93 { |
92 try | 94 let data = JSON.parse(result.content); |
93 { | 95 for (let key in data) |
94 let data = JSON.parse(result.content); | 96 if (key in defaults) |
95 for (let key in data) | 97 values[key] = data[key]; |
96 if (key in defaults) | |
97 values[key] = data[key]; | |
98 } | |
99 catch (e) | |
100 { | |
101 Cu.reportError(e); | |
102 } | |
103 } | 98 } |
104 | 99 catch (e) |
| 100 { |
| 101 Cu.reportError(e); |
| 102 } |
| 103 }).catch(() => |
| 104 { |
| 105 // prefs.json is expected to be missing, ignore file reading errors |
| 106 }).then(() => |
| 107 { |
105 Prefs.initialized = true; | 108 Prefs.initialized = true; |
106 if (typeof Prefs._initListener == "function") | 109 if (typeof Prefs._initListener == "function") |
107 Prefs._initListener(); | 110 Prefs._initListener(); |
108 }); | 111 }); |
109 } | 112 } |
110 | 113 |
111 function save() | 114 function save() |
112 { | 115 { |
113 if (isSaving) | 116 if (isSaving) |
114 { | 117 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 defaults[key] = _preconfiguredPrefs[key]; | 152 defaults[key] = _preconfiguredPrefs[key]; |
150 | 153 |
151 // Define defaults | 154 // Define defaults |
152 for (let key in defaults) | 155 for (let key in defaults) |
153 defineProperty(key); | 156 defineProperty(key); |
154 | 157 |
155 // Set values of prefs based on defaults | 158 // Set values of prefs based on defaults |
156 values = Object.create(defaults); | 159 values = Object.create(defaults); |
157 | 160 |
158 load(); | 161 load(); |
OLD | NEW |