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

Unified Diff: lib/prefs.js

Issue 29545700: Issue 5685 - Pass ESLint (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Address review comments Created Sept. 18, 2017, 12:42 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/notificationShowRegistration.js ('k') | lib/updater.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/prefs.js
===================================================================
--- a/lib/prefs.js
+++ b/lib/prefs.js
@@ -10,16 +10,18 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+"use strict";
+
//
// The values are hardcoded for now.
//
let defaults = {
__proto__: null,
enabled: true,
patternsbackups: 5,
@@ -42,51 +44,52 @@
notificationurl: "https://notification.adblockplus.org/notification.json",
suppress_first_run_page: false,
disable_auto_updates: false,
first_run_subscription_auto_select: true,
notifications_ignoredcategories: [],
allowed_connection_type: ""
};
-let preconfigurable = ["suppress_first_run_page", "disable_auto_updates",
+let preconfigurable = [
+ "suppress_first_run_page", "disable_auto_updates",
"first_run_subscription_auto_select", "allowed_connection_type"];
let values;
let prefsFileName = "prefs.json";
let listeners = [];
let isDirty = false;
let isSaving = false;
function defineProperty(key)
{
Object.defineProperty(Prefs, key,
- {
- get: () => values[key],
- set: function(value)
{
- if (typeof value != typeof defaults[key])
- throw new Error("Attempt to change preference type");
+ get: () => values[key],
+ set(value)
+ {
+ if (typeof value != typeof defaults[key])
+ throw new Error("Attempt to change preference type");
- if (value == defaults[key])
- delete values[key];
- else
- values[key] = value;
- save();
+ if (value == defaults[key])
+ delete values[key];
+ else
+ values[key] = value;
+ save();
- for (let listener of listeners)
- listener(key);
- },
- enumerable: true
- });
+ for (let listener of listeners)
+ listener(key);
+ },
+ enumerable: true
+ });
}
function load()
{
- _fileSystem.read(prefsFileName, function (result)
+ _fileSystem.read(prefsFileName, result =>
{
// prefs.json is expected to be missing, ignore errors reading file
if (!result.error)
{
try
{
let data = JSON.parse(result.content);
for (let key in data)
@@ -110,39 +113,39 @@
if (isSaving)
{
isDirty = true;
return;
}
isDirty = false;
isSaving = true;
- _fileSystem.write(prefsFileName, JSON.stringify(values), function ()
+ _fileSystem.write(prefsFileName, JSON.stringify(values), () =>
{
isSaving = false;
if (isDirty)
save();
});
}
let Prefs = exports.Prefs = {
initialized: false,
- addListener: function(listener)
+ addListener(listener)
{
if (listeners.indexOf(listener) < 0)
listeners.push(listener);
},
- removeListener: function(listener)
+ removeListener(listener)
{
let index = listeners.indexOf(listener);
if (index >= 0)
listeners.splice(index, 1);
- },
+ }
};
// Update the default prefs with what was preconfigured
for (let key in _preconfiguredPrefs)
if (preconfigurable.indexOf(key) != -1)
defaults[key] = _preconfiguredPrefs[key];
// Define defaults
« no previous file with comments | « lib/notificationShowRegistration.js ('k') | lib/updater.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld