feat: can specify UI theme via /?theme=default and /?theme=dark (#2842)

* feat: set themeType through URL parameter

* Update App.js

---------

Co-authored-by: Eric Luo <hsluoyz@qq.com>
This commit is contained in:
xyt 2024-03-29 00:52:18 +08:00 committed by GitHub
parent d054f3e001
commit 5315f16a48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,6 +41,7 @@ setTwoToneColor("rgb(87,52,211)");
class App extends Component { class App extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.setThemeAlgorithm();
let storageThemeAlgorithm = []; let storageThemeAlgorithm = [];
try { try {
storageThemeAlgorithm = localStorage.getItem("themeAlgorithm") ? JSON.parse(localStorage.getItem("themeAlgorithm")) : ["default"]; storageThemeAlgorithm = localStorage.getItem("themeAlgorithm") ? JSON.parse(localStorage.getItem("themeAlgorithm")) : ["default"];
@ -157,6 +158,15 @@ class App extends Component {
return Setting.getLogo(themes); return Setting.getLogo(themes);
} }
setThemeAlgorithm() {
const currentUrl = window.location.href;
const url = new URL(currentUrl);
const themeType = url.searchParams.get("theme");
if (themeType === "dark" || themeType === "default") {
localStorage.setItem("themeAlgorithm", JSON.stringify([themeType]));
}
}
setLanguage(account) { setLanguage(account) {
const language = account?.language; const language = account?.language;
if (language !== null && language !== "" && language !== i18next.language) { if (language !== null && language !== "" && language !== i18next.language) {