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

Side by Side Diff: lib/prefs.js

Issue 11175032: Actually saving and loading the prefs (Closed)
Patch Set: Created July 22, 2013, 12:43 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/api.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 { 67 {
68 _fileSystem.read(path, function(result) 68 _fileSystem.read(path, function(result)
69 { 69 {
70 // prefs.json is expected to be missing, ignore errors reading file 70 // prefs.json is expected to be missing, ignore errors reading file
71 if (!result.error) 71 if (!result.error)
72 { 72 {
73 try 73 try
74 { 74 {
75 let data = JSON.parse(result.content); 75 let data = JSON.parse(result.content);
76 for (let key in data) 76 for (let key in data)
77 if (key in defaults)
78 values[key] = data[key]; 77 values[key] = data[key];
79 } 78 }
80 catch (e) 79 catch (e)
81 { 80 {
82 Cu.reportError(e); 81 Cu.reportError(e);
83 } 82 }
84 } 83 }
85 84
86 if (typeof Prefs._initListener == "function") 85 if (typeof Prefs._initListener == "function")
87 Prefs._initListener(); 86 Prefs._initListener();
88 }); 87 });
89 } 88 }
90 89
91 function save() 90 function save()
92 { 91 {
93 if (isSaving) 92 if (isSaving)
94 { 93 {
95 isDirty = true; 94 isDirty = true;
96 return; 95 return;
97 } 96 }
98
99 isDirty = false; 97 isDirty = false;
100 isSaving = true; 98 isSaving = true;
101 _fileSystem.write(path, JSON.stringify(values), function() 99 _fileSystem.write(path, JSON.stringify(values), function()
102 { 100 {
103 isSaving = false; 101 isSaving = false;
104 if (isDirty) 102 if (isDirty)
105 save(); 103 save();
106 }); 104 });
107 } 105 }
108 106
109 let Prefs = exports.Prefs = { 107 let Prefs = exports.Prefs = {
110 addListener: function(listener) 108 addListener: function(listener)
111 { 109 {
112 if (listeners.indexOf(listener) < 0) 110 if (listeners.indexOf(listener) < 0)
113 listeners.push(listener); 111 listeners.push(listener);
114 }, 112 },
115 113
116 removeListener: function(listener) 114 removeListener: function(listener)
117 { 115 {
118 let index = listeners.indexOf(listener); 116 let index = listeners.indexOf(listener);
119 if (index >= 0) 117 if (index >= 0)
120 listeners.splice(index, 1); 118 listeners.splice(index, 1);
121 }, 119 },
120 save: save,
121 values: values,
122 }; 122 };
123 123
124 for (let key in defaults) 124 for (let key in defaults)
125 defineProperty(key); 125 defineProperty(key);
Wladimir Palant 2013/07/22 06:45:47 This is where a property is defined for each pref.
126 126
127 load(); 127 load();
OLDNEW
« no previous file with comments | « lib/api.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld