Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 }; | 45 }; |
46 | 46 |
47 let values = Object.create(defaults); | 47 let values = Object.create(defaults); |
48 let path = _fileSystem.resolve("prefs.json"); | 48 let path = _fileSystem.resolve("prefs.json"); |
49 let listeners = []; | 49 let listeners = []; |
50 let isDirty = false; | 50 let isDirty = false; |
51 let isSaving = false; | 51 let isSaving = false; |
52 | 52 |
53 function defineProperty(key) | 53 function defineProperty(key) |
54 { | 54 { |
55 Prefs.__defineGetter__(key, function() { return values[key] }); | 55 Object.defineProperty(Prefs, key, |
Felix Dahlke
2015/04/29 16:47:38
Had to change this - jshydra doesn't handle functi
Wladimir Palant
2015/04/29 17:42:57
Why not change it into |() => values[key]|? Note t
Felix Dahlke
2015/04/30 05:06:11
Done.
| |
56 Prefs.__defineSetter__(key, function(value) | |
57 { | 56 { |
58 if (typeof value != typeof defaults[key]) | 57 get: () => values[key], |
59 throw new Error("Attempt to change preference type"); | 58 set: function(value) |
59 { | |
60 if (typeof value != typeof defaults[key]) | |
61 throw new Error("Attempt to change preference type"); | |
60 | 62 |
61 if (value == defaults[key]) | 63 if (value == defaults[key]) |
62 delete values[key]; | 64 delete values[key]; |
63 else | 65 else |
64 values[key] = value; | 66 values[key] = value; |
65 save(); | 67 save(); |
66 | 68 |
67 for (let listener of listeners) | 69 for (let listener of listeners) |
68 listener(key); | 70 listener(key); |
71 }, | |
72 enumerable: true | |
69 }); | 73 }); |
70 } | 74 } |
71 | 75 |
72 function load() | 76 function load() |
73 { | 77 { |
74 _fileSystem.read(path, function(result) | 78 _fileSystem.read(path, function(result) |
75 { | 79 { |
76 // prefs.json is expected to be missing, ignore errors reading file | 80 // prefs.json is expected to be missing, ignore errors reading file |
77 if (!result.error) | 81 if (!result.error) |
78 { | 82 { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 let index = listeners.indexOf(listener); | 128 let index = listeners.indexOf(listener); |
125 if (index >= 0) | 129 if (index >= 0) |
126 listeners.splice(index, 1); | 130 listeners.splice(index, 1); |
127 }, | 131 }, |
128 }; | 132 }; |
129 | 133 |
130 for (let key in defaults) | 134 for (let key in defaults) |
131 defineProperty(key); | 135 defineProperty(key); |
132 | 136 |
133 load(); | 137 load(); |
LEFT | RIGHT |