Skip to content

Commit

Permalink
Settings to control disabled features
Browse files Browse the repository at this point in the history
  • Loading branch information
lautis committed Apr 5, 2018
1 parent 6602691 commit 7049116
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/Settings.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>DefaultValue</key>
<string>show-recently-pushed-branches</string>
<key>Key</key>
<string>disabledFeatures</string>
<key>Title</key>
<string>Disabled features</string>
<key>Titles</key>
<array>
<string></string>
</array>
<key>Type</key>
<string>TextField</string>
</dict>
</array>
</plist>
25 changes: 20 additions & 5 deletions src/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,35 @@
}
};

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 {};
}
};

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));

Expand Down

0 comments on commit 7049116

Please sign in to comment.