Don't show default store in options on save (#96)

This commit is contained in:
Maxim Baz
2019-04-13 19:23:58 +02:00
committed by GitHub
parent 0a06ba6009
commit 2ad7675c8b
2 changed files with 21 additions and 15 deletions

View File

@@ -20,9 +20,6 @@ function Interface(settings, saveSettings) {
this.settings = settings; this.settings = settings;
this.saveSettings = saveSettings; this.saveSettings = saveSettings;
this.saveEnabled = false; this.saveEnabled = false;
// 'default' store must not be displayed or later attempted to be saved
delete this.settings.stores.default;
} }
/** /**

View File

@@ -27,6 +27,25 @@ function handleError(error, type = "error") {
document.body.appendChild(errorNode); document.body.appendChild(errorNode);
} }
/**
* Get settings
*
* @since 3.0.9
*
* @return object Settings object
*/
async function getSettings() {
var response = await chrome.runtime.sendMessage({ action: "getSettings" });
if (response.status != "ok") {
throw new Error(response.message);
}
// 'default' store must not be displayed or later attempted to be saved
delete response.settings.stores.default;
return response.settings;
}
/** /**
* Save settings * Save settings
* *
@@ -45,12 +64,7 @@ async function saveSettings(settings) {
} }
// reload settings // reload settings
var response = await chrome.runtime.sendMessage({ action: "getSettings" }); return await getSettings();
if (response.status != "ok") {
throw new Error(response.message);
}
return response.settings;
} }
/** /**
@@ -62,12 +76,7 @@ async function saveSettings(settings) {
*/ */
async function run() { async function run() {
try { try {
var response = await chrome.runtime.sendMessage({ action: "getSettings" }); var options = new Interface(await getSettings(), saveSettings);
if (response.status != "ok") {
throw new Error(response.message);
}
var options = new Interface(response.settings, saveSettings);
options.attach(document.body); options.attach(document.body);
} catch (e) { } catch (e) {
handleError(e); handleError(e);