Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

settings: opcion de tema "Sistema" que sigue el prefers-color-scheme del OS

Josevi7261403d2d0a
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index b413db01a..d31095722 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -28,9 +28,14 @@ import Admin from './views/Admin.jsx'
bindUI(useUI) // lets the shared controls open sheets without importing the store at module scope
+// theme === 'system' follows the OS/browser preference instead of a fixed choice.
+const resolveTheme = theme => theme === 'light' || theme === 'dark'
+ ? theme
+ : (window.matchMedia?.('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
+
function applyPrefs(theme, accent) {
const de = document.documentElement
- de.dataset.theme = theme === 'light' ? 'light' : 'dark'
+ de.dataset.theme = resolveTheme(theme)
de.dataset.accent = ACCENTS[accent] ? accent : 'lime'
const meta = document.querySelector('meta[name="theme-color"]')
if (meta) meta.content = de.dataset.theme === 'light' ? '#f2f2f7' : '#000000'
@@ -44,6 +49,16 @@ function Shell() {
const langV = useLang() // re-renders the whole shell when the language (pack) changes
useEffect(() => { setNav(navigate) }, [navigate])
useEffect(() => { applyPrefs(S.theme, S.accent) }, [S.theme, S.accent])
+ // 'system' needs to react live if the OS theme flips while the app is open, not just on
+ // the next mount — a fixed 'dark'/'light' choice never re-fires this since matchMedia
+ // isn't consulted for those.
+ useEffect(() => {
+ if (S.theme !== 'system' || !window.matchMedia) return
+ const mql = window.matchMedia('(prefers-color-scheme: dark)')
+ const onChange = () => applyPrefs(S.theme, S.accent)
+ mql.addEventListener('change', onChange)
+ return () => mql.removeEventListener('change', onChange)
+ }, [S.theme, S.accent])
useEffect(() => { setLang(S.lang || 'en') }, [S.lang])
useEffect(() => { document.documentElement.lang = S.lang || 'en' }, [langV, S.lang])
// every tab/route change starts at the top of the page
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index 9e1039e55..6050aa33c 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -274,6 +274,7 @@ export default {
'Theme': 'Tema',
'Dark': 'Oscuro',
'Light': 'Claro',
+ 'System': 'Sistema',
'Accent color': 'Color de acento',
'General': 'General',
'During a workout': 'Durante el entrenamiento',
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx
index 8630e8bbf..c56debe27 100644
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@ -153,8 +153,12 @@ export default function Settings() {
<Row icon="moon" iconTint="var(--indigo)" title={t('Theme')}>
<Segmented
className="seg-inline"
- options={[{ value: 'dark', icon: 'moon', label: t('Dark') }, { value: 'light', icon: 'sun', label: t('Light') }]}
- value={S.theme === 'light' ? 'light' : 'dark'}
+ options={[
+ { value: 'dark', icon: 'moon', label: t('Dark') },
+ { value: 'light', icon: 'sun', label: t('Light') },
+ { value: 'system', icon: 'gear', label: t('System') },
+ ]}
+ value={S.theme || 'dark'}
onChange={v => update(s => { s.theme = v })}
/>
</Row>