Repository navigation
Make connectors pluggable - #74
Conversation
pepperstm
left a comment
There was a problem hiding this comment.
Thanks, this is a really nice piece of work. The trait plus registry is a clean way to do it, and the migration of old uploads, settings and segments is careful. I've been through all of it and found nothing worrying security-wise: the keychain entry keeps its name so nobody gets logged out, the secret never reaches the page, connector ids are checked, uploads are still limited to our own activity files, and returned links only open over https.
It needs a rebase on main first. Laps (#68) went in after you branched, so there are conflicts in commands.rs (route_is_loop sits next to segments_fetch), RideSetup.tsx and tests/features.rs. They're mechanical, but two things in RideSetup.tsx need a bit of care:
- Ghosts are off on lap rides, so the "From Strava…" button and the new ride picker should go inside the
!lapRideblock with the rest of the ghost section. - #75 (Herne Hill, about to merge) adds a direction choice for the velodrome and uses
rideIdinstead ofroute.idfor ghosts and segments, so clockwise and anticlockwise keep their own. The new calls (connectors.rides,ghosts.importRemote,segments.fetch) should userideIdtoo.
I'll merge #73 before this, so the loop-route matching will be right once you're rebased on it.
A few small things, none of them blockers:
- The description still says
Fixes #<feature-issue>, and HANDOFF says "Rides from before v0.4". This will go out in 0.3.10, so that should say 0.3.10. migrate_uploadstakesstravaActivityIdaway when it writes the list. If someone goes back to 0.3.9, their rides will offer "Upload to Strava" again. Strava turns away duplicate files, so it's not a big deal, but keeping the old field alongside for a release or two would avoid it.- For Dreeve and other key-based services: it'd be worth refusing an
http://server URL, or at least warning, so the API key isn't sent unencrypted. connector_uploadreads the ride list, adds the record and writes it back. With two services auto-uploading at once, one record could be lost. Not an issue with only Strava, but worth a lock once Dreeve lands.
Once it's rebased I'll try the Strava side against the live API: linking, upload, the ride picker and segments.
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 <noreply@anthropic.com>
The ghost picker listed the last 60 rides and only found out on import whether a ride rides the route. Now each ride carries the service's summary outline, and a new core check measures how far it follows the route from its start. A ride fits when it covers half the route (a kilometre on short routes, at most 80 % of very short ones). The picker lists the fitting rides first, by how much of the route they cover, with the rest behind "Show the other N rides". The import still checks the full track as before. Half the route, not a fixed distance: run against a real ride history, "follows the first kilometre" matched 69 of 100 rides from the same front door, since they all share its first streets. Rides are fetched a page at a time; find_rides pages back until five fit or five pages were read, since the matching ride is often older than the first page. The outline check rejects rides that never pass the start before running the costlier route following. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ide list on upload - migrate_uploads copies the legacy Strava id into uploads instead of removing it, so going back to 0.3.9 doesn't offer to upload the ride again. - connectors::secure_server_url refuses http:// server URLs (except this machine) before an API key is sent; the connector guide uses it. - connector_upload serialises the read-change-write of the ride list. - HANDOFF: 0.3.10 instead of 0.4. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
9db6574 to
b07aaca
Compare
|
Thank you for looking into it. |
What and why
Turns the Strava implementation into the first of several connectors: services a ride can be sent to, and whose past rides can be raced as ghosts. This is the groundwork for adding other services (Dreeve is next, in a follow-up PR) without touching the UI each time.
Connector interface
src-tauri/src/connectors/, implementing aConnectortrait and registered once inconnectors::ALL.docs/ADDING_A_CONNECTOR.mdwalks through adding one.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 everything with its existing API calls.strava_*ones.segments_fetchtakes the connector id and merges segments per route.Existing data keeps working
RideSummary.uploadsrecords where a ride went, per connector. The oldstravaActivityIdis still read and migrated the next time the list is written.Settings.autoUploadis a list of connector ids. The oldstravaAutoUploadis migrated inmergeSettings.SegmentSource::StravabecomesRemotewith a connector id on the segment. Stored segments that say"strava"are read as Strava's.Ghost picker shows rides that fit the route first
The picker used to list the last 60 rides and only found out on import whether a ride follows the route. Now each ride carries the service's summary outline, and a new core check measures how far it follows the route from its start. A ride fits when it covers half the route (a kilometre on short routes, at most 80 % of very short ones). Fitting rides come first, by how much of the route they cover, and the rest sit behind "Show the other N rides". The import still checks the full track as before.
Half the route rather than a fixed distance, because against a real ride history "follows the first kilometre" matched 69 of 100 rides from the same front door. Rides are fetched a page at a time and
find_ridespages back until five fit or five pages were read, since the matching ride is often older than the first page.User-visible changes: the wording of Strava's settings card and buttons now comes from the connector's description, and the Segment Hunter badge no longer names Strava.
Fixes #71
How it was tested
Unit tests for the registry (unique ids, every connector describes its fields), the optional parts saying no, paging in
find_rides, route matching of ride outlines, and the migration of old upload records, settings and segments (crates/core/tests/uploads.rs,features.rs).The matching threshold was tuned against a real ride history. That run used a Dreeve instance, which is not part of this PR.
Not tested: the Strava calls against the live API. Only the code paths around them are unit-tested, and the calls themselves are the ones that were already there. I also haven't clicked through the changed screens in the running app.
npm run checkpasses locallyTested on: I do not have Access to the Strava API. I need your help with testing here
Documentation
docs/wiki/updated (Architecture.md,Strava.md)HANDOFF.mdupdated: source layout, secrets and upload records, and why connectors are a trait plus a registryAnything unfinished or risky?
follow_track, fixed separately in Follow a ride on a loop route from its start, not its finish #73. This PR works without it, but the "fits the route" ordering on loop routes only becomes right once that is merged.stravaActivityId,stravaAutoUpload,"strava"as segment source) are read for compatibility and written no more. They can be dropped in a later release.🤖 Generated with Claude Code and carefully reviewed by me.
Please test the functionality against the Strava API before merging, I do not have access to it.