Skip to content

Commit 91a9429

Browse files
sovanesyanclaude
andcommitted
Auto-discover iCloud calendars on startup when no saved tokens exist
Previously, after initial setup, iCloud CalDAV discovery only ran when manually triggered with 'i'. This left users with no events until they discovered that keybinding. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 83c5949 commit 91a9429

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/main.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,36 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
155155
});
156156
}
157157

158+
// Auto-discover iCloud calendars if configured but no saved tokens
159+
if matches!(app.icloud_auth, ICloudAuthState::NotAuthenticated)
160+
&& let Some(ref icloud_config) = app.config.icloud
161+
&& !icloud_config.is_eventkit() {
162+
app.icloud_auth = ICloudAuthState::Discovering;
163+
let auth = ICloudAuth::new(icloud_config.clone());
164+
let client = CalDavClient::new(auth);
165+
let tx = tx.clone();
166+
tokio::spawn(async move {
167+
match client.discover_calendars().await {
168+
Ok(discovered) => {
169+
let calendars: Vec<CalendarEntry> = discovered
170+
.into_iter()
171+
.map(|c| CalendarEntry { url: c.url, name: c.name })
172+
.collect();
173+
if calendars.is_empty() {
174+
let _ = tx.send(AsyncMessage::ICloudDiscoveryError(
175+
"No calendars found".to_string()
176+
)).await;
177+
} else {
178+
let _ = tx.send(AsyncMessage::ICloudDiscovered { calendars }).await;
179+
}
180+
}
181+
Err(e) => {
182+
let _ = tx.send(AsyncMessage::ICloudDiscoveryError(e.to_string())).await;
183+
}
184+
}
185+
});
186+
}
187+
158188
// Enable raw mode and enter alternate screen
159189
enable_raw_mode()?;
160190
execute!(stdout(), EnterAlternateScreen, cursor::Hide)?;

0 commit comments

Comments
 (0)