How tuyangjs/windows_autotheme works
1. Product shape
- This is a Windows desktop app built with Tauri: a TypeScript/React frontend runs in the webview, while a Rust backend performs OS-level work on Windows.
- The app’s purpose is narrow and clear: automatically switch Windows light/dark theme based on sunrise/sunset timing.
2. Top-level architecture
- The repository is split into two major runtime halves:
- src/ for the UI and app logic
- src-tauri/ for the native backend, Windows integration, and packaging
- This boundary matters: the frontend handles configuration, display, and user interaction; the Rust side applies theme changes and manages OS-specific behavior.
3. Frontend shell and navigation
- src/main.tsx, App.tsx, Content.tsx, and TitleBar.tsx form the app shell.
- The UI appears to be a single-window desktop interface with a custom title bar rather than a browser-style multi-page app.
- src/com/ThemeSelector.tsx and ThemeThumb.tsx suggest a theme-selection and preview area, likely for choosing appearance-related options.
4. Core domain logic in the frontend
- The src/mod/ folder holds most of the application logic:
- ThemeConfig.ts for theme-related settings/state
- Crontab.ts and adjustTime.ts for time-based scheduling and offsets
- Deviation.tsx for time deviation or adjustment controls
- Mainoption.tsx for primary settings/options
- WindowCode.ts for window/app behavior or window-state handling
- applyTheme.ts for invoking theme changes
- update.ts, RatingPrompt.tsx, and openStoreRating.ts for update/review flows
- DataSave.ts for persistence
- This layer likely acts as the orchestration layer between user settings, time calculations, and backend actions.
5. Weather/time source and scheduling flow
- The README says the app uses a free API to get sunrise and sunset data.
- In code terms, the time-source concerns are probably handled in searchCiti.tsx, sociti.ts, and adjustTime.ts, where the app likely:
1. resolves a city/location,
2. fetches sunrise/sunset times,
3. applies user offsets/deviation,
4. schedules the next theme switch.
- Crontab.ts suggests periodic or scheduled execution rather than continuous polling.
6. Persistence and local state
- DataSave.ts plus src/mod/utils/path.ts and tauri-file.ts indicate local configuration storage on disk.
- The app likely persists user preferences such as location, theme mode preferences, schedule settings, and language selection.
- This is an important architectural boundary: configuration is stored locally and consumed by both UI and scheduling logic.
7. Localization and UX structure
- src/language/ contains JSON translation files for en, es-ES, ja-JP, ru, zh-CN, and zh-HK.
- src/language/index.tsx likely centralizes language loading/selection.
- This suggests the UI is localized through a client-side dictionary system rather than server-side rendering.
8. Native backend responsibilities
- src-tauri/src/main.rs and lib.rs are the Tauri entry points.
- theme_apply.rs and windows_themes/ are the key native subsystem for changing Windows theme settings.
- This backend is where the app crosses from “desktop UI” into “system control,” which is the main architectural boundary in the project.
9. Windows-specific system integration
- The src-tauri/capabilities/default.json and desktop.json files define the permissions exposed to the frontend.
- build.rs and the icons/ / img/ assets indicate packaging and Windows app branding.
- The presence of Appx/ and Microsoft Store references in the README show that distribution includes Store/AppX packaging, not just a local installer.
10. Updates, store rating, and distribution flow
- src/mod/update.ts and src/updates.tsx indicate a dedicated update/announcement path in the frontend.
- openStoreRating.ts and RatingPrompt.tsx suggest a Microsoft Store-aware review prompt.
- The README explicitly mentions Microsoft Store delivery and automatic updates, so update and rating flows are part of the product architecture, not just UI extras.
11. Overall data flow
- User changes settings in the React UI.
- Settings are saved locally and used by the scheduling logic.
- The app fetches sunrise/sunset data for the chosen location, adjusts it by user preference, and computes the next switch time.
- When the trigger time arrives, the frontend/backend boundary is crossed and the Rust layer applies the Windows theme change.
- The result is a closed loop: configuration → time calculation → OS action → persisted state.
12. What to show in an architecture diagram
- A clean diagram should have four main blocks:
- React/TypeScript UI
- Local settings/scheduler logic
- Tauri/Rust native commands
- Windows OS + external sunrise/sunset API
- The main arrows are:
- UI to local config/state
- UI to Rust commands
- scheduler/time logic to external API
- Rust backend to Windows theme settings
- This repository is best understood as a desktop automation client with a thin native system-control layer behind a rich settings UI.
Main entry points: Content.tsx Content · App.tsx App Shell · ThemeConfig.ts Theme Config · Crontab.ts Schedule
Components 21
Frontend UI
React/TypeScript desktop shell, settings, scheduling, and localization.
- Entry · Bootstraps the webview app.
src/main.tsx - App Shell · Main window layout and application framing.
src/App.tsx - Content · Primary content area and screen composition.
src/Content.tsx - Title Bar · Custom window title bar for the desktop app.
src/TitleBar.tsx - Theme Picker · Theme selection and preview controls.
src/com/ThemeSelector.tsx - Preview Thumb · Small theme preview rendering.
src/com/ThemeThumb.tsx - Theme Config · Theme-related configuration and state.
src/mod/ThemeConfig.ts - Schedule · Time-based switching and cron-like scheduling.
src/mod/Crontab.ts - Adjust Time · Applies user offsets and deviations to switch times.
src/mod/adjustTime.ts - Location Lookup · Resolves city or location for sunrise/sunset data.
src/mod/searchCiti.tsx - Sun Data · Fetches sunrise and sunset timing data.
src/mod/sociti.ts - Local Store · Persists user settings and runtime state locally.
src/mod/DataSave.ts - Language Pack · Client-side translation loading and selection.
src/language/index.tsx - Updates · Update and announcement UI flow.
src/updates.tsx - Rating Prompt · Microsoft Store review prompt and open-store action.
src/mod/RatingPrompt.tsx
Native Backend
Tauri Rust commands and Windows theme integration.
- Tauri Commands · Frontend-facing commands and native integration boundary.
src-tauri/src/lib.rs - Native Entry · Starts the Rust side of the desktop application.
src-tauri/src/main.rs - Theme Apply · Applies the chosen Windows light or dark theme.
src-tauri/src/theme_apply.rs - Windows Themes · Windows-specific theme implementation details.
src-tauri/src/windows_themes/mod.rs
Other components
- Windows OS · System theme settings and desktop environment.
- Sunrise API · External source for sunrise and sunset timing.
Connections 21
- Entry → App Shell: mounts · Bootstraps the main application shell.
- App Shell → Content: contains · Renders the main content region.
- App Shell → Title Bar: contains · Provides custom desktop window chrome.
- Content → Theme Picker: uses · Displays theme selection controls.
- Theme Picker → Preview Thumb: previews · Shows theme appearance previews.
- Content → Theme Config: binds · Reads and edits theme settings.
- Content → Schedule: configures · Sets when automatic switching runs.
- Schedule → Adjust Time: adjusts with · Applies offset/deviation to computed times.
- Adjust Time → Location Lookup: uses · Resolves the target location first.
- Location Lookup → Sun Data: requests · Fetches sunrise/sunset timing data.
- Sun Data → Sunrise API: calls · Reads timing data from the external service.
- Theme Config → Local Store: persists · Saves user preferences locally.
- Schedule → Local Store: loads · Restores schedule and runtime state.
- Content → Language Pack: localizes · Loads UI language resources.
- Updates → Rating Prompt: prompts · Routes users toward store review actions.
- Content → Updates: shows · Surfaces update and announcement flow.
- Theme Config → Tauri Commands: invokes · Sends native commands across the Tauri boundary.
- Tauri Commands → Theme Apply: dispatches · Routes theme-change requests to Rust.
- Native Entry → Tauri Commands: exposes · Initializes native command handling.
- Theme Apply → Windows Themes: uses · Delegates to Windows-specific theme code.
- Windows Themes → Windows OS: changes · Applies the system theme on Windows.