Skip to content
Open
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
1 change: 1 addition & 0 deletions packages/app/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"windows": ["main"],
"permissions": [
"core:default",
"core:app:allow-set-app-theme",
"core:window:allow-close",
"core:window:allow-minimize",
"core:window:allow-start-dragging",
Expand Down
18 changes: 18 additions & 0 deletions packages/app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "@readany/core/rag";
import { setPlatformService } from "@readany/core/services";
import { fetch as tauriFetch } from "@tauri-apps/plugin-http";
import { setTheme as setTauriTheme } from "@tauri-apps/api/app";
import { TauriPlatformService } from "./lib/platform/tauri-platform-service";
import { syncLegacyDesktopLibraryRootConfig } from "./lib/storage/desktop-library-root";
import { TauriVectorDB } from "./lib/tauri-vector-db";
Expand All @@ -31,6 +32,19 @@ import { useVectorModelStore } from "./stores/vector-model-store";

installFeedbackLogCapture();

// Keep the WebView color scheme in sync with the app theme so book CSS that
// relies on light-dark() / @media(prefers-color-scheme) follows the app theme
// instead of the OS scheme (e.g. sepia maps to a light scheme, so borders/text
// in light-mode colors stay visible instead of the OS dark-mode colors).
function syncSystemTheme() {
const theme = document.documentElement.getAttribute("data-theme");
void setTauriTheme(theme === "dark" ? "dark" : "light").catch(() => {});
}
new MutationObserver(syncSystemTheme).observe(document.documentElement, {
attributes: true,
attributeFilter: ["data-theme"],
});

const FEEDBACK_WORKER_FALLBACK = "https://feedback.readany.top";
const feedbackWorkerUrl = import.meta.env.VITE_FEEDBACK_WORKER_URL?.trim() || FEEDBACK_WORKER_FALLBACK;
setFeedbackWorkerUrl(feedbackWorkerUrl);
Expand Down Expand Up @@ -122,6 +136,10 @@ i18nReady.then(() => {
document.documentElement.setAttribute("data-theme", "sepia");
}

// Apply the restored theme to the WebView color scheme (observer above also
// keeps it in sync on any later theme switch).
syncSystemTheme();

// Restore saved language from platform KV storage
initI18nLanguage().catch(console.error);

Expand Down