blob: f83d8072a6d54a5285265a6c3cfa73780972298f [file] [log] [blame]
avm99963cbea3142019-03-28 00:48:15 +01001function isEmpty(obj) {
2 return Object.keys(obj).length === 0;
3}
4
avm99963adf90862020-04-12 13:27:45 +02005const defaultOptions = {
avm99963122dc9b2019-03-30 18:44:18 +01006 "list": true,
7 "thread": true,
avm999636d9c5fe2019-06-04 00:35:53 +02008 "threadall": false,
avm99963122dc9b2019-03-30 18:44:18 +01009 "fixedtoolbar": false,
10 "redirect": false,
avm999636d9c5fe2019-06-04 00:35:53 +020011 "history": false,
avm99963af7860e2019-06-04 03:33:26 +020012 "loaddrafts": false,
avm99963c19497f2019-08-23 00:15:11 +020013 "batchduplicate": false,
avm99963eb2d0b82019-10-07 22:58:55 +020014 "escalatethreads": false,
avm99963ae6a26d2020-04-12 14:03:51 +020015 "movethreads": false,
16 "increasecontrast": false
avm99963122dc9b2019-03-30 18:44:18 +010017};
18
19function cleanUpOptions() {
20 chrome.storage.sync.get(null, function(options) {
avm999630a2840d2019-03-30 22:00:24 +010021 console.log("[cleanUpOptions] Previous options", options);
avm99963122dc9b2019-03-30 18:44:18 +010022 var ok = true;
23 for (const [opt, value] of Object.entries(defaultOptions)) {
avm999630a2840d2019-03-30 22:00:24 +010024 if (!(opt in options)) {
avm99963122dc9b2019-03-30 18:44:18 +010025 ok = false;
26 options[opt] = value;
27 }
28 }
29
avm999630a2840d2019-03-30 22:00:24 +010030 console.log("[cleanUpOptions] New options", options);
31
avm99963122dc9b2019-03-30 18:44:18 +010032 if (!ok) {
33 chrome.storage.sync.set(options);
avm99963cbea3142019-03-28 00:48:15 +010034 }
35 });
avm99963122dc9b2019-03-30 18:44:18 +010036}
37
38chrome.runtime.onInstalled.addListener(function(details) {
avm999630a2840d2019-03-30 22:00:24 +010039 if (details.reason == "install" || details.reason == "update") {
avm99963122dc9b2019-03-30 18:44:18 +010040 cleanUpOptions();
41 }
avm99963cbea3142019-03-28 00:48:15 +010042});