Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
2a5ad66
feat: add MedtrumKit
bastiaanv Aug 9, 2025
5ede45e
chore: cleanup
bastiaanv Aug 9, 2025
8be7c4a
Merge pull request #742 from bastiaanv/medtrum
dnzxy Aug 11, 2025
6817e8b
Merge pull request #744 from nightscout/dev
dnzxy Aug 11, 2025
f7f4619
Merge pull request #745 from nightscout/dev
dnzxy Aug 11, 2025
74dd4fc
Merge branch 'dev' into feat/dev-medtrum
Sjoerd-Bo3 Aug 21, 2025
4d86d2d
Merge pull request #757 from Sjoerd-Bo3/feat/dev-medtrum
Sjoerd-Bo3 Aug 21, 2025
aa34d29
Merge branch 'dev' into feat/dev-medtrum
marionbarker Sep 12, 2025
bef8d7f
update MedtrumKit: 5bfb806...e695e62
marionbarker Sep 12, 2025
f98c3d1
reformat swiftformat exclude line and add MedtrumKit
marionbarker Sep 12, 2025
40f48e4
restore app name to Trio, fix inadventent commit
marionbarker Sep 12, 2025
e4e2a87
Merge branch 'dev' into updates_to_medtrumkit
marionbarker Sep 16, 2025
a26e87a
update MedtrumKit: default alert now beep; detect pump base change, t…
marionbarker Sep 16, 2025
3e5b983
update MedtrumKit: fix onboarding logic PR 24
marionbarker Sep 19, 2025
986de65
Merge pull request #766 from nightscout/updates_to_medtrumkit
marionbarker Sep 19, 2025
35be807
fix: update patch endTime after "replace patch"
bastiaanv Sep 24, 2025
bff840c
Merge branch 'feat/dev-medtrum' into medtrum
bastiaanv Sep 24, 2025
e43d546
Merge pull request #777 from bastiaanv/medtrum
dnzxy Sep 27, 2025
f905a92
fix: keep reservoir level up-to-date on HomeScreen
bastiaanv Oct 5, 2025
1a4e239
Merge pull request #790 from bastiaanv/medtrum
Sjoerd-Bo3 Oct 9, 2025
f499733
Merge pull request #797 from nightscout/dev
Sjoerd-Bo3 Oct 9, 2025
8561bec
feat: show patch age if patch does not have an expiration
bastiaanv Oct 12, 2025
b6e6a59
chore: update Medtrum
bastiaanv Oct 12, 2025
862360b
fix: improve time active format
bastiaanv Oct 12, 2025
47b119b
chore: update medtrumkit
bastiaanv Oct 12, 2025
fce9722
chore: update hourglass icon when representing activation time
bastiaanv Oct 18, 2025
7dc3dc5
chore: update MedtrumKit
bastiaanv Oct 18, 2025
2da5286
chore: update MedtrumKit
bastiaanv Oct 18, 2025
5420be1
wip
bastiaanv Oct 19, 2025
9629d76
fix: update logic of + color
bastiaanv Oct 19, 2025
bf9fd4c
chore: update MedtrumKit
bastiaanv Oct 20, 2025
aaba299
chore: update MedtrumKit
bastiaanv Oct 29, 2025
aeb6b08
chore: cleanup
bastiaanv Oct 29, 2025
f2a23fb
Merge pull request #803 from bastiaanv/feat/dev-medtrum
Sjoerd-Bo3 Oct 29, 2025
5deff54
chore: update MedtrumKit
bastiaanv Oct 31, 2025
cd5fe21
Merge branch 'dev' of https://github.com/nightscout/Trio into sync-de…
dnzxy Nov 1, 2025
b76d329
Merge pull request #839 from nightscout/sync-dev-to-medtrum-2025-11-01
Sjoerd-Bo3 Nov 2, 2025
15ce128
Merge branch 'feat/dev-medtrum' of https://github.com/bastiaanv/Trio …
bastiaanv Nov 2, 2025
488a462
Merge branch 'dev' into feat/dev-medtrum
bastiaanv Nov 6, 2025
bbd5cb4
chore: update MedtrumKit
bastiaanv Nov 6, 2025
86ceb54
chore: cleanup
bastiaanv Nov 6, 2025
f506959
Merge branch 'dev' into feat/dev-medtrum
bastiaanv Nov 9, 2025
c9d6405
Merge pull request #842 from bastiaanv/feat/dev-medtrum
Sjoerd-Bo3 Nov 9, 2025
e1022d9
Merge branch 'dev' into update_feat/dev-medtrum
marionbarker Nov 25, 2025
eaaf579
update MedtrumKit: Loop specific fixes, PR 55
marionbarker Nov 25, 2025
066b8b7
update swiftformat.sh
marionbarker Nov 25, 2025
bde338f
Merge branch 'dev' into update_feat/dev-medtrum
marionbarker Nov 26, 2025
88b4ede
update DanaKit: linting change
marionbarker Nov 26, 2025
f673700
Merge pull request #862 from loopandlearn/update_feat/dev-medtrum
dnzxy Nov 26, 2025
138284f
chore: update MedtrumKit
bastiaanv Dec 20, 2025
6d00433
Merge pull request #896 from bastiaanv/feat/dev-medtrum
dnzxy Dec 21, 2025
59772e0
Implement snooze action for glucose notifications and enhance notific…
cachrisman Dec 28, 2025
716c526
updated main app snooze function to use the same functions as the not…
cachrisman Dec 28, 2025
caf041d
Unified in-app and notification action snooze functionality to use th…
cachrisman Dec 28, 2025
62b47e8
Refactor UI operations to ensure they execute on the main thread acro…
cachrisman Dec 28, 2025
f5053d5
Snooze: stabilize observer lifecycle and alert identifiers
cachrisman Dec 28, 2025
c9dd44c
Refactor notification handling to use NotificationCategoryFactory
cachrisman Dec 28, 2025
a518edc
Merge branch 'dev' into feature/fix-ios-app-notification-duplicates-a…
cachrisman Jan 4, 2026
904bb57
fix(notifications): standardize threading and fix/improve watch conne…
cachrisman Jan 8, 2026
bf7bae1
Merge branch 'dev' into feat/dev-medtrum
marionbarker Jan 12, 2026
c17bb51
update MedtrumKit: aedb7bf...0905638;
marionbarker Jan 12, 2026
912be7e
Merge branch 'dev' into feature/fix-ios-app-notification-duplicates-a…
cachrisman Jan 12, 2026
119e5da
chore: update MedtrumKit
bastiaanv Jan 14, 2026
0a69738
chore: cleanup
bastiaanv Jan 14, 2026
98f8fb6
Merge pull request #936 from bastiaanv/feat/dev-medtrum
dnzxy Jan 14, 2026
446bf0f
Merge pull request #943 from nightscout/dev
dnzxy Jan 20, 2026
eaaca25
Merge branch 'dev' of https://github.com/nightscout/Trio into feat/de…
dnzxy Jan 26, 2026
eee3468
Sync with upstream MedtrumKit (loopandlearn/MedtrumKit#f21d808)
dnzxy Jan 26, 2026
3d24f24
Merge branch 'dev' into feature/fix-ios-app-notification-duplicates-a…
dnzxy Jan 31, 2026
a372f12
Merge branch 'dev' into feat/dev-medtrum
MikePlante1 Feb 20, 2026
4de4dba
Merge branch 'dev' into feat/dev-medtrum
MikePlante1 Mar 4, 2026
4f2fdfc
Merge branch 'dev' into feature/fix-ios-app-notification-duplicates-a…
dnzxy Mar 22, 2026
9e9e9ec
Merge branch 'dev' of https://github.com/nightscout/Trio into feat/de…
dnzxy Mar 23, 2026
c481012
Bump MedtrumKit
dnzxy Mar 23, 2026
c78f73e
Merge pull request #1023 from nightscout/feat/dev-medtrum-sync-dev-24…
MikePlante1 Mar 24, 2026
ec479fe
Update actions to Node.js 24 compatible versions
bjorkert Mar 24, 2026
19707ac
Merge remote-tracking branch 'upstream/dev' into dev
EJM0 Mar 25, 2026
ebab072
Refactor Snooze functionality by removing the handleSnoozeResponse me…
build-bot Mar 25, 2026
84d8d8e
Refactor snooze handling in SnoozeStateModel and UserNotificationsMan…
build-bot Mar 25, 2026
472efe8
Merge branch 'dev' into feature/fix-ios-app-notification-duplicates-a…
cachrisman Mar 25, 2026
e0c35fd
Remove smoothed glucose default value
kingst Mar 25, 2026
8832b36
Merge pull request #1029 from nightscout/remove-smoothedGlucose-defau…
kingst Mar 25, 2026
27f0e45
CI: Bump APP_DEV_VERSION to 0.6.0.65 [skip ci]
github-actions[bot] Mar 25, 2026
5977041
Merge branch 'nightscout:dev' into dev
EJM0 Mar 25, 2026
13556d6
Merge remote-tracking branch 'upstream/dev' into dev
EJM0 Mar 25, 2026
9125dcf
Merge branch 'dev' of https://github.com/EJM0/Trio into dev
EJM0 Mar 25, 2026
abbc2b8
Merge pull request #1027 from bjorkert/update-actions-node24
dnzxy Mar 26, 2026
ed6d593
CI: Bump APP_DEV_VERSION to 0.6.0.66 [skip ci]
github-actions[bot] Mar 26, 2026
924bf1c
Add watch notification files and snooze strings
MikePlante1 Mar 26, 2026
d3db45d
Merge remote-tracking branch 'upstream/dev' into dev
EJM0 Mar 26, 2026
42fd5a3
Fix typo
MikePlante1 Mar 27, 2026
1aa3c2b
Show start of every month on chart axes for 3M stats views
MikePlante1 Mar 27, 2026
02e9c22
Fix crash from force-unwrap on orphaned PumpEventStored with nil bolus
kingst Mar 27, 2026
03e3057
Merge pull request #807 from cachrisman/feature/fix-ios-app-notificat…
dnzxy Mar 27, 2026
50e1d45
CI: Bump APP_DEV_VERSION to 0.6.0.67 [skip ci]
github-actions[bot] Mar 27, 2026
c841a1f
Merge pull request #1033 from MikePlante1/stats
dnzxy Mar 27, 2026
d63c70a
CI: Bump APP_DEV_VERSION to 0.6.0.68 [skip ci]
github-actions[bot] Mar 27, 2026
a2d416f
Merge pull request #1034 from nightscout/fix-forced-unwrap-crash
kingst Mar 27, 2026
43bb419
CI: Bump APP_DEV_VERSION to 0.6.0.69 [skip ci]
github-actions[bot] Mar 27, 2026
ff65742
Rework and fix smoothing stop gap issue
dnzxy Mar 28, 2026
7f55ef0
Revert predicate to fetch 24 hrs of glucose
dnzxy Mar 29, 2026
63bbd3e
Merge branch 'feat/dev-medtrum' into feat/dev-medtrum-bump-24032026
dnzxy Mar 29, 2026
7d53d93
Bump MedtrumKit
dnzxy Mar 29, 2026
fec67f6
Adjust remaining time string handling after rework
dnzxy Mar 29, 2026
f17185b
Remove MedtrumKit reliance in pump header view again
dnzxy Mar 29, 2026
4959fc5
Merge pull request #1035 from nightscout/bugfix/smoothing-gap
dnzxy Mar 30, 2026
8ecf9c6
CI: Bump APP_DEV_VERSION to 0.6.0.70 [skip ci]
github-actions[bot] Mar 30, 2026
7dc2eb4
Merge pull request #1024 from nightscout/feat/dev-medtrum-bump-24032026
dnzxy Mar 30, 2026
d7e4805
Merge branch 'dev' into feat/dev-medtrum
dnzxy Mar 30, 2026
3272609
Remove unused code
dnzxy Mar 30, 2026
4ef32aa
Fix active bolus view being obscured and isSuspended race condition
kingst Mar 27, 2026
bfc2792
Back out isSuspended change to simplify commit
kingst Mar 31, 2026
4dd9002
Bump MedtrumKit; pull in i18n fixes
dnzxy Mar 31, 2026
66bd341
Merge pull request #1041 from nightscout/ui-at-bottom-blocked
kingst Mar 31, 2026
a8701d1
CI: Bump APP_DEV_VERSION to 0.6.0.71 [skip ci]
github-actions[bot] Mar 31, 2026
cd20c87
Merge pull request #1039 from nightscout/feat/dev-medtrum
dnzxy Mar 31, 2026
c2ec95e
CI: Bump APP_DEV_VERSION to 0.6.0.72 [skip ci]
github-actions[bot] Mar 31, 2026
f770bb6
Fix basal profile chart not showing active rate at chart's left edge
marv-out Mar 18, 2026
4752a75
Xcode fixems
MikePlante1 Mar 31, 2026
98568bc
typo
MikePlante1 Mar 31, 2026
553424d
Correct "BG reading values" to "glucose values"
MikePlante1 Mar 31, 2026
fb2bcb2
typo
MikePlante1 Mar 31, 2026
78bfc21
typo
MikePlante1 Mar 31, 2026
f11e82e
Merge pull request #1044 from MikePlante1/typo
dnzxy Mar 31, 2026
4bd164b
CI: Bump APP_DEV_VERSION to 0.6.0.73 [skip ci]
github-actions[bot] Mar 31, 2026
6c352b4
Merge pull request #1043 from nightscout/fix-basal-profile-chart
dnzxy Mar 31, 2026
a2e6c25
CI: Bump APP_DEV_VERSION to 0.6.0.74 [skip ci]
github-actions[bot] Mar 31, 2026
a233a39
Merge remote-tracking branch 'upstream/dev' into dev
EJM0 Apr 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

custom: ["https://www.nightscoutfoundation.org/donate"]
4 changes: 2 additions & 2 deletions .github/workflows/add_identifiers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
identifiers:
name: Add Identifiers
needs: validate
runs-on: macos-15
runs-on: macos-26
steps:
# Checks-out the repo
- name: Checkout Repo
uses: actions/checkout@v4
uses: actions/checkout@v5

# Patch Fastlane Match to not print tables
- name: Patch Match Tables
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/auto_version_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
token: ${{ secrets.TRIO_TOKEN_AUTOBUMP }}

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build_trio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
if: |
steps.workflow-permission.outputs.has_permission == 'true' &&
(vars.SCHEDULED_BUILD != 'false' || vars.SCHEDULED_SYNC != 'false')
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
token: ${{ secrets.GH_PAT }}

Expand All @@ -99,7 +99,7 @@ jobs:
steps.workflow-permission.outputs.has_permission == 'true' &&
vars.SCHEDULED_SYNC != 'false' && github.repository_owner != 'nightscout'
id: sync
uses: aormsby/Fork-Sync-With-Upstream-action@v3.4.1
uses: aormsby/Fork-Sync-With-Upstream-action@v3.4.2
with:
target_sync_branch: ${{ env.TARGET_BRANCH }}
shallow_since: 6 months ago
Expand Down Expand Up @@ -177,7 +177,7 @@ jobs:
run: "SUDO_ASKPASS=/usr/local/bin/askpass.sh sudo -A xcode-select --switch /Applications/Xcode-26.2.0.app/Contents/Developer"

- name: Checkout Repo for building
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
token: ${{ secrets.GH_PAT }}
submodules: recursive
Expand Down Expand Up @@ -257,7 +257,7 @@ jobs:
# Upload Build artifacts
- name: Upload build log, IPA and Symbol artifacts
if: always()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
name: build-artifacts
path: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/create_certs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:
create_certs:
name: Certificates
needs: validate
runs-on: macos-15
runs-on: macos-26
outputs:
new_certificate_needed: ${{ steps.set_output.outputs.new_certificate_needed }}

steps:
# Checks-out the repo
- name: Checkout Repo
uses: actions/checkout@v4
uses: actions/checkout@v5

# Patch Fastlane Match to not print tables
- name: Patch Match Tables
Expand Down Expand Up @@ -90,14 +90,14 @@ jobs:
nuke_certs:
name: Nuke certificates
needs: [validate, create_certs]
runs-on: macos-15
runs-on: macos-26
if: ${{ (needs.create_certs.outputs.new_certificate_needed == 'true' && vars.ENABLE_NUKE_CERTS == 'true') || vars.FORCE_NUKE_CERTS == 'true' }}
steps:
- name: Output from step id 'check_certs'
run: echo "new_certificate_needed=${{ needs.create_certs.outputs.new_certificate_needed }}"

- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Install dependencies
run: bundle install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/stale_issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
pull-requests: write
if: github.repository_owner == 'nightscout'
steps:
- uses: actions/stale@v9.0.0
- uses: actions/stale@v10
with:
days-before-issue-stale: 30
days-before-issue-close: 14
Expand All @@ -32,7 +32,7 @@ jobs:
pull-requests: write
if: github.repository_owner == 'nightscout'
steps:
- uses: actions/stale@v9.0.0
- uses: actions/stale@v10
with:
days-before-issue-stale: 30
days-before-issue-close: 30
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ on:
jobs:
test:
name: Run Unit Tests
runs-on: macos-15
runs-on: macos-26
if: github.repository_owner == 'nightscout'

steps:
- name: Select Xcode version
run: sudo xcode-select -s /Applications/Xcode_16.4.app/Contents/Developer
run: sudo xcode-select -s /Applications/Xcode_26.2.app/Contents/Developer

- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
fetch-depth: 1
submodules: recursive

- name: Restore cache
id: cache-restore
uses: actions/cache/restore@v4
uses: actions/cache/restore@v5
with:
path: |
/Users/runner/Library/Developer/Xcode/DerivedData
Expand All @@ -64,7 +64,7 @@ jobs:
time xcodebuild build-for-testing \
-workspace Trio.xcworkspace \
-scheme "Trio Tests" \
-destination 'platform=iOS Simulator,name=iPhone 16,OS=18.5' \
-destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' \

- name: Check for uncommitted changes
run: |
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:

- name: Save cache
if: steps.cache-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
uses: actions/cache/save@v5
with:
path: |
/Users/runner/Library/Developer/Xcode/DerivedData
Expand All @@ -107,7 +107,7 @@ jobs:
time xcodebuild test-without-building \
-workspace Trio.xcworkspace \
-scheme "Trio Tests" \
-destination 'platform=iOS Simulator,name=iPhone 16,OS=18.5' \
-destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' \
$([ "$ENABLE_PARALLEL_TESTING" = "true" ] && echo "-parallel-testing-enabled YES") \
2>&1 | tee xcodebuild.log

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/validate_secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
validate-fastlane-secrets:
name: Fastlane
needs: [validate-access-token]
runs-on: macos-15
runs-on: macos-26
env:
GH_PAT: ${{ secrets.GH_PAT }}
GH_TOKEN: ${{ secrets.GH_PAT }}
Expand All @@ -116,7 +116,7 @@ jobs:
TEAMID: ${{ secrets.TEAMID }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
uses: actions/checkout@v5

- name: Install Project Dependencies
run: bundle install
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@
[submodule "DanaKit"]
path = DanaKit
url = https://github.com/loopandlearn/DanaKit
[submodule "MedtrumKit"]
path = MedtrumKit
branch = dev
url = https://github.com/loopandlearn/MedtrumKit
2 changes: 1 addition & 1 deletion Config.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TRIO_APP_GROUP_ID = group.org.nightscout.$(DEVELOPMENT_TEAM).trio.trio-app-group

// The developers set the version numbers, please leave them alone
APP_VERSION = 0.6.0
APP_DEV_VERSION = 0.6.0.53
APP_DEV_VERSION = 0.6.0.74
APP_BUILD_NUMBER = 1
COPYRIGHT_NOTICE =

Expand Down
1 change: 1 addition & 0 deletions MedtrumKit
Submodule MedtrumKit added at b7f3d4
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public extension GlucoseStored {
@NSManaged var glucose: Int16
@NSManaged var id: UUID?
@NSManaged var isManual: Bool
@NSManaged var isUploadedToNS: Bool
@NSManaged var isUploadedToHealth: Bool
@NSManaged var isUploadedToNS: Bool
@NSManaged var isUploadedToTidepool: Bool
@NSManaged var smoothedGlucose: NSDecimalNumber?
}

extension GlucoseStored: Identifiable {}
5 changes: 5 additions & 0 deletions Model/Helper/PumpEvent+helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ extension NSPredicate {
return NSPredicate(format: "timestamp >= %@", date as NSDate)
}

static var pumpHistoryLast48h: NSPredicate {
let date = Date() - TimeInterval(hours: 48)
return NSPredicate(format: "timestamp >= %@", date as NSDate)
}

static var pumpHistoryLast24h: NSPredicate {
let date = Date.oneDayAgo
return NSPredicate(format: "timestamp >= %@", date as NSDate)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="24512" systemVersion="25B78" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="24512" systemVersion="25D2128" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithSwiftData="YES" userDefinedModelVersionIdentifier="">
<entity name="BolusStored" representedClassName="BolusStored" syncable="YES">
<attribute name="amount" optional="YES" attributeType="Decimal" defaultValueString="0"/>
<attribute name="isExternal" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
Expand Down Expand Up @@ -78,6 +78,7 @@
<attribute name="isUploadedToHealth" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isUploadedToNS" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isUploadedToTidepool" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="smoothedGlucose" optional="YES" attributeType="Decimal"/>
<fetchIndex name="byDate">
<fetchIndexElement property="date" type="Binary" order="ascending"/>
</fetchIndex>
Expand Down
66 changes: 66 additions & 0 deletions Trio Watch App Extension/Helper/WatchNotificationHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Foundation
import UserNotifications
import WatchConnectivity

final class WatchNotificationHandler: NSObject, UNUserNotificationCenterDelegate {
static let shared = WatchNotificationHandler()

override private init() {
super.init()
}

func configure() {
let center = UNUserNotificationCenter.current()
center.delegate = self
registerCategories(on: center)
}

private func registerCategories(on center: UNUserNotificationCenter) {
center.getNotificationCategories { existingCategories in
let glucoseCategory = NotificationCategoryFactory.createGlucoseCategory()

var categories = existingCategories
categories.update(with: glucoseCategory)
// UNUserNotificationCenter methods should be called on main thread
Task { @MainActor in
center.setNotificationCategories(categories)
}
}
}

/// UNUserNotificationCenterDelegate method called when user interacts with a notification on watch.
/// This can be called off the main thread. WCSession.transferUserInfo is thread-safe.
func userNotificationCenter(
_: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
defer { completionHandler() }

guard let action = NotificationResponseAction(rawValue: response.actionIdentifier) else { return }
sendSnoozeRequest(for: action)
}

/// Sends snooze request to iPhone via WatchConnectivity.
/// WCSession.transferUserInfo is thread-safe and can be called from any thread.
/// Relies on the watch app's WCSession owner (e.g., WatchState) to handle
/// session activation and delegate management.
private func sendSnoozeRequest(for action: NotificationResponseAction) {
guard WCSession.isSupported() else { return }

let payload: [String: Any] = [WatchMessageKeys.snoozeDuration: action.minutes]
let session = WCSession.default

// Try sendMessage first if session is reachable and activated (faster, immediate delivery)
// Fall back to transferUserInfo if not reachable or if sendMessage fails
if session.isReachable, session.activationState == .activated {
session.sendMessage(payload, replyHandler: nil) { _ in
// Fallback to transferUserInfo if sendMessage fails
session.transferUserInfo(payload)
}
} else {
// Session not reachable or not activated - use transferUserInfo (queued delivery)
session.transferUserInfo(payload)
}
}
}
5 changes: 5 additions & 0 deletions Trio Watch App Extension/TrioWatchApp.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import SwiftUI
import UserNotifications

@main struct TrioWatchApp: App {
@Environment(\.scenePhase) private var scenePhase

init() {
WatchNotificationHandler.shared.configure()
}

var body: some Scene {
WindowGroup {
TrioMainWatchView()
Expand Down
Loading
Loading