From 5bf9ac9fe61bd2aff8114fe34ea645b6185bb246 Mon Sep 17 00:00:00 2001 From: btzr-io Date: Fri, 4 Aug 2017 19:36:36 -0600 Subject: [PATCH] implement theme-system --- ui/dist/index.html | 2 +- ui/js/lbry.js | 1 + ui/js/page/settings/view.jsx | 32 +++++++++++++++++++++++++++++++- ui/js/util/getThemes.js | 20 ++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 ui/js/util/getThemes.js diff --git a/ui/dist/index.html b/ui/dist/index.html index d951dddd1..c5b675312 100644 --- a/ui/dist/index.html +++ b/ui/dist/index.html @@ -6,7 +6,7 @@ - + diff --git a/ui/js/lbry.js b/ui/js/lbry.js index e43a20b55..e66362088 100644 --- a/ui/js/lbry.js +++ b/ui/js/lbry.js @@ -19,6 +19,7 @@ let lbry = { customLighthouseServers: [], showDeveloperMenu: false, language: "en", + theme: "light", }, }; diff --git a/ui/js/page/settings/view.jsx b/ui/js/page/settings/view.jsx index d7646c476..9767a5efe 100644 --- a/ui/js/page/settings/view.jsx +++ b/ui/js/page/settings/view.jsx @@ -3,9 +3,12 @@ import { FormField, FormRow } from "component/form.js"; import SubHeader from "component/subHeader"; import lbry from "lbry.js"; import Link from "component/link"; - +import getThemes from "util/getThemes"; const { remote } = require("electron"); +const themes = getThemes(); +console.log(themes); + class SettingsPage extends React.PureComponent { constructor(props) { super(props); @@ -18,6 +21,7 @@ class SettingsPage extends React.PureComponent { showUnavailable: lbry.getClientSetting("showUnavailable"), language: lbry.getClientSetting("language"), clearingCache: false, + theme: lbry.getClientSetting("theme"), }; } @@ -81,6 +85,13 @@ class SettingsPage extends React.PureComponent { this.setDaemonSetting("disable_max_key_fee", isDisabled); } + onThemeChange(event) { + const value = event.target.value; + const link = document.getElementById("theme"); + link.href = `./themes/${value}.css`; + this.props.setClientSetting("theme", value); + } + // onMaxUploadPrefChange(isLimited) { // if (!isLimited) { // this.setDaemonSetting("max_upload", 0.0); @@ -251,6 +262,25 @@ class SettingsPage extends React.PureComponent { +
+
+

{__("Theme")}

+
+
+ + {themes.map((i, k) => + + )} + + +
+
+

{__("Application Cache")}

diff --git a/ui/js/util/getThemes.js b/ui/js/util/getThemes.js new file mode 100644 index 000000000..d82bc4d0c --- /dev/null +++ b/ui/js/util/getThemes.js @@ -0,0 +1,20 @@ +const { readdirSync } = require("fs"); +const { extname } = require("path"); +const { remote } = require("electron"); + +function getThemes() { + // Themes path + const themesPath = `${remote.app.getAppPath()}/dist/themes`; + + // Get all themes / only .css + const themes = readdirSync(themesPath).filter(function(file) { + return extname(file) === ".css"; + }); + + // Remove file extension (css) + return themes.map(function(theme) { + return theme.replace(".css", ""); + }); +} + +export default getThemes;