diff --git a/src/actions/SupportActions.js b/src/actions/SupportActions.js index f4cfaf5..52b1bb2 100644 --- a/src/actions/SupportActions.js +++ b/src/actions/SupportActions.js @@ -4,7 +4,8 @@ export default alt.createActions(class SupportActions { constructor() { this.generateActions( 'isChrome', - 'noSupport' + 'noSupport', + 'themeChange', ) } }) diff --git a/src/client.js b/src/client.js index 6bff7ff..6887a5a 100644 --- a/src/client.js +++ b/src/client.js @@ -11,12 +11,20 @@ let bootstrap = document.getElementById("bootstrap").innerHTML; alt.bootstrap(bootstrap); window.FilePizza = () => { - ReactRouter.run(routes, ReactRouter.HistoryLocation, function(Handler) { + ReactRouter.run(routes, ReactRouter.HistoryLocation, function (Handler) { React.render(, document); }); if (!webrtcSupport.support) SupportActions.noSupport(); + let theme = localStorage.getItem("theme") + if (theme != "") { + SupportActions.themeChange(theme) + } else { + let prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches + SupportActions.themeChange(prefersDark ? "dark" : "light") + } + let isChrome = navigator.userAgent.toLowerCase().indexOf("chrome") > -1; if (isChrome) SupportActions.isChrome(); }; diff --git a/src/components/App.js b/src/components/App.js index 4ca3f07..f9bbc35 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -3,6 +3,7 @@ import ErrorPage from "./ErrorPage"; import FrozenHead from "react-frozenhead"; import React from "react"; import SupportStore from "../stores/SupportStore"; +import SupportActions from "../actions/SupportActions"; import { RouteHandler } from "react-router"; import ga from "react-google-analytics"; @@ -21,6 +22,16 @@ export default class App extends React.Component { }; } + toggleTheme(e) { + e.preventDefault() + + if (this.state.theme == "dark") { + SupportActions.themeChange("light") + } else { + SupportActions.themeChange("dark") + } + } + componentDidMount() { SupportStore.listen(this._onChange); } @@ -56,7 +67,7 @@ export default class App extends React.Component {