How oldj/switchhosts works
SwitchHosts is a desktop hosts-file manager. Users organize local, remote, system, group, and folder entries, choose which hosts are active, then apply the resulting content to the system hosts file; they can also refresh remote entries, search, import/export, and switch entries from the tray. The graph separates the renderer, Tauri command layer, domain operations, and filesystem storage. Several backend relationships are supported by the SOURCE INDEX, but unsampled implementation details are not inferred.
Main entry points: commands.rs Tauri commands · mod.rs Persistent storage · http_api.rs Local HTTP API · write.rs System hosts apply
Components 19
Desktop interface
- Main window
src/renderer/pages/index.tsx - Hosts data model
src/renderer/models/useHostsData.ts - Hosts editor
src/renderer/components/Editor/HostsEditor.tsx - Tray window
src/renderer/pages/tray.tsx
Tauri backend
- Tauri commands
src-tauri/src/commands.rs - Menus and tray
src-tauri/src/app_menu.rs - Tray behavior
src-tauri/src/tray.rs
Hosts operations
- Find entries
src-tauri/src/find.rs - Remote refresh
src-tauri/src/refresh.rs - Import and export
src-tauri/src/import_export.rs - Import preview
src-tauri/src/import_export/preview.rs - System hosts apply
src-tauri/src/hosts_apply/write.rs - Apply recovery
src-tauri/src/hosts_apply/recovery.rs - Privileged helper client
src-tauri/src/hosts_apply/helper_client.rs - Local HTTP API
src-tauri/src/http_api.rs
Data and state
- Persistent storage
src-tauri/src/storage/mod.rs - Hosts tree format
src-tauri/src/storage/tree_format.rs - Apply history
src-tauri/src/hosts_apply/history.rs
Other components
- User
Connections 28
- User → Main window: manages entries
README.md - User → Tray window: switches hosts
README.md - Main window → Hosts data model: views data
- Hosts data model → Tauri commands: requests data and apply
- Main window → Hosts editor: edits entries
- Tray window → Tray behavior: switches entries
- Tauri commands → Find entries: references
src-tauri/src/commands.rs - Tauri commands → Remote refresh: references
src-tauri/src/commands.rs - Tauri commands → Import and export: references
src-tauri/src/commands.rs - Tauri commands → System hosts apply: delegates apply
src-tauri/src/commands.rs - Tauri commands → Persistent storage: uses storage
src-tauri/src/commands.rs - Tauri commands → Local HTTP API: references
src-tauri/src/commands.rs - Tauri commands → Menus and tray: references
src-tauri/src/commands.rs - Tauri commands → Tray behavior: references
src-tauri/src/commands.rs - Import and export → Import preview: uses preview
src-tauri/src/import_export.rs - Import and export → Persistent storage: uses storage
src-tauri/src/import_export.rs - Find entries → Persistent storage: reads entries
src-tauri/src/find.rs - Remote refresh → Persistent storage: uses storage
- Local HTTP API → Remote refresh: references
src-tauri/src/http_api.rs - Local HTTP API → System hosts apply: references
src-tauri/src/http_api.rs - Local HTTP API → Apply recovery: references
src-tauri/src/http_api.rs - Local HTTP API → Persistent storage: uses storage
src-tauri/src/http_api.rs - System hosts apply → Privileged helper client: privileged write
- Apply recovery → System hosts apply: uses write
src-tauri/src/hosts_apply/recovery.rs - System hosts apply → Apply history: records changes
- Persistent storage → Hosts tree format: uses format
src-tauri/src/storage/mod.rs - Persistent storage → Apply history: supports history
src-tauri/src/hosts_apply/history.rs - Menus and tray → Tray behavior: routes tray events
src-tauri/src/lib.rs