From 2511c310f13e8723a905078a69e47935a2acb2d4 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Thu, 15 Jun 2023 06:32:36 -0400 Subject: [PATCH] Added settings to choose desired UI theme. --- bazarr/app/config.py | 1 + frontend/src/App/theme.tsx | 15 ++++++++++++++- frontend/src/pages/Settings/UI/index.tsx | 12 ++++++++++-- frontend/src/pages/Settings/UI/options.ts | 15 +++++++++++++++ frontend/src/types/settings.d.ts | 1 + 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/bazarr/app/config.py b/bazarr/app/config.py index b04ca93c3..4ffea8761 100644 --- a/bazarr/app/config.py +++ b/bazarr/app/config.py @@ -52,6 +52,7 @@ defaults = { 'movie_default_enabled': 'False', 'movie_default_profile': '', 'page_size': '25', + 'theme': 'auto', 'page_size_manual_search': '10', 'minimum_score_movie': '70', 'use_embedded_subs': 'True', diff --git a/frontend/src/App/theme.tsx b/frontend/src/App/theme.tsx index 0fe2be9d5..947b4f7a8 100644 --- a/frontend/src/App/theme.tsx +++ b/frontend/src/App/theme.tsx @@ -1,3 +1,4 @@ +import { useSystemSettings } from "@/apis/hooks"; import { ColorScheme, ColorSchemeProvider, @@ -34,7 +35,19 @@ const theme: MantineThemeOverride = { }; function useAutoColorScheme() { - const preferredColorScheme = useColorScheme(); + const settings = useSystemSettings(); + const settingsColorScheme = settings.data?.general.theme; + + let preferredColorScheme: ColorScheme = useColorScheme(); + switch (settingsColorScheme) { + case "light": + preferredColorScheme = "light" as ColorScheme; + break; + case "dark": + preferredColorScheme = "dark" as ColorScheme; + break; + } + const [colorScheme, setColorScheme] = useState(preferredColorScheme); // automatically switch dark/light theme diff --git a/frontend/src/pages/Settings/UI/index.tsx b/frontend/src/pages/Settings/UI/index.tsx index 9cb2de367..c7b6ada1b 100644 --- a/frontend/src/pages/Settings/UI/index.tsx +++ b/frontend/src/pages/Settings/UI/index.tsx @@ -1,12 +1,12 @@ import { uiPageSizeKey } from "@/utilities/storage"; import { FunctionComponent } from "react"; import { Layout, Section, Selector } from "../components"; -import { pageSizeOptions } from "./options"; +import { colorSchemeOptions, pageSizeOptions } from "./options"; const SettingsUIView: FunctionComponent = () => { return ( -
+
{ defaultValue={50} >
+
+ +
); }; diff --git a/frontend/src/pages/Settings/UI/options.ts b/frontend/src/pages/Settings/UI/options.ts index 57c79c588..47687c657 100644 --- a/frontend/src/pages/Settings/UI/options.ts +++ b/frontend/src/pages/Settings/UI/options.ts @@ -26,3 +26,18 @@ export const pageSizeOptions: SelectorOption[] = [ value: 1000, }, ]; + +export const colorSchemeOptions: SelectorOption[] = [ + { + label: "Auto", + value: "auto", + }, + { + label: "Light", + value: "light", + }, + { + label: "Dark", + value: "dark", + }, +]; diff --git a/frontend/src/types/settings.d.ts b/frontend/src/types/settings.d.ts index 127386118..dc4ed89b5 100644 --- a/frontend/src/types/settings.d.ts +++ b/frontend/src/types/settings.d.ts @@ -57,6 +57,7 @@ declare namespace Settings { path_mappings: [string, string][]; path_mappings_movie: [string, string][]; page_size: number; + theme: string; port: number; upgrade_subs: boolean; postprocessing_cmd?: string;