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

Side by Side Diff: lib/prefs.js

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Updated implementation. Created June 2, 2017, 3:49 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
OLDNEW
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 for (let key in data) 94 for (let key in data)
95 if (key in defaults) 95 if (key in defaults)
96 values[key] = data[key]; 96 values[key] = data[key];
97 } 97 }
98 catch (e) 98 catch (e)
99 { 99 {
100 Cu.reportError(e); 100 Cu.reportError(e);
101 } 101 }
102 } 102 }
103 103
104 Prefs.initialized = true;
104 if (typeof Prefs._initListener == "function") 105 if (typeof Prefs._initListener == "function")
105 Prefs._initListener(); 106 Prefs._initListener();
106 }); 107 });
107 } 108 }
108 109
109 function save() 110 function save()
110 { 111 {
111 if (isSaving) 112 if (isSaving)
112 { 113 {
113 isDirty = true; 114 isDirty = true;
114 return; 115 return;
115 } 116 }
116 117
117 isDirty = false; 118 isDirty = false;
118 isSaving = true; 119 isSaving = true;
119 _fileSystem.write(path, JSON.stringify(values), function() 120 _fileSystem.write(path, JSON.stringify(values), function()
120 { 121 {
121 isSaving = false; 122 isSaving = false;
122 if (isDirty) 123 if (isDirty)
123 save(); 124 save();
124 }); 125 });
125 } 126 }
126 127
127 let Prefs = exports.Prefs = { 128 let Prefs = exports.Prefs = {
129 initialized: false,
130
128 addListener: function(listener) 131 addListener: function(listener)
129 { 132 {
130 if (listeners.indexOf(listener) < 0) 133 if (listeners.indexOf(listener) < 0)
131 listeners.push(listener); 134 listeners.push(listener);
132 }, 135 },
133 136
134 removeListener: function(listener) 137 removeListener: function(listener)
135 { 138 {
136 let index = listeners.indexOf(listener); 139 let index = listeners.indexOf(listener);
137 if (index >= 0) 140 if (index >= 0)
138 listeners.splice(index, 1); 141 listeners.splice(index, 1);
139 }, 142 },
140 }; 143 };
141 144
142 // Update the default prefs with what was preconfigured 145 // Update the default prefs with what was preconfigured
143 for (let key in _preconfiguredPrefs) 146 for (let key in _preconfiguredPrefs)
144 if (preconfigurable.indexOf(key) != -1) 147 if (preconfigurable.indexOf(key) != -1)
145 defaults[key] = _preconfiguredPrefs[key]; 148 defaults[key] = _preconfiguredPrefs[key];
146 149
147 // Define defaults 150 // Define defaults
148 for (let key in defaults) 151 for (let key in defaults)
149 defineProperty(key); 152 defineProperty(key);
150 153
151 // Set values of prefs based on defaults 154 // Set values of prefs based on defaults
152 values = Object.create(defaults); 155 values = Object.create(defaults);
153 156
154 load(); 157 load();
OLDNEW
« lib/init.js ('K') | « lib/init.js ('k') | libadblockplus.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld