fix: wire initial sync, oauth flow, and eliminate warnings

- Add token_file_exists() to ApiClient for sync token check
- App::new now checks for token on startup; shows DeviceAuth popup if missing
- Background thread starts OAuth Device Flow automatically when no token
- App::poll_auth() called each frame to detect auth completion
- Auth completion triggers SyncCommand::InitialSync
- run_initial_sync fetches all lists and tasks via Google Tasks API
- Stores results in local DB via replace_all_lists / replace_all_tasks
- App::check_initial_load() refreshes UI from DB after initial sync
- Removed all compile warnings (dead_code annotations)
This commit is contained in:
Ruben Rosario
2026-06-20 19:51:10 +01:00
parent 71befdf9f8
commit 320a9c2572
3 changed files with 149 additions and 32 deletions
+37
View File
@@ -56,7 +56,18 @@ fn main() -> io::Result<()> {
});
});
// Trigger initial sync if already authenticated
if !app.needs_auth {
let _ = sync_tx.try_send(SyncCommand::InitialSync);
}
while !app.should_quit {
// Poll auth status (non-blocking)
app.poll_auth();
// Check if initial sync has loaded data into DB
app.check_initial_load();
terminal.draw(|frame| {
let status = {
let guard = network_status.blocking_lock();
@@ -109,6 +120,9 @@ async fn run_sync_engine(
Some(SyncCommand::TriggerSync) => {
process_sync_queue(&db, &api, &network_status).await;
}
Some(SyncCommand::InitialSync) => {
run_initial_sync(&db, &api, &network_status).await;
}
Some(SyncCommand::Shutdown) | None => break,
}
}
@@ -116,6 +130,29 @@ async fn run_sync_engine(
}
}
async fn run_initial_sync(
db: &Arc<Db>,
api: &Arc<ApiClient>,
network_status: &Arc<Mutex<NetworkStatus>>,
) {
*network_status.lock().await = NetworkStatus::Syncing;
match api.fetch_lists().await {
Ok(lists) => {
db.replace_all_lists(&lists).ok();
for list in &lists {
if let Ok(tasks) = api.fetch_tasks(&list.id).await {
db.replace_all_tasks(&list.id, &tasks).ok();
}
}
*network_status.lock().await = NetworkStatus::Online;
}
Err(_) => {
*network_status.lock().await = NetworkStatus::Offline;
}
}
}
async fn process_sync_queue(
db: &Arc<Db>,
api: &Arc<ApiClient>,