Skip to content

Commit 6b643bc

Browse files
committed
Merge branch 'main' of https://github.com/murdercode/tempo
2 parents 65dd8b2 + 603398b commit 6b643bc

File tree

8 files changed

+109
-98
lines changed

8 files changed

+109
-98
lines changed

src/main.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,25 @@ window.performTotalReset = async function () {
289289

290290
// Initialize theme early to prevent flash
291291
async function initializeEarlyTheme() {
292+
// Helper function to convert theme preference to actual theme
293+
function getActualTheme(themePreference) {
294+
if (themePreference === 'auto') {
295+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
296+
}
297+
return themePreference;
298+
}
299+
292300
try {
293301
// Try to load theme from saved settings first
294302
const savedSettings = await invoke('load_settings');
295303
const themeFromSettings = savedSettings?.appearance?.theme;
296304
const timerThemeFromSettings = savedSettings?.appearance?.timer_theme;
297305

298306
if (themeFromSettings) {
299-
document.documentElement.setAttribute('data-theme', themeFromSettings);
300-
localStorage.setItem('theme-preference', themeFromSettings);
301-
console.log(`🎨 Early theme loaded from settings: ${themeFromSettings}`);
307+
const actualTheme = getActualTheme(themeFromSettings);
308+
document.documentElement.setAttribute('data-theme', actualTheme);
309+
localStorage.setItem('theme-preference', themeFromSettings); // Store preference (could be "auto")
310+
console.log(`🎨 Early theme loaded from settings: ${themeFromSettings} -> actual: ${actualTheme}`);
302311
}
303312

304313
// Also initialize timer theme early
@@ -327,8 +336,9 @@ async function initializeEarlyTheme() {
327336

328337
// Fallback to localStorage or default for main theme
329338
const storedTheme = localStorage.getItem('theme-preference') || 'auto';
330-
document.documentElement.setAttribute('data-theme', storedTheme);
331-
console.log(`🎨 Early theme initialized from localStorage: ${storedTheme}`);
339+
const actualTheme = getActualTheme(storedTheme);
340+
document.documentElement.setAttribute('data-theme', actualTheme);
341+
console.log(`🎨 Early theme initialized from localStorage: ${storedTheme} -> actual: ${actualTheme}`);
332342
}
333343

334344
// Request notification permission using Tauri v2 API
@@ -537,7 +547,7 @@ function setupUpdateManagement() {
537547
}
538548
}
539549
}
540-
550+
541551
// Imposta la versione corrente
542552
setCurrentVersion();
543553

src/managers/settings-manager.js

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -847,19 +847,27 @@ export class SettingsManager {
847847
// Remove existing theme attributes
848848
html.removeAttribute('data-theme');
849849

850-
// Apply new theme
851-
html.setAttribute('data-theme', theme);
850+
// Determine the actual theme to apply
851+
let actualTheme = theme;
852+
if (theme === 'auto') {
853+
// For auto mode, detect system preference and apply the actual theme
854+
actualTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
855+
console.log(`🎨 Auto theme detected system preference: ${actualTheme}`);
856+
}
857+
858+
// Apply the actual theme (never "auto")
859+
html.setAttribute('data-theme', actualTheme);
852860

853861
// Store theme preference in localStorage for quick access
854-
localStorage.setItem('theme-preference', theme);
862+
localStorage.setItem('theme-preference', theme); // Store user preference (could be "auto")
855863

856864
// Update settings object and save immediately to prevent loss on app close
857865
if (this.settings && this.settings.appearance) {
858-
this.settings.appearance.theme = theme;
866+
this.settings.appearance.theme = theme; // Store user preference (could be "auto")
859867
try {
860868
// Save immediately to file
861869
await invoke('save_settings', { settings: this.settings });
862-
console.log(`🎨 Theme saved: ${theme}`);
870+
console.log(`🎨 Theme preference saved: ${theme}, actual theme applied: ${actualTheme}`);
863871
} catch (error) {
864872
console.error('Failed to save theme setting:', error);
865873
}
@@ -872,7 +880,7 @@ export class SettingsManager {
872880
this.removeSystemThemeListener();
873881
}
874882

875-
console.log(`🎨 Theme applied: ${theme}`);
883+
console.log(`🎨 Theme preference: ${theme}, actual theme applied: ${actualTheme}`);
876884

877885
// Update timer theme compatibility when color mode changes
878886
this.updateTimerThemeCompatibility();
@@ -885,10 +893,19 @@ export class SettingsManager {
885893
// Create new listener
886894
this.systemThemeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
887895
this.systemThemeListener = (e) => {
888-
console.log(`🎨 System theme changed: ${e.matches ? 'dark' : 'light'}`);
889-
// Theme is automatically applied via CSS media queries when data-theme="auto"
890-
// Update timer theme compatibility when system theme changes
891-
this.updateTimerThemeCompatibility();
896+
const newSystemTheme = e.matches ? 'dark' : 'light';
897+
console.log(`🎨 System theme changed: ${newSystemTheme}`);
898+
899+
// Only apply if current preference is "auto"
900+
const currentPreference = this.settings?.appearance?.theme || 'auto';
901+
if (currentPreference === 'auto') {
902+
const html = document.documentElement;
903+
html.setAttribute('data-theme', newSystemTheme);
904+
console.log(`🎨 Auto theme updated to: ${newSystemTheme}`);
905+
906+
// Update timer theme compatibility when system theme changes
907+
this.updateTimerThemeCompatibility();
908+
}
892909
};
893910

894911
this.systemThemeMediaQuery.addEventListener('change', this.systemThemeListener);
@@ -907,10 +924,21 @@ export class SettingsManager {
907924
const currentTheme = document.documentElement.getAttribute('data-theme');
908925
const storedTheme = localStorage.getItem('theme-preference');
909926

910-
// If early theme was set and matches localStorage, keep it
927+
// If early theme was set and matches localStorage, check if we need to process it
911928
if (currentTheme && storedTheme && currentTheme === storedTheme) {
912-
console.log(`🎨 Keeping early initialized theme: ${currentTheme}`);
929+
console.log(`🎨 Early initialized theme found: ${currentTheme}`);
930+
931+
// If the stored theme is "auto", we need to apply the correct auto logic
932+
// because data-theme should never be "auto" - it should be "light" or "dark"
933+
if (storedTheme === 'auto') {
934+
console.log(`🎨 Converting auto theme to actual theme`);
935+
await this.applyTheme('auto'); // This will set data-theme to light/dark
936+
return;
937+
}
913938

939+
// For non-auto themes, keep the early initialization
940+
console.log(`🎨 Keeping early initialized theme: ${currentTheme}`);
941+
914942
// Update settings to match current theme
915943
if (this.settings && this.settings.appearance) {
916944
this.settings.appearance.theme = currentTheme;
@@ -921,11 +949,6 @@ export class SettingsManager {
921949
console.error('Failed to update theme in settings:', error);
922950
}
923951
}
924-
925-
// Setup listeners for auto theme if needed
926-
if (currentTheme === 'auto') {
927-
this.setupSystemThemeListener();
928-
}
929952
return;
930953
}
931954

@@ -994,15 +1017,9 @@ export class SettingsManager {
9941017
// Timer Theme Management Functions
9951018
getCurrentColorMode() {
9961019
const currentTheme = document.documentElement.getAttribute('data-theme');
997-
998-
if (currentTheme === 'light') return 'light';
999-
if (currentTheme === 'dark') return 'dark';
1000-
if (currentTheme === 'auto') {
1001-
// Check system preference
1002-
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
1003-
}
1004-
1005-
return 'light'; // default fallback
1020+
1021+
// Since data-theme is now always 'light' or 'dark' (never 'auto'), this is simpler
1022+
return currentTheme === 'dark' ? 'dark' : 'light';
10061023
}
10071024

10081025
async initializeTimerTheme() {
@@ -1117,13 +1134,10 @@ export class SettingsManager {
11171134
</div>
11181135
<div class="color-preview-strip">
11191136
<div class="preview-color" style="background-color: ${theme.preview.focus}">
1120-
<span class="preview-label">Focus</span>
11211137
</div>
11221138
<div class="preview-color" style="background-color: ${theme.preview.break}">
1123-
<span class="preview-label">Break</span>
11241139
</div>
11251140
<div class="preview-color" style="background-color: ${theme.preview.longBreak}">
1126-
<span class="preview-label">Long</span>
11271141
</div>
11281142
</div>
11291143
</div>

src/managers/update-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export class UpdateManager {
250250
compareVersions(a, b) {
251251
try {
252252
console.log('🔍 Confronto versioni:', { a, b });
253-
253+
254254
// Pulisci le versioni da prefissi e suffissi non numerici
255255
const cleanA = this.cleanVersionString(a);
256256
const cleanB = this.cleanVersionString(b);

src/styles/layout.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* Default body background - neutral for all pages */
22
body {
3-
background-color: #f6f6f6;
43
transition: background-color 0.3s ease;
54
margin: 0;
65
padding: 0;

0 commit comments

Comments
 (0)