Web: Client: Common: Utils: Added getSystemTheme for detecting system theme on desktop editors

This commit is contained in:
Ilya Oleshko 2023-06-23 17:48:15 +03:00
parent c9fced08de
commit 257d7d4f7e

View File

@ -17,7 +17,7 @@ import BackgroundPatternBlackReactSvgUrl from "PUBLIC_DIR/images/background.patt
import moment from "moment";
import { LANGUAGE } from "../constants";
import { LANGUAGE, ThemeKeys } from "../constants";
import sjcl from "sjcl";
import { isMobile } from "react-device-detect";
import TopLoaderService from "@docspace/components/top-loading-indicator";
@ -547,3 +547,15 @@ export const getFileExtension = (fileTitle: string) => {
const posExt = fileTitle.lastIndexOf(".");
return 0 <= posExt ? fileTitle.substring(posExt).trim().toLowerCase() : "";
};
export const getSystemTheme = () => {
const isDesktopClient = window["AscDesktopEditor"] !== undefined;
return isDesktopClient
? window?.RendererProcessVariable?.theme?.type === "dark"
? ThemeKeys.DarkStr
: ThemeKeys.BaseStr
: window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
? ThemeKeys.DarkStr
: ThemeKeys.BaseStr;
};