Settings theme and app info UI
Covers:
Overview
The settings surface is currently only a placeholder: src/…/Settings.tsx exports a Settings React component that renders a single <div>Settings</div> and does not yet call the hooks in this scope or read/write settings state.
Application environment information is exposed through src/…/useInfo.tsx. useInfo() keeps platform and isMac in React state, then runs handleInfo() once on mount via useEffect. handleInfo() calls Tauri's platform() function from @tauri-apps/plugin-os, stores the platform string, and sets isMac when the returned platform is exactly macos. The hook returns { platform, isMac } for callers that need OS-specific UI behavior.
Theme behavior is exposed through src/…/useTheme.tsx. useTheme() initializes theme to light, then on mount obtains the current Tauri window via getCurrentWindow() from @tauri-apps/api/window. It reads win.theme() to replace the initial value and registers win.onThemeChanged(...) so frontend state tracks future native theme changes. The effect cleanup calls the listener's unlisten function if it was registered. The hook returns the current theme string, which may be light, dark, or an empty string if Tauri reports no current theme.
Both hooks depend on Tauri browser/runtime APIs and are designed for the Tauri frontend context rather than generic server-side rendering.
Coupling
- If src/…/Settings.tsx starts rendering OS-specific controls, verify it consumes src/…/useInfo.tsx defensively:
platformstarts as an empty string until the async Tauri call completes, whileisMacstarts asfalseand only becomes true afterplatform()returnsmacos. - If theme values are used for class names or preference persistence, verify callers of src/…/useTheme.tsx handle the initial
lightvalue and the later empty-string fallback fromwin.theme() || ''; otherwise UI can briefly render as light or lose a valid theme state before the Tauri API resolves.
Risks
- src/…/useInfo.tsx calls
TauriPlatform()twice inhandleInfo(): once intopand once again forsetPlatform. If the plugin call is slow, fails, or ever returns inconsistent values, the displayedplatformand derivedisMaccan diverge. - src/…/useTheme.tsx assigns
unlistenasynchronously after registeringwin.onThemeChanged(...). If the component unmounts before registration resolves, cleanup runs beforeunlistenis assigned and the theme listener may remain registered.