diff --git a/src/Settings.plist b/src/Settings.plist new file mode 100644 index 0000000..c5d28a3 --- /dev/null +++ b/src/Settings.plist @@ -0,0 +1,20 @@ + + + + + + DefaultValue + show-recently-pushed-branches + Key + disabledFeatures + Title + Disabled features + Titles + + + + Type + TextField + + + diff --git a/src/global.html b/src/global.html index 3c95851..8ed3045 100644 --- a/src/global.html +++ b/src/global.html @@ -32,12 +32,23 @@ } }; + const injectSettings = (namespace, data) => { + if (namespace === "sync") { + return { + ...data, + options: { + ...(data.options || {}), + disabledFeatures: safari.extension.settings.disabledFeatures + } + }; + } else { + return data; + } + }; + const safeParse = data => { try { - const parsed = JSON.parse(data) || {}; - parsed.options = parsed.options || {}; - parsed.options.disabledFeatures = parsed.options.disabledFeatures || "show-recently-pushed-branches"; - return parsed; + return JSON.parse(data) || {}; } catch { return {}; } @@ -45,7 +56,11 @@ const localStorageKey = namespace => `refined-github:${namespace}`; const readLocalStorage = namespace => - safeParse(localStorage.getItem(localStorageKey(namespace))); + injectSettings( + namespace, + safeParse(localStorage.getItem(localStorageKey(namespace))) + ); + const writeLocalStorage = (namespace, data) => localStorage.setItem(localStorageKey(namespace), JSON.stringify(data));