2 Copyright (C) 2019 Kai Uwe Broulik <kde@privat.broulik.de>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 3 of
7 the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 return (IS_FIREFOX ? chrome.storage.local : chrome.storage.sync);
24 return new Promise((resolve, reject) => {
25 SettingsUtils.storage().get(null /* get all */, (items) => {
26 const error = chrome.runtime.lastError;
31 // Passing a default Object get() only returns defaults for the top level of the object,
32 // so we need to merge the level underneath manually.
33 const addObjectInto = (obj, add) => {
34 if (typeof add !== "object" || Array.isArray(add)) {
38 Object.keys(add).forEach((key) => {
39 if (obj.hasOwnProperty(key)) {
40 addObjectInto(obj[key], add[key]);
47 addObjectInto(items, DEFAULT_EXTENSION_SETTINGS);
53 static set(settings) {
54 return new Promise((resolve, reject) => {
56 SettingsUtils.storage().set(settings, () => {
57 const error = chrome.runtime.lastError;
71 return chrome.storage.onChanged;