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
131 changes: 131 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "socdof",
"private": true,
"version": "24.4.0",
"version": "24.6.2",
"description": "Strudel's Organization, Commerce & Documentation Offline Flow - Offline-first Windows ERP Desktop Suite & Web Workspace",
"author": "Yuri / Strudel",
"publisher": "Yuri / Strudel",
Expand Down
16 changes: 5 additions & 11 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useCallback } from 'react';
import React, { useState, useEffect, useCallback, useRef } from 'react';
import {
Contact,
Product,
Expand Down Expand Up @@ -121,11 +121,8 @@ export default function App() {
if (session && !session.locked) {
const user = getUserById(session.userId);
if (user) {
const media = window.matchMedia('(prefers-color-scheme: dark)');
const enableDark = nextMode === 'dark' || (nextMode !== 'light' && media.matches);
const userTheme = enableDark ? 'dark' : 'light';
if (user.preferences.theme !== userTheme) {
updateUserPreferences(user.id, { ...user.preferences, theme: userTheme });
if (user.preferences.theme !== nextMode) {
updateUserPreferences(user.id, { ...user.preferences, theme: nextMode });
}
}
}
Expand Down Expand Up @@ -397,11 +394,8 @@ export default function App() {
if (session && !session.locked) {
const user = getUserById(session.userId);
if (user) {
const media = window.matchMedia('(prefers-color-scheme: dark)');
const enableDark = updated.theme_mode === 'dark' || (updated.theme_mode !== 'light' && media.matches);
const userTheme = enableDark ? 'dark' : 'light';
if (user.preferences.theme !== userTheme) {
updateUserPreferences(user.id, { ...user.preferences, theme: userTheme });
if (user.preferences.theme !== updated.theme_mode) {
updateUserPreferences(user.id, { ...user.preferences, theme: updated.theme_mode });
}
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/components/AccountScopedWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ function applyUserAppearance(user: UserAccount | null): void {
} catch {
// ignore
}
} else if (user.preferences.theme === 'system') {
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
root.classList.toggle('dark', isDark);
root.style.colorScheme = isDark ? 'dark' : 'light';
try {
localStorage.removeItem('odoo_theme_dark');
} catch {
// ignore
}
}
// ACCENT COLOR: If the user account explicitly has an accent color preference, apply it.
// Otherwise, respect the saved system / company / localStorage accent color! DO NOT force 'indigo'!
Expand Down Expand Up @@ -162,20 +171,18 @@ export const AccountScopedWorkspace: React.FC<React.PropsWithChildren> = ({ chil
const account = session && !session.locked ? getUserById(session.userId) : null;
setActiveAccount(account);
};
const onAccentOrCompanyChanged = () => {
const onCompanyChanged = () => {
const session = getSession();
const account = session && !session.locked ? getUserById(session.userId) : null;
applyUserAppearance(account);
};
window.addEventListener(AUTH_CHANGE_EVENT_NAME, refreshAccount);
window.addEventListener('storage', refreshAccount);
window.addEventListener('socdof-company-updated', onAccentOrCompanyChanged);
window.addEventListener('socdof-accent-changed', onAccentOrCompanyChanged);
window.addEventListener('socdof-company-updated', onCompanyChanged);
return () => {
window.removeEventListener(AUTH_CHANGE_EVENT_NAME, refreshAccount);
window.removeEventListener('storage', refreshAccount);
window.removeEventListener('socdof-company-updated', onAccentOrCompanyChanged);
window.removeEventListener('socdof-accent-changed', onAccentOrCompanyChanged);
window.removeEventListener('socdof-company-updated', onCompanyChanged);
};
}, []);

Expand Down
Loading
Loading