Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,45 @@
-->
<title>Internxt Drive – Private & Secure Cloud Storage</title>

<style>
html.dark,
html.dark body {
background-color: #111;
color-scheme: dark;
}
</style>
<script>
(function () {
try {
var storedTheme = localStorage.getItem('theme');
var persistedIsDark = localStorage.getItem('theme:isDark');
var systemPrefersDark = false;

try {
systemPrefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
} catch (matchError) {
systemPrefersDark = false;
}

var theme = storedTheme || 'system';
var shouldUseDark = false;

if (persistedIsDark !== null) {
shouldUseDark = JSON.parse(persistedIsDark);
} else {
shouldUseDark =
theme === 'dark' ||
(theme === 'system' && systemPrefersDark) ||
(theme !== 'system' && theme !== 'light');
}

if (shouldUseDark) {
document.documentElement.classList.add('dark');
}
} catch (error) {}
})();
</script>

<script src="https://www.google.com/recaptcha/api.js?render=%REACT_APP_RECAPTCHA_V3%"></script>
<script src="https://www.googletagmanager.com/gtag/js?id=%REACT_APP_GA_ID%"></script>
<script>
Expand Down
1 change: 1 addition & 0 deletions src/app/core/services/local-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function clear(): void {
localStorage.removeItem('workspace');
localStorage.removeItem('language');
localStorage.removeItem('showSummerBanner');
localStorage.removeItem('theme:isDark');
localStorage.removeItem('xInvitedToken');
localStorage.removeItem('xResourcesToken');
localStorage.removeItem(STORAGE_KEYS.B2B_WORKSPACE);
Expand Down
12 changes: 12 additions & 0 deletions src/app/theme/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {

const toggleTheme = (theme: Theme) => setCurrentTheme(theme);

const persistDarkTheme = (value: boolean) => {
localStorageService.set('theme:isDark', value ? 'true' : 'false');
};

useEffect(() => {
const stored = localStorageService.get('theme') as Theme | null;
const defaultTheme = stored ?? 'system';
Expand All @@ -93,6 +97,7 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
root.style.backgroundImage = 'none';
document.documentElement.classList.add('dark');
setCheckoutTheme('dark');
persistDarkTheme(true);
return;
}

Expand All @@ -109,15 +114,22 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
if (config.darkMode) {
document.documentElement.classList.add('dark');
setCheckoutTheme('dark');
persistDarkTheme(true);
return;
}

document.documentElement.classList.remove('dark');
setCheckoutTheme('light');
persistDarkTheme(false);

return;
}

// fallback to light theme
root.style.backgroundImage = 'none';
document.documentElement.classList.remove('dark');
setCheckoutTheme('light');
persistDarkTheme(false);
};

updateTheme();
Expand Down
Loading