From 257d7d4f7eefd043cf621860dc3c32ac3c424e53 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Fri, 23 Jun 2023 17:48:15 +0300 Subject: [PATCH] Web: Client: Common: Utils: Added getSystemTheme for detecting system theme on desktop editors --- packages/common/utils/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/common/utils/index.ts b/packages/common/utils/index.ts index 512a144482..9984823aff 100644 --- a/packages/common/utils/index.ts +++ b/packages/common/utils/index.ts @@ -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; +};