Skip to content

The open alternative to Salesforce, designed for AI.

[BUGFIX] Dynamic default body background depending on device preferences (#10626)

Paul Rastoind6171c66df5b
diff --git a/packages/twenty-front/index.html b/packages/twenty-front/index.html
index 33bf69175da..99ae9850d5f 100644
--- a/packages/twenty-front/index.html
+++ b/packages/twenty-front/index.html
@@ -3,7 +3,12 @@
<head>
<meta charset="UTF-8" />
- <link rel="icon" type="image/x-icon" href="/icons/android/android-launchericon-48-48.png" data-rh="true"/>
+ <link
+ rel="icon"
+ type="image/x-icon"
+ href="/icons/android/android-launchericon-48-48.png"
+ data-rh="true"
+ />
<link rel="apple-touch-icon" href="/icons/ios/192.png" />
<meta name="theme-color" content="#000000" />
@@ -42,9 +47,12 @@
const viewportMetadata = document.querySelector('meta[name=viewport]');
if (viewportMetadata !== null) {
- viewportMetadata.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0');
+ viewportMetadata.setAttribute(
+ 'content',
+ 'width=device-width, initial-scale=1.0, maximum-scale=1.0',
+ );
}
- }
+ };
const isIOS = /iPad|iPhone/.test(navigator.userAgent);
if (isIOS) {
@@ -52,9 +60,13 @@
}
</script>
</head>
- <body>
+ <body style="width: 100%; height: 100vh">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
+ <script
+ type="module"
+ src="/src/renderBodyOptimisticBackgroundBeforeAppBootstrap.ts"
+ ></script>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
diff --git a/packages/twenty-front/src/renderBodyOptimisticBackgroundBeforeAppBootstrap.ts b/packages/twenty-front/src/renderBodyOptimisticBackgroundBeforeAppBootstrap.ts
new file mode 100644
index 00000000000..573ca517d4f
--- /dev/null
+++ b/packages/twenty-front/src/renderBodyOptimisticBackgroundBeforeAppBootstrap.ts
@@ -0,0 +1,18 @@
+// TODO consume theme from twenty-ui after its migration as a package, at the moment the bunlde is too big
+// eslint-disable-next-line @nx/workspace-no-hardcoded-colors
+const THEME_LIGHT_BACKGROUND_TERTIARY = '#f1f1f1';
+// eslint-disable-next-line @nx/workspace-no-hardcoded-colors
+const THEME_DARK_BACKGROUND_TERTIARY = '#1d1d1d';
+
+// TODO should search in local storage for user last session appearance preferences
+const renderBodyOptimisticBackgroundBeforeAppBootstrap = () => {
+ const isDarkTheme =
+ window.matchMedia &&
+ window.matchMedia('(prefers-color-scheme: dark)').matches;
+ if (isDarkTheme) {
+ document.body.style.background = THEME_DARK_BACKGROUND_TERTIARY;
+ } else {
+ document.body.style.background = THEME_LIGHT_BACKGROUND_TERTIARY;
+ }
+};
+renderBodyOptimisticBackgroundBeforeAppBootstrap();