Skip to content

Sync trio-next-dev with next-dev, without the delegate queue removal (#118) - #20

Merged
dnzxy merged 18 commits into
loopandlearn:trio-next-devfrom
EJM0:sync/next-dev-before-delegate-queue-removal
Nov 24, 2026
Merged

dnzxy merged 18 commits into
loopandlearn:trio-next-devfrom
EJM0:sync/next-dev-before-delegate-queue-removal

Conversation

@EJM0

@EJM0 EJM0 commented Nov 16, 2026

Copy link
Copy Markdown

Brings trio-next-dev up to LoopKit/G7SensorKit next-dev, except for LoopKit#118.

LoopKit#118 drops delegateQueue from G7CGMManager and awaits the async CGMManagerDelegate calls. That needs LoopKit/LoopKit#696, which loopandlearn/LoopKit trio-next-dev (babddf04, Trio's current pin) doesn't have. Its CGMManager still requires delegateQueue, so next-dev itself doesn't build in Trio.

Included:

The result differs from next-dev only by LoopKit#118: G7CGMManager.swift and its two test files.

Once Trio moves LoopKit to #696, trio-next-dev can follow next-dev directly again.

🤖 Generated with Claude Code

ETolboom and others added 17 commits November 4, 2026 21:05
The calibration sheet always led with a long "Before You Calibrate"
page, every single time, which made routine calibrations tedious.

The advice now only leads the flow the first time it is shown; later
calibrations skip straight to the meter-entry page, with the
how-to reachable again from a "How to Calibrate" pill on that page.

The advice itself is split into two pages: whether calibrating is a
good idea at all, then how to do it properly. The seen flag flips on
an explicit exit from the advice flow (cancelling, or continuing past
the how-to page) rather than on mere appearance, so a sheet nobody
acted on doesn't count as shown.
#if DEBUG alone would still ship it to real phones, since Trio's own
builds are commonly Debug configuration.
A G7 that fails or ends its session keeps advertising. While
eavesdropping, the scan for its replacement connects to any Dexcom
sensor in range to identify it, so it found the same sensor again five
minutes later, adopted it as a new sensor, read the same failed message
and raised Sensor Failed again: a critical alarm every five minutes
until the sensor was removed. Each pass also recorded a sensor start and
end, and overwrote the previous-sensor record, losing the failure.

The previous-sensor record now says why the sensor ended (failed,
session ended), and discovery declines that sensor, matched by name and
activation time. A sensor forgotten by the user can still be adopted
again. The Sensor Failed alert now stays up until a different sensor is
adopted, instead of being retracted as soon as it is issued, and its
issued marker survives the forget (as in LoopKit#112).

Fixes LoopKit#111.
reportGattError logged six arguments, but the OSLog helper only spreads
up to five; the default case passed the whole array as one argument and
os_log read the rest from garbage memory. Fold the error domain, code and
tag into one argument, and make the default case log the format string
and argument count instead.

Fixes LoopKit#116
Cancel on the advice pages now just dismisses. Before, backing out of the
why page marked the advice as seen, so the how page was never shown
automatically. The entry page's onAppear already marks it.
The flag lives in the CGM manager state, so it resets when the G7 is
removed and re-added, not once per app install.
A test hook doesn't belong in the settings UI. Removing and re-adding
the CGM resets the flag when testing.
After the first time, the entry page's link opened only the how page, so
the why page (factory calibrated; a big difference is a reason for
caution) could not be reached again. The link is now "Read Before
Calibrating" and opens one scrolling sheet with both.
Once the advice had been seen, the entry page had no caution apart from
the large-difference alert. The entry footer now always says the G7 is
factory calibrated and to calibrate only when glucose is steady, right
above the Read Before Calibrating button.
…ensor is new

The "glucose is changing" note was only on the how page, so after the
first time it was never seen while calibrating. It moves to the entry
page as a yellow card above the Calibrate button whenever the trend is
at least 1 mg/dL/min. A second card warns during the sensor's first day,
which the how page already advises against.
A calibration isn't applied the moment it's entered: it goes with the
sensor's next connection (or is dropped after five minutes), can be
refused, and once accepted is applied over the next couple of readings.
The entry footer only covered the first part. A third advice page, also
at the end of the Read Before Calibrating sheet, covers all three and
says not to calibrate again to chase the change.
"The G7 is factory calibrated" was hardcoded, so ONE+ and Stelo users
were told about a G7. Both the entry page's caution and the Before You
Calibrate text now use the paired sensor's model name.
…redesign

Show calibration advice only once, split into why and how
…io drops (LoopKit#119)

isSearchingForSensor was cleared only by endBootstrapPass. radioDown() ends a pass without it, so a
sensor adopted during that pass and relodged at poweredOn kept the flag set while readings arrived.
needsCodeForSensor was cleared only by lodge(), so a code arriving through reconfigure left it set
until the next lodge even when a link came up first.

A link-up now clears the searching flag, and the code flag when the delegate can authenticate (a
link restored after a relaunch can be up without a code). radioDown() clears the searching flag with
the pass it ends.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 26d6da0)
A sensor paired while the current one is ok or in its grace period waits
on a standby session (its own central) and takes over on its first
reliable reading, so readings carry on through its warm-up. Settings show
it as Next Sensor, with Discard Next Sensor and Stop Current Sensor (which
hands over at once). A next sensor that fails is reported once and never
switched to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dnzxy
dnzxy merged commit 1c6dfd5 into loopandlearn:trio-next-dev Nov 24, 2026
t1dude added a commit to t1dude/Trio that referenced this pull request Nov 24, 2026
dnzxy added a commit to nightscout/Trio that referenced this pull request Nov 27, 2026
…1809)

* feat(watch): add configurable Apple Watch complications

Four data-driven complications (Trio Glucose, Trio Gauge, Trio IOB, Trio
Chart) configured from Settings > Smart Watch > Apple Watch, with
previews, a stale threshold and corner/small-line options.

The watch app writes a ComplicationState snapshot to the App Group on
every WatchState and reloads installed timelines. Stale readings show
"--" and their age. The phone publishes state to an unreachable watch
via application context and budgeted complication transfers; the watch
schedules background refreshes so the face keeps updating with the app
closed.

Tests in TrioTests/WatchComplicationTests.swift.

* chore(watch): log complication snapshot saves, background refreshes and transfers

* Watch: the watch reads the CGM itself, the phone's readings first

While the CGM's Read on Apple Watch is on, the phone passes its configuration and the watch builds its own manager
from it (as LoopKit/Loop#2545's WatchCGMHost). The watch reads the sensor all the time but shows its own readings
only once the phone's have stopped coming (7 min since the phone's newest), and alarms by the phone's thresholds only
then. The glucose bubble shows where the reading comes from, a yellow triangle for a sensor problem, and the sensor's
state in place of the minutes while no readings come.

CGMs the watch can read are one protocol, WatchReadableCGM, in WatchDeviceManagers; the G7 is the first. The watch
settings show Read on Apple Watch for any CGM that shares its configuration, with a link to its settings, and a
Critical Alerts switch for the watch's urgent low.

The watch app's Info.plist (bluetooth-central) is now its INFOPLIST_FILE; the watch targets need watchOS 10.6 for
LoopKit and G7SensorKit, and the app's module is Trio for the shared glucose helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Watch: a sensor the phone pairs is paired on the watch with Trio open; Trio 1.0.2.59

When the phone pairs a new sensor, its export changes and the watch builds its manager again. The G7 then searches
for a sensor it has never connected to, and watchOS shows the Bluetooth pairing request only with Trio on the
screen (kristinkand/Trio fb7e6a5: background pairings were refused at the next reading). The bubble says so in
place of the minutes, also while the phone's readings still come, and in the background a notification asks to open
Trio, at most every 20 minutes, until the pairing has gone through. WatchReadableCGM.watchNeedsAppInFront carries
it for further CGMs.

G7SensorKit: upstream's 08d4886 with Kristin's acquisition fixes (a request that missed its burst is renewed at the
next wake; a wake's hold is granted before the caller goes on), EJM0/G7SensorKit trio-watch-read.

On 1.0.2.59: Trio says it supports reading on the watch (supportsWatchDirectRead, else G7SensorKit#105 hides Read on
Apple Watch); LoopKit instead of LoopAlgorithm; a manager is deleted with async delete().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Submodules: G7SensorKit as Trio dev pins it

loopandlearn trio-next-dev 08d4886, which is LoopKit/G7SensorKit next-dev: all the G7 changes Sport Mode has
merged. Kristin's acquisition fixes (EJM0 trio-watch-read) wait for G7SensorKit itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Watch: the shared helpers' log calls through the algorithm package's logging shim

JSON.swift, which BloodGlucose needs, logs with Trio's warning(.storage, …); the watch target has no Logger, so
the call resolved to the #warning macro. As the algorithm package does, the watch compiles AlgorithmLoggingShim
with TRIO_ALGORITHM_PACKAGE, and those log lines are dropped there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Watch: the pairing notice's text as SwiftFormat wraps it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Watch: JSON.swift logs through WatchLogger when built for the watch

The watch app now compiles JSON.swift, which called the phone's global
warning(.storage, ...) logger. That logger is not in the watch target,
so the call resolved to Swift's #warning macro and the build failed.

* Watch: show the watch's own CGM reading first, the phone's as fallback

The watch app shows its own direct reading while it is fresh (5 min
30 s), or while it is newer than the phone's; only then the phone's
readings, as the phone sent them. The chart is the watch's own readings
with the phone's filling in where the watch has none. When the watch's
reading ages out, the phone's take over at once (a timer, and again
when the app comes to the front), not at the next message.

The bubble's icon follows: Apple Watch while the watch's own reading is
shown, iPhone while the phone's is.

The watch alarms on its own readings once the phone's are older than
5 min 30 s (was 7 min).

* Watch: a fresh reading of the watch's own hides a stale sensor link note

The note under the glucose bubble ("Sensor code needed", "Pairing the
sensor: keep Trio open") was read only when the sensor kit posted a
status change, so a flag the kit had not cleared stayed on screen while
the watch's own readings came in. A reading now re-reads the status, and
while the watch's own newest reading is fresh (5 min 30 s) the link notes
and the pairing notification stay off: the reading proves the link. The
sensor's lifecycle notes (warmup, expired, failed) still show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(watch): address complication review feedback

- AppGroupID comes from the watch app and complication Info.plists; drop the
  bundle ID fallback
- Push complication state with the watch app closed for settings, pump
  settings, glucose deletion, override, temp target and snooze changes;
  debounce watch state builds to one per 2 s
- Treat empty IOB, COB, delta and loop time from the phone as missing
- Grey Out After range starts at 10 min
- No emoji in watch log lines; application context failure logs a warning
- Settings footer matches the face (--) and states the refresh tradeoff
- Clear the reload flag after the timeline reloads are issued
- Timeline entry when the loop goes stale

* fix(watch): prove complication review fixes with tests

Watch state now reaches a closed watch through a testable transport, reload and app group lookup have seams, and tests cover delivery, debounce, the reload flag, stale and empty values on every complication, and the Grey Out After settings.

* fix from  dnzxy/Trio@a098fdae7
keep cgm.manager trough placeholder state

* remove pairing notification on new cgm bt pair, only passive note.

* Refactor sensor state handling in WatchCGMHost and WatchDeviceManagers; simplify state text logic and remove unused properties.

* Watch: a new sensor is acquired without a relaunch; an unfinished pairing stays noted

The phone switching sensors built the watch's new G7 manager beside the old one. Both centrals share one
restore identifier, and the new one never powered on: no scan or connect until the app was relaunched
(log 2026-11-12, 30 min dead after the switch). The old manager now lets go first, awaited.

A pairing whose Bluetooth bond never finished (app in the background) only logged the kit's
pairingUnfinished alert. It is now the sensor note until the kit retracts it on a reading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(watch): address complication settings and gauge review feedback

- Move complication previews to their own page behind a NavigationLink
- Replace the long settings footer with one-line hints and help sheets
- Describe complication lag honestly and point to the Contact Image
- Rename Grey Out After to Mark Stale After, keeping the stored key
- Draw the Trio Gauge ring from colour stops the phone derives from
  the glucose colour scheme, with a neutral fallback
- Show one trend arrow per complication layout

* refactor(watch): share the ring stop payload format and align gauge ranges

* Watch: one status line under the bubble; sensor state on the watch icon

Reading directly, the line under the bubble shows the reading's age, the
loop's age only once it is late (or unknown), else the grace period note.
What needs doing (code, pairing, warmup countdown) replaces it; red once
the sensor failed or expired. The bubble's triangle is gone: the watch
icon turns yellow for a sensor that needs a look, red when it has ended.
The phone sends lastLoopDate so the watch ages the loop itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* beautify waapp folder structure

* Watch: show a G7 sensor issue as a sensor problem

A reading the G7 withholds (temporarySensorIssue) reaches the watch as an
error, so the watch kept its status and only went stale. It now shows
"Sensor issue" under the glucose bubble and the yellow watch icon, as the
phone's status pill does, until the next good reading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Watch state: the glucose target is a local since upstream 1.0.2.76

The merge kept a read of the removed currentGlucoseTarget property; the
perform closure then failed to type-check and CI reported a Void result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Watch CGM: keep the manager while the phone's export names the same sensor

The watch compared the phone's whole export with the one its manager was built from, so a key a kit update adds
(G7SensorKit's calibrationAdviceSeen) rebuilt the manager. The new one had lost the sensor it had found and bonded,
and the watch searched again with "Pairing: keep Trio open" under the bubble. Now only the sensor's identity
counts: sensor ID, activation and pairing code, and the manager type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Watch settings: split complication settings, explain contact image

* Watch complications: color or monochrome text

* Watch complications: follow the shown reading from either source

* Bump G7SensorKit to include loopandlearn/G7SensorKit#20

* Shorten the Apple Watch settings hints

* Color complication glucose and add Trio Loop

Small text is white, glucose is colored in range too, and Trio Loop shows the loop's device, status color and time.

* Sync the string catalog

* Show loop icon in corner complication and label circular loop

---------

Co-authored-by: Paul Ingham <pauldavidingham@gmail.com>
Co-authored-by: EJM0 <57327565+EJM0@users.noreply.github.com>
Co-authored-by: dnzxy <48965855+dnzxy@users.noreply.github.com>
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.

4 participants