Live Sync Module
live_sync.rs (905 lines) — bidirectional file synchronization between a local folder and Proton Drive.
Architecture: Bidirectional Sync
graph TB
subgraph "Local"
FS[Filesystem
Sync Folder]
WATCHER[notify Watcher
inotify/kqueue]
end
subgraph "Remote"
PROTON[Proton Drive API]
end
subgraph "LiveSyncManager"
EVENTS[Local Events]
POLLER[Remote Poller
30s interval]
SUPPRESS[Suppression Cache
30s TTL]
BRIDGE[Sync Bridge
Tauri IPC]
end
FS --> WATCHER
WATCHER --> EVENTS
EVENTS --> SUPPRESS
SUPPRESS --> BRIDGE
BRIDGE --> PROTON
PROTON --> POLLER
POLLER --> SUPPRESS
SDB[(sync_db.rs
SQLite)]
EVENTS --> SDB
POLLER --> SDB
How It Works
Local → Remote
notify::RecommendedWatchermonitors the sync folder for filesystem events (create, modify, delete)- Events are deduplicated via a suppression cache with a 30-second TTL (max 4096 entries)
- Changes are serialized as
LiveSyncEventand emitted to the WebView frontend via Tauri IPC - The frontend uploads changed files through Proton’s API
Remote → Local
- A background poller thread runs at a configurable interval (default: 30 seconds)
- Polls the Proton API for remote changes via
RemoteSyncChangestructs RemoteSyncChangecontains:relative_path,action(string), and optionalcontent_base64- Remote changes are applied to the local filesystem
Sync Database Integration
Every change (local or remote) updates the sync_db SQLite database. On restart, the sync manager reads persisted state from sync_db to resume without re-scanning.
Key Structures
| Struct | Purpose |
|---|---|
LiveSyncManager |
Core manager: watcher, poller, worker threads, known-files cache |
LiveSyncEvent |
Serialized event emitted to WebView: kind, paths, root_path, source |
LiveSyncStatus |
Status snapshot: enabled, folder_path, poll_interval_seconds |
RemoteSyncChange |
Incoming remote change: relative_path, action, content_base64 |
Suppression Logic
The suppression cache prevents echo loops: when remote changes are applied to disk, the local watcher would detect them as “new” changes. The 30-second TTL suppression window catches these echoes before they loop back to the server.