From 2ad7675c8b17a7c7a00b39ea241da28bf89380a5 Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Sat, 13 Apr 2019 19:23:58 +0200 Subject: [PATCH] Don't show default store in options on save (#96) --- src/options/interface.js | 3 --- src/options/options.js | 33 +++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/options/interface.js b/src/options/interface.js index e982875..1411fd8 100644 --- a/src/options/interface.js +++ b/src/options/interface.js @@ -20,9 +20,6 @@ function Interface(settings, saveSettings) { this.settings = settings; this.saveSettings = saveSettings; this.saveEnabled = false; - - // 'default' store must not be displayed or later attempted to be saved - delete this.settings.stores.default; } /** diff --git a/src/options/options.js b/src/options/options.js index a8fcb8d..ff5e165 100644 --- a/src/options/options.js +++ b/src/options/options.js @@ -27,6 +27,25 @@ function handleError(error, type = "error") { 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 * @@ -45,12 +64,7 @@ async function saveSettings(settings) { } // reload settings - var response = await chrome.runtime.sendMessage({ action: "getSettings" }); - if (response.status != "ok") { - throw new Error(response.message); - } - - return response.settings; + return await getSettings(); } /** @@ -62,12 +76,7 @@ async function saveSettings(settings) { */ async function run() { try { - var response = await chrome.runtime.sendMessage({ action: "getSettings" }); - if (response.status != "ok") { - throw new Error(response.message); - } - - var options = new Interface(response.settings, saveSettings); + var options = new Interface(await getSettings(), saveSettings); options.attach(document.body); } catch (e) { handleError(e);