From 25c9119a1bf36b6fe28ed6b7ae48cc18d832fd4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Hofmann?= Date: Tue, 10 Nov 2026 15:18:13 +0100 Subject: [PATCH 1/3] Turn Strava into the first of extensible connectors Services a ride can be sent to are now connectors: one file each in src-tauri/src/connectors/ implementing the Connector trait, registered in connectors::ALL. The settings card, upload buttons, auto-upload toggle, ghost import and segment search are generic and built from each connector's own description, so adding a service (Dreeve is next) needs no UI change. Besides linking and uploading, the trait has two optional parts whose defaults say the service can't: listing the rider's past rides to race them as ghosts (lists_rides, recent_rides, ride_track) and finding segments along a route (finds_segments, segments_near). Services offer different subsets, so a connector implements what its service has. Strava implements all of it with its existing API calls; its OAuth flow, keychain entry and tokens are unchanged. - Commands routed by connector id replace the strava_* ones: connectors_list, connector_status, connector_configure, connector_connect, connector_disconnect, connector_upload, connector_rides and ghost_import_connector; segments_fetch takes the connector id and merges each connector's segments per route. - RideSummary.uploads records where a ride went per connector; the old stravaActivityId is still read and migrated on the next write. - Settings.autoUpload is a list of connector ids; the old stravaAutoUpload toggle is migrated in mergeSettings. - SegmentSource::Strava becomes Remote with a connector id on the segment; stored segments that say "strava" are read as Strava's. Strava works as before. The wording of its settings card and buttons now comes from the connector's description, and the Segment Hunter badge no longer names Strava. Tests for the registry, the optional parts saying no, and the migration of old upload records, settings and segments; guide in docs/ADDING_A_CONNECTOR.md. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 1 + HANDOFF.md | 11 +- crates/core/src/gamify.rs | 2 +- crates/core/src/segments.rs | 21 +- crates/core/src/types.rs | 53 ++++- crates/core/tests/core.rs | 3 +- crates/core/tests/features.rs | 2 +- crates/core/tests/uploads.rs | 71 ++++++ docs/ADDING_A_CONNECTOR.md | 153 +++++++++++++ docs/wiki/Architecture.md | 5 +- docs/wiki/Strava.md | 2 +- src-tauri/Cargo.toml | 1 + src-tauri/src/commands.rs | 121 ++++++---- src-tauri/src/connectors/mod.rs | 269 +++++++++++++++++++++++ src-tauri/src/{ => connectors}/strava.rs | 217 ++++++++++-------- src-tauri/src/library.rs | 9 +- src-tauri/src/main.rs | 17 +- src-tauri/src/secrets.rs | 11 +- src-tauri/src/session.rs | 6 +- web/src/bridge.ts | 26 ++- web/src/state.ts | 4 +- web/src/types.ts | 64 +++++- web/src/ui/History.tsx | 4 +- web/src/ui/Ride.tsx | 6 +- web/src/ui/RideSetup.tsx | 75 +++++-- web/src/ui/Settings.tsx | 123 ++++++----- web/src/ui/Summary.tsx | 73 ++++-- 27 files changed, 1062 insertions(+), 288 deletions(-) create mode 100644 crates/core/tests/uploads.rs create mode 100644 docs/ADDING_A_CONNECTOR.md create mode 100644 src-tauri/src/connectors/mod.rs rename src-tauri/src/{ => connectors}/strava.rs (63%) diff --git a/Cargo.lock b/Cargo.lock index 2fc0243..33e4b1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5258,6 +5258,7 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" name = "velopopuli" version = "0.3.9" dependencies = [ + "async-trait", "base64 0.22.1", "block2 0.6.2", "btleplug", diff --git a/HANDOFF.md b/HANDOFF.md index 893687c..ad33146 100644 --- a/HANDOFF.md +++ b/HANDOFF.md @@ -63,7 +63,11 @@ src-tauri/ The app (Tauri 2) mapdata.rs Downloading + caching vector tiles and Overpass data per route native/ Native renderer (mod.rs, host.rs NSView, shader.wgsl) diag.rs Diagnostics log + reports; issues.rs: GitHub new-issue links; snapshot.rs: window PNGs (macOS) - strava, geo, photos, smart, group, library, terrain, secrets, store + connectors/ Services a ride is uploaded to, and whose past rides can be raced as ghosts: + mod.rs (Connector trait, registry, descriptor types the settings card is built from), + strava.rs (OAuth, upload, recent rides, segments). + docs/ADDING_A_CONNECTOR.md explains adding one. + geo, photos, smart, group, library, terrain, secrets, store web/ React + three.js (Vite). ui/ screens, world/ the 3D scene (scene.ts, terrain.ts, trees.ts (tree models, sprite atlas), rider.ts, barriers.ts, surfaces.ts, weather.ts, native.ts = assets handed to the native renderer) docs/images/ README screenshots; docs/wiki/ wiki source @@ -80,7 +84,8 @@ How a ride flows end to end is in the wiki's [Architecture](https://github.com/p - **App data folder:** macOS `~/Library/Application Support/org.velopopuli.VeloPopuli`, Windows `%APPDATA%\org.velopopuli.VeloPopuli`, Linux `~/.local/share/org.velopopuli.VeloPopuli`. Override with `VP_DATA_DIR`. - `data/*.json` (store keys): `settings`, `routes` (library list) + `route-` (name + GPX), `rides`, `profile`, `ghosts-`, `scenery-`, `buildings-`, workouts, segments. - **Caches have versions:** buildings `FORMAT` (2) and `SCENERY_FORMAT` (4) in `mapdata.rs`; road tags `WAY_TAGS` (3, since trails added `mtb:scale`) in `world/surface.rs`. Bump the relevant one when the cached shape changes, or old caches will be read wrongly. -- **Secrets** (Strava, Home Assistant, GitHub none): OS keychain on macOS/Windows under the service name **"Velo Populi"** (with the space — kept on purpose so saved logins survive the rename), files with 0600 permissions on Linux. +- **Secrets** (Strava, Home Assistant, GitHub none): OS keychain on macOS/Windows under the service name **"Velo Populi"** (with the space — kept on purpose so saved logins survive the rename), files with 0600 permissions on Linux. Each connector's credentials are one entry named after its id (`strava`, …); the Home Assistant token is `homeassistant`. +- **Uploads:** a ride records where it went in `RideSummary.uploads` by connector id. Rides from before v0.4 carry `stravaActivityId` instead; `RideSummary::upload()` (Rust) and `uploadOf()` (page) read both, and `connector_upload` migrates the list when it next writes it. The old `stravaAutoUpload` setting becomes `autoUpload: ["strava"]` in `mergeSettings`. - **Logs:** `logs/diagnostics-