implement initial fallback for missing theme

load last theme selected
This commit is contained in:
btzr-io 2017-08-12 12:46:10 -06:00
parent beffda09bd
commit c9c50349b8
3 changed files with 31 additions and 6 deletions

View file

@ -8,6 +8,7 @@ import store from "store.js";
import SplashScreen from "component/splash"; import SplashScreen from "component/splash";
import { doChangePath, doNavigate, doDaemonReady } from "actions/app"; import { doChangePath, doNavigate, doDaemonReady } from "actions/app";
import { toQueryString } from "util/query_params"; import { toQueryString } from "util/query_params";
import setTheme from "util/setTheme";
import * as types from "constants/action_types"; import * as types from "constants/action_types";
const env = ENV; const env = ENV;
@ -71,6 +72,9 @@ document.addEventListener("click", event => {
} }
}); });
// Load initial theme
setTheme(lbry.getClientSetting("theme"));
const application = remote.app; const application = remote.app;
const dock = application.dock; const dock = application.dock;
const win = remote.getCurrentWindow(); const win = remote.getCurrentWindow();

View file

@ -6,6 +6,7 @@ import lbry from "lbry.js";
import Link from "component/link"; import Link from "component/link";
import FormFieldPrice from "component/formFieldPrice"; import FormFieldPrice from "component/formFieldPrice";
import { remote } from "electron"; import { remote } from "electron";
import setTheme from "util/setTheme";
class SettingsPage extends React.PureComponent { class SettingsPage extends React.PureComponent {
constructor(props) { constructor(props) {
@ -38,7 +39,7 @@ class SettingsPage extends React.PureComponent {
} }
getThemes() { getThemes() {
const themes = this.props.getThemes().data.themes; const { themes } = this.props.getThemes().data;
this.setState({ themes }); this.setState({ themes });
} }
@ -51,6 +52,11 @@ class SettingsPage extends React.PureComponent {
this._onSettingSaveSuccess(); this._onSettingSaveSuccess();
} }
setTheme(value) {
setTheme(value);
this.props.setClientSetting("theme", value);
}
onRunOnStartChange(event) { onRunOnStartChange(event) {
this.setDaemonSetting("run_on_startup", event.target.checked); this.setDaemonSetting("run_on_startup", event.target.checked);
} }
@ -72,11 +78,8 @@ class SettingsPage extends React.PureComponent {
} }
onThemeChange(event) { onThemeChange(event) {
// Todo: Add better way to handle this const { value } = event.target;
const value = event.target.value; this.setTheme(value);
const link = document.getElementById("theme");
link.href = `./themes/${value}.css`;
this.props.setClientSetting("theme", value);
} }
// onMaxUploadPrefChange(isLimited) { // onMaxUploadPrefChange(isLimited) {

18
ui/js/util/setTheme.js Normal file
View file

@ -0,0 +1,18 @@
import lbry from "lbry";
import { existsSync } from "fs";
import { remote } from "electron";
function setTheme(name) {
const link = document.getElementById("theme");
const file = `${name}.css`;
const path = `${remote.app.getAppPath()}/dist/themes/${file}`;
if (existsSync(path)) {
link.href = `./themes/${file}`;
lbry.setClientSetting("theme", name);
} else {
lbry.setClientSetting("theme", "light");
}
}
export default setTheme;