generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for the AccessorySetupKit #15
Draft
Supereg
wants to merge
43
commits into
main
Choose a base branch
from
feature/accessory-setup-kit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
45a8120
Allow to customize the time stamp of the measurement for Omron mock d…
Supereg 660b9bb
Allow to provide the measurements for HealthMeasurements mock methods
Supereg b8378b5
Add .git again. Seems to resolve some caching issues?
Supereg 73a3f84
Enable Swift 6 language mode
Supereg f910b0d
Enable Swift 6 Language mode for UITests
Supereg 5b7d0ac
Update conformance
Supereg 5ae7820
Disable CodeQl
Supereg 709a168
Support for the AccessorySetupKit
Supereg 7d5bb7b
Initial draft implementation
Supereg bafeb87
Only if compatible
Supereg 18db0a6
Ensure we do not capture task local values from configure
Supereg 4f9b7dc
Some hints
Supereg 895f883
Minor todo annotations
Supereg 9fde7e5
Update for device appearance
Supereg 10c0d31
Integrate with new device defined appearance
Supereg 3304796
LabeledContent, localization and rename button implementation
Supereg 1186741
Make it compile
Supereg ed8aadd
Improve some state handling
Supereg 762251a
Fix discovery for bp5250 and sc150
Supereg 2cd4710
Minor changes
Supereg f5ddb87
More adjustments and fixes
Supereg 6b00000
Make sure we connect and disconnect from SpeziBluetooth actor
Supereg 8521d72
Dismiss later
Supereg 660760d
Minor fixes and adjustments
Supereg 918534d
Make sure to cancel connection attempt upon forgetting about the device
Supereg d5af0a5
Prevent connection attempt race condition
Supereg b10194f
Modularize the PairedDevices module a bit.
Supereg e57e9d6
Fix forget device not removing from local store
Supereg 3a254df
Minor adjustments
Supereg b639968
Minor checks
Supereg bfe83b6
Inverse condition
Supereg 6394647
Some modifications
Supereg 67d2708
Minor logging changes
Supereg 041591a
Minor changes
Supereg 1548a02
Improve some logging
Supereg 480057c
Some notes
Supereg bbb1538
Update to sync event handlers
Supereg b35ad0d
Clear the peripheral property sync
Supereg 159cdf7
Do not retrieve the device for no reason
Supereg 71e5f80
Do not call disconnect ever after accessory removal
Supereg 0ab64d1
Modifications and updates
Supereg 2328379
Resolve some todos
Supereg d200058
Merge branch 'main' into feature/accessory-setup-kit
PSchmiedmayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
// swift-tools-version:5.9 | ||
// swift-tools-version:6.0 | ||
|
||
// | ||
// This source file is part of the Stanford SpeziDevices open source project | ||
// | ||
// | ||
// SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import class Foundation.ProcessInfo | ||
import PackageDescription | ||
|
||
|
||
#if swift(<6) | ||
let swiftConcurrency: SwiftSetting = .enableExperimentalFeature("StrictConcurrency") | ||
#else | ||
let swiftConcurrency: SwiftSetting = .enableUpcomingFeature("StrictConcurrency") | ||
#endif | ||
|
||
|
||
let package = Package( | ||
name: "SpeziDevices", | ||
defaultLocalization: "en", | ||
|
@@ -32,13 +25,13 @@ let package = Package( | |
.library(name: "SpeziOmron", targets: ["SpeziOmron"]) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-collections", from: "1.1.1"), | ||
.package(url: "https://github.com/StanfordSpezi/SpeziFoundation", from: "2.0.0-beta.1"), | ||
.package(url: "https://github.com/StanfordSpezi/Spezi", from: "1.7.1"), | ||
.package(url: "https://github.com/StanfordSpezi/SpeziViews", from: "1.5.0"), | ||
.package(url: "https://github.com/StanfordSpezi/SpeziBluetooth", from: "3.0.1"), | ||
.package(url: "https://github.com/StanfordSpezi/SpeziNetworking", from: "2.1.1"), | ||
.package(url: "https://github.com/StanfordBDHG/XCTestExtensions", from: "1.0.0") | ||
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.1"), | ||
.package(url: "https://github.com/StanfordSpezi/SpeziFoundation.git", from: "2.0.0"), | ||
.package(url: "https://github.com/StanfordSpezi/Spezi.git", from: "1.8.0"), | ||
.package(url: "https://github.com/StanfordSpezi/SpeziViews.git", from: "1.7.0"), | ||
.package(url: "https://github.com/StanfordSpezi/SpeziBluetooth.git", branch: "feature/accessory-setup-kit"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO to get the tagged version in here once it is merged. |
||
.package(url: "https://github.com/StanfordSpezi/SpeziNetworking.git", from: "2.1.1"), | ||
.package(url: "https://github.com/StanfordBDHG/XCTestExtensions.git", from: "1.0.0") | ||
] + swiftLintPackage(), | ||
targets: [ | ||
.target( | ||
|
@@ -51,10 +44,6 @@ let package = Package( | |
.product(name: "SpeziViews", package: "SpeziViews"), | ||
.product(name: "Spezi", package: "Spezi") | ||
], | ||
swiftSettings: [ | ||
swiftConcurrency, | ||
.enableUpcomingFeature("InferSendableFromCaptures") | ||
], | ||
plugins: [] + swiftLintPlugin() | ||
), | ||
.target( | ||
|
@@ -68,10 +57,6 @@ let package = Package( | |
resources: [ | ||
.process("Resources") | ||
], | ||
swiftSettings: [ | ||
swiftConcurrency, | ||
.enableUpcomingFeature("InferSendableFromCaptures") | ||
], | ||
plugins: [] + swiftLintPlugin() | ||
), | ||
.target( | ||
|
@@ -84,10 +69,6 @@ let package = Package( | |
resources: [ | ||
.process("Resources") | ||
], | ||
swiftSettings: [ | ||
swiftConcurrency, | ||
.enableUpcomingFeature("InferSendableFromCaptures") | ||
], | ||
plugins: [] + swiftLintPlugin() | ||
), | ||
.testTarget( | ||
|
@@ -100,10 +81,6 @@ let package = Package( | |
.product(name: "SpeziBluetoothServices", package: "SpeziBluetooth"), | ||
.product(name: "XCTestExtensions", package: "XCTestExtensions") | ||
], | ||
swiftSettings: [ | ||
swiftConcurrency, | ||
.enableUpcomingFeature("InferSendableFromCaptures") | ||
], | ||
plugins: [] + swiftLintPlugin() | ||
), | ||
.testTarget( | ||
|
@@ -114,10 +91,6 @@ let package = Package( | |
.product(name: "XCTByteCoding", package: "SpeziNetworking"), | ||
.product(name: "XCTestExtensions", package: "XCTestExtensions") | ||
], | ||
swiftSettings: [ | ||
swiftConcurrency, | ||
.enableUpcomingFeature("InferSendableFromCaptures") | ||
], | ||
plugins: [] + swiftLintPlugin() | ||
) | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,8 +257,8 @@ This project is licensed under the MIT License. See [Licenses](https://github.co | |
|
||
|
||
## Contributors | ||
This project is developed as part of the Stanford Byers Center for Biodesign at Stanford University. | ||
This project is developed as part of the Stanford Mussallem Center for Biodesign at Stanford University. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 |
||
See [CONTRIBUTORS.md](https://github.com/StanfordSpezi/SpeziDevices/tree/main/CONTRIBUTORS.md) for a full list of all TemplatePackage contributors. | ||
|
||
 | ||
 | ||
 | ||
 |
42 changes: 42 additions & 0 deletions
42
Sources/SpeziDevices/AccessorySetupKit/ImageReference+AccessorySetupKit.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import AccessorySetupKit | ||
import SpeziViews | ||
import SwiftUI | ||
|
||
|
||
extension ImageReference { | ||
func uiImageScaledForAccessorySetupKit() -> UIImage { | ||
let image: UIImage | ||
let isSymbol: Bool | ||
|
||
if let uiImage { | ||
image = uiImage | ||
isSymbol = isSystemImage | ||
} else { | ||
guard let sensor = UIImage(systemName: "sensor") else { | ||
preconditionFailure("UIImage with systemName 'sensor' is not available.") | ||
} | ||
isSymbol = true | ||
image = sensor | ||
} | ||
|
||
if isSymbol { | ||
guard let configuredImage = image | ||
.applyingSymbolConfiguration(.init(font: .systemFont(ofSize: 256), scale: .large))? | ||
.withTintColor(UIColor.tintColor, renderingMode: .alwaysTemplate) else { | ||
preconditionFailure("Failed to apply symbol configuration to UIImage: \(image).") | ||
} | ||
|
||
return configuredImage | ||
} else { | ||
return image | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Sources/SpeziDevices/AccessorySetupKit/LoadAccessorySetupKit.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import Spezi | ||
import SpeziBluetooth | ||
|
||
|
||
@available(iOS 18, *) | ||
final class LoadAccessorySetupKit: Module { | ||
@Dependency(AccessorySetupKit.self) | ||
var accessorySetupKit | ||
|
||
init() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SpeziBluetooth | ||
|
||
|
||
/// Support migration to the new variant appearance system. | ||
@_spi(Migration) | ||
public protocol DeviceVariantMigration { | ||
/// Select an appearance for an already paired device. | ||
/// | ||
/// This method is called when we detect a paired device with variants defined but not variantId associated with the device info (as it is for devices paired before the variant system was introduced). | ||
/// - Parameter deviceInfo: The device info for which to select an appearance. | ||
/// - Returns: Returns the `appearance` and an optional `variantId`. | ||
static func selectAppearance(for deviceInfo: PairedDeviceInfo) -> (appearance: Appearance, variantId: String?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import OSLog | ||
import SpeziBluetooth | ||
import SpeziFoundation | ||
|
||
|
||
@MainActor | ||
final class DiscoveredDevice: Sendable { | ||
private static nonisolated let logger = Logger(subsystem: "edu.stanford.spezi.SpeziDevices", category: "DiscoveredDevice") | ||
|
||
let device: any PairableDevice | ||
private(set) var ongoingPairing: PairingContinuation? | ||
|
||
init(device: some PairableDevice) { | ||
self.device = device | ||
} | ||
|
||
func handleDeviceStateUpdated<Device: PairableDevice>(for device: Device, _ state: PeripheralState) { | ||
guard self.device === device else { | ||
return | ||
} | ||
|
||
switch state { | ||
case .disconnected: | ||
if let ongoingPairing { | ||
Self.logger.debug("Device \(device.label), \(device.id) disconnected while pairing was ongoing") | ||
self.ongoingPairing = nil | ||
ongoingPairing.signalDisconnect() | ||
} | ||
default: | ||
break | ||
} | ||
} | ||
|
||
func signalDevicePaired(_ device: some PairableDevice) -> Bool { | ||
guard self.device === device else { | ||
return false | ||
} | ||
|
||
if let ongoingPairing { | ||
Self.logger.debug("Device \(device.label), \(device.id) signaled it is fully paired.") | ||
self.ongoingPairing = nil | ||
ongoingPairing.signalPaired() | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func assignContinuation(_ continuation: CheckedContinuation<Void, Error>) { | ||
if let ongoingPairing { | ||
ongoingPairing.signalCancellation() | ||
} | ||
self.ongoingPairing = PairingContinuation(continuation) | ||
} | ||
|
||
func clearPairingContinuationWithIntentionToResume() -> PairingContinuation? { | ||
if let ongoingPairing { | ||
self.ongoingPairing = nil | ||
return ongoingPairing | ||
} | ||
return nil | ||
} | ||
|
||
deinit { | ||
ongoingPairing?.signalCancellation() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.