Skip to content

Commit 5e10de2

Browse files
committed
fix: sync tauri window theme
1 parent 8857d64 commit 5e10de2

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src-tauri/capabilities/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"windows": ["main"],
66
"permissions": [
77
"core:default",
8+
"core:window:allow-set-theme",
89
"opener:default",
910
"sql:default",
1011
"sql:allow-load",

src/shared/providers/theme-provider.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useState,
66
type ReactNode,
77
} from 'react';
8+
import { isTauri } from '@tauri-apps/api/core';
89
import {
910
accentColors,
1011
getSettings,
@@ -13,6 +14,17 @@ import {
1314
type BackgroundStyle,
1415
} from '@/shared/db/settings';
1516

17+
async function syncTauriTheme(theme: 'light' | 'dark' | 'system') {
18+
if (!isTauri()) return;
19+
try {
20+
const { getCurrentWindow } = await import('@tauri-apps/api/window');
21+
// Pass null to follow system theme
22+
await getCurrentWindow().setTheme(theme === 'system' ? null : theme);
23+
} catch (e) {
24+
console.warn('[Theme] Failed to sync Tauri window theme:', e);
25+
}
26+
}
27+
1628
type Theme = 'light' | 'dark' | 'system';
1729
type ResolvedTheme = 'light' | 'dark';
1830

@@ -112,6 +124,10 @@ export function ThemeProvider({ children }: ThemeProviderProps) {
112124
applyBackgroundStyle(backgroundStyle);
113125
}, [theme, accentColor, backgroundStyle]);
114126

127+
useEffect(() => {
128+
void syncTauriTheme(theme);
129+
}, [theme]);
130+
115131
// Listen for system theme changes
116132
useEffect(() => {
117133
if (theme !== 'system') return;

0 commit comments

Comments
 (0)