fix: auto-provision theme files on vault open for any vault

seed_vault_themes now writes individual missing/empty files instead of
skipping when the theme/ directory already exists. A new
ensure_vault_themes Tauri command is called by useThemeManager on every
vault open so vaults without a theme/ folder get default.md and dark.md
seeded automatically.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
lucaronin
2026-03-03 22:34:51 +01:00
parent 389e9d4372
commit f99b9d0b9b
5 changed files with 159 additions and 11 deletions

View File

@@ -478,4 +478,17 @@ describe('useThemeManager', () => {
// Light theme isDark should be false (default state is false, so this is stable)
expect(result.current.isDark).toBe(false)
})
it('calls ensure_vault_themes on mount with vaultPath', async () => {
renderHook(() => useThemeManager('/vault', entries, allContent))
await waitFor(() => {
expect(mockInvokeFn).toHaveBeenCalledWith('ensure_vault_themes', { vaultPath: '/vault' })
})
})
it('does not call ensure_vault_themes when vaultPath is null', async () => {
renderHook(() => useThemeManager(null, entries, allContent))
await new Promise(r => setTimeout(r, 50))
expect(mockInvokeFn).not.toHaveBeenCalledWith('ensure_vault_themes', expect.anything())
})
})

View File

@@ -196,6 +196,11 @@ export function useThemeManager(
entries: VaultEntry[],
allContent: Record<string, string>,
): ThemeManager {
// Ensure default theme files exist on vault open (creates theme/ dir + defaults if missing)
useEffect(() => {
if (vaultPath) tauriCall('ensure_vault_themes', { vaultPath }).catch(() => {})
}, [vaultPath])
const { activeThemeId, setActiveThemeId, reload } = useThemeSetting(vaultPath)
const cachedThemeContent = activeThemeId ? allContent[activeThemeId] : undefined
const { clearDom: clearTheme, isDark } = useThemeApplier(activeThemeId, cachedThemeContent)

View File

@@ -309,6 +309,7 @@ line-height-base: 1.6
syncWindowContent()
return path
},
ensure_vault_themes: (): null => null,
}
export function addMockEntry(_entry: VaultEntry, content: string): void {