| Left: | ||
| Right: |
| 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-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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 // | 18 // |
| 19 // The values are hardcoded for now. | 19 // The values are hardcoded for now. |
| 20 // | 20 // |
| 21 | 21 |
| 22 let defaults = { | 22 let defaults = { |
| 23 __proto__: null, | 23 __proto__: null, |
| 24 enabled: true, | 24 enabled: true, |
| 25 patternsfile: "patterns.ini", | |
|
sergei
2017/08/11 12:49:39
now it's hardcoded in adblockpluscore/lib/filtersS
| |
| 26 patternsbackups: 5, | 25 patternsbackups: 5, |
| 27 patternsbackupinterval: 24, | 26 patternsbackupinterval: 24, |
| 28 data_directory: "", | |
| 29 savestats: false, | 27 savestats: false, |
| 30 privateBrowsing: false, | 28 privateBrowsing: false, |
| 31 subscriptions_fallbackerrors: 5, | 29 subscriptions_fallbackerrors: 5, |
| 32 subscriptions_fallbackurl: "https://adblockplus.org/getSubscription?version=%V ERSION%&url=%SUBSCRIPTION%&downloadURL=%URL%&error=%ERROR%&channelStatus=%CHANNE LSTATUS%&responseStatus=%RESPONSESTATUS%", | 30 subscriptions_fallbackurl: "https://adblockplus.org/getSubscription?version=%V ERSION%&url=%SUBSCRIPTION%&downloadURL=%URL%&error=%ERROR%&channelStatus=%CHANNE LSTATUS%&responseStatus=%RESPONSESTATUS%", |
| 33 subscriptions_autoupdate: true, | 31 subscriptions_autoupdate: true, |
| 34 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/excep tionrules.txt", | 32 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/excep tionrules.txt", |
| 35 documentation_link: "https://adblockplus.org/redirect?link=%LINK%&lang=%LANG%" , | 33 documentation_link: "https://adblockplus.org/redirect?link=%LINK%&lang=%LANG%" , |
| 36 update_url_release: "https://update.adblockplus.org/%NAME%/update.json?type=%T YPE%", | 34 update_url_release: "https://update.adblockplus.org/%NAME%/update.json?type=%T YPE%", |
| 37 update_url_devbuild: "https://adblockplus.org/devbuilds/%NAME%/update.json?typ e=%TYPE%", | 35 update_url_devbuild: "https://adblockplus.org/devbuilds/%NAME%/update.json?typ e=%TYPE%", |
| 38 update_last_check: 0, | 36 update_last_check: 0, |
| 39 update_last_error: 0, | 37 update_last_error: 0, |
| 40 update_soft_expiration: 0, | 38 update_soft_expiration: 0, |
| 41 update_hard_expiration: 0, | 39 update_hard_expiration: 0, |
| 42 currentVersion: "0.0", | 40 currentVersion: "0.0", |
| 43 notificationdata: {}, | 41 notificationdata: {}, |
| 44 notificationurl: "https://notification.adblockplus.org/notification.json", | 42 notificationurl: "https://notification.adblockplus.org/notification.json", |
| 45 suppress_first_run_page: false, | 43 suppress_first_run_page: false, |
| 46 disable_auto_updates: false, | 44 disable_auto_updates: false, |
| 47 first_run_subscription_auto_select: true, | 45 first_run_subscription_auto_select: true, |
| 48 notifications_ignoredcategories: [], | 46 notifications_ignoredcategories: [], |
| 49 allowed_connection_type: "" | 47 allowed_connection_type: "" |
| 50 }; | 48 }; |
| 51 | 49 |
| 52 let preconfigurable = ["suppress_first_run_page", "disable_auto_updates", | 50 let preconfigurable = ["suppress_first_run_page", "disable_auto_updates", |
| 53 "first_run_subscription_auto_select", "allowed_connection_type"]; | 51 "first_run_subscription_auto_select", "allowed_connection_type"]; |
| 54 | 52 |
| 55 let values; | 53 let values; |
| 56 let path = _fileSystem.resolve("prefs.json"); | 54 let prefsFileName = "prefs.json"; |
|
sergei
2017/08/11 12:49:39
it's renamed because file system does not support
| |
| 57 let listeners = []; | 55 let listeners = []; |
| 58 let isDirty = false; | 56 let isDirty = false; |
| 59 let isSaving = false; | 57 let isSaving = false; |
| 60 | 58 |
| 61 function defineProperty(key) | 59 function defineProperty(key) |
| 62 { | 60 { |
| 63 Object.defineProperty(Prefs, key, | 61 Object.defineProperty(Prefs, key, |
| 64 { | 62 { |
| 65 get: () => values[key], | 63 get: () => values[key], |
| 66 set: function(value) | 64 set: function(value) |
| 67 { | 65 { |
| 68 if (typeof value != typeof defaults[key]) | 66 if (typeof value != typeof defaults[key]) |
| 69 throw new Error("Attempt to change preference type"); | 67 throw new Error("Attempt to change preference type"); |
| 70 | 68 |
| 71 if (value == defaults[key]) | 69 if (value == defaults[key]) |
| 72 delete values[key]; | 70 delete values[key]; |
| 73 else | 71 else |
| 74 values[key] = value; | 72 values[key] = value; |
| 75 save(); | 73 save(); |
| 76 | 74 |
| 77 for (let listener of listeners) | 75 for (let listener of listeners) |
| 78 listener(key); | 76 listener(key); |
| 79 }, | 77 }, |
| 80 enumerable: true | 78 enumerable: true |
| 81 }); | 79 }); |
| 82 } | 80 } |
| 83 | 81 |
| 84 function load() | 82 function load() |
| 85 { | 83 { |
| 86 _fileSystem.read(path, function(result) | 84 _fileSystem.read(prefsFileName, function (result) |
| 87 { | 85 { |
| 88 // prefs.json is expected to be missing, ignore errors reading file | 86 // prefs.json is expected to be missing, ignore errors reading file |
| 89 if (!result.error) | 87 if (!result.error) |
| 90 { | 88 { |
| 91 try | 89 try |
| 92 { | 90 { |
| 93 let data = JSON.parse(result.content); | 91 let data = JSON.parse(result.content); |
| 94 for (let key in data) | 92 for (let key in data) |
| 95 if (key in defaults) | 93 if (key in defaults) |
| 96 values[key] = data[key]; | 94 values[key] = data[key]; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 110 function save() | 108 function save() |
| 111 { | 109 { |
| 112 if (isSaving) | 110 if (isSaving) |
| 113 { | 111 { |
| 114 isDirty = true; | 112 isDirty = true; |
| 115 return; | 113 return; |
| 116 } | 114 } |
| 117 | 115 |
| 118 isDirty = false; | 116 isDirty = false; |
| 119 isSaving = true; | 117 isSaving = true; |
| 120 _fileSystem.write(path, JSON.stringify(values), function() | 118 _fileSystem.write(prefsFileName, JSON.stringify(values), function () |
| 121 { | 119 { |
| 122 isSaving = false; | 120 isSaving = false; |
| 123 if (isDirty) | 121 if (isDirty) |
| 124 save(); | 122 save(); |
| 125 }); | 123 }); |
| 126 } | 124 } |
| 127 | 125 |
| 128 let Prefs = exports.Prefs = { | 126 let Prefs = exports.Prefs = { |
| 129 initialized: false, | 127 initialized: false, |
| 130 | 128 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 148 defaults[key] = _preconfiguredPrefs[key]; | 146 defaults[key] = _preconfiguredPrefs[key]; |
| 149 | 147 |
| 150 // Define defaults | 148 // Define defaults |
| 151 for (let key in defaults) | 149 for (let key in defaults) |
| 152 defineProperty(key); | 150 defineProperty(key); |
| 153 | 151 |
| 154 // Set values of prefs based on defaults | 152 // Set values of prefs based on defaults |
| 155 values = Object.create(defaults); | 153 values = Object.create(defaults); |
| 156 | 154 |
| 157 load(); | 155 load(); |
| OLD | NEW |