Skip to content

Make connectors pluggable - #74

Merged
pepperstm merged 3 commits into
pepperstm:mainfrom
joern-h:feature/connectors
Nov 12, 2026
Merged

pepperstm merged 3 commits into
pepperstm:mainfrom
joern-h:feature/connectors

Conversation

@joern-h

@joern-h joern-h commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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

  • One file per service in src-tauri/src/connectors/, implementing a Connector trait and registered once in connectors::ALL. docs/ADDING_A_CONNECTOR.md walks through adding one.
  • The settings card, upload buttons, auto-upload toggle, ghost import and segment search are generic. They are built from each connector's own description.
  • Besides linking and uploading, the trait has two optional parts whose defaults say the service can't: listing the rider's past rides (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.
  • Commands are routed by connector id and replace the strava_* ones. segments_fetch takes the connector id and merges segments per route.

Existing data keeps working

  • RideSummary.uploads records where a ride went, per connector. The old stravaActivityId is still read and migrated the next time the list is written.
  • Settings.autoUpload is a list of connector ids. The old stravaAutoUpload 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's OAuth flow, keychain entry and tokens are unchanged.

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_rides pages 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 check passes locally

  • Tested on: I do not have Access to the Strava API. I need your help with testing here

Documentation

  • README (features / project status): not needed
  • Wiki source in docs/wiki/ updated (Architecture.md, Strava.md)
  • HANDOFF.md updated: source layout, secrets and upload records, and why connectors are a trait plus a registry
  • Cache format version bumped if cached data changed shape: not needed, only stored records changed and they are migrated on read

Anything unfinished or risky?

  • Loop routes (finish at the start) are matched wrongly: a ride's first point snaps to the finish. That is an existing bug in 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.
  • The old fields (stravaActivityId, stravaAutoUpload, "strava" as segment source) are read for compatibility and written no more. They can be dropped in a later release.
  • Two commits that can be reviewed separately: the connector refactor, then the ghost picker.

🤖 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.

@RalfLeonFasler RalfLeonFasler mentioned this pull request Nov 11, 2026
6 tasks done

@pepperstm pepperstm left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Ghosts are off on lap rides, so the "From Strava…" button and the new ride picker should go inside the !lapRide block with the rest of the ghost section.
  2. #75 (Herne Hill, about to merge) adds a direction choice for the velodrome and uses rideId instead of route.id for ghosts and segments, so clockwise and anticlockwise keep their own. The new calls (connectors.rides, ghosts.importRemote, segments.fetch) should use rideId too.

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_uploads takes stravaActivityId away 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_upload reads 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.

joern-h and others added 3 commits November 12, 2026 12:57
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>
@joern-h

joern-h commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for looking into it.
I rebased onto main and addressed your concerns. Please review again

@pepperstm
pepperstm merged commit 5fcfc26 into pepperstm:main Nov 12, 2026
6 checks passed
@pepperstm pepperstm mentioned this pull request Nov 12, 2026
pepperstm added a commit that referenced this pull request Nov 12, 2026
Version 0.3.10: laps (#68, by Rallensooo), Herne Hill Velodrome (#75), signposted road routes (#77), your Strava routes (#78), the Dreeve connector and pluggable connectors (#74, #83, by Jörn), remembered sensors (#79), smooth bends with lean (#81) and the Linux Bluetooth fix (#84).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upload rides to a self-hosted Dreeve server (and make upload targets pluggable)

2 participants