Skip to content
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

Integration with AccessorySetupKit #49

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e20cdb6
Imporve how we persist the last manually disconnected device
Supereg Oct 28, 2024
7949a61
Remove data structures that moved to SpeziFoundation
Supereg Sep 11, 2024
876fedf
Experiment with ASKit
Supereg Sep 11, 2024
804ccb9
Adding module for ASKit
Supereg Sep 23, 2024
e4be1ba
Make init public
Supereg Sep 23, 2024
782a4ad
Isolation
Supereg Sep 23, 2024
74893f2
Make some API public
Supereg Sep 23, 2024
4e79785
Bridge showPicker
Supereg Sep 23, 2024
3be5f80
Add description for event type enum
Supereg Sep 23, 2024
4a62880
Support renaming and removing accessories
Supereg Sep 23, 2024
93e4ded
Allow to retrieve accessories
Supereg Sep 23, 2024
d4010a6
Revamp DiscoveryCriteria model and experiment with additional discove…
Supereg Sep 24, 2024
27611b3
Docs, Device Appearance; Swift 6 doc generation
Supereg Sep 25, 2024
dcf6471
Do not force 6.0
Supereg Sep 25, 2024
6f05ae7
Allow to apply variant descriptor to ASDiscoveryDescriptor
Supereg Sep 25, 2024
c1c60db
Allow to match DiscoveryDescriptor against DeviceVariantCrtieria
Supereg Sep 26, 2024
8d39db5
Make the appearance part of the device implementation
Supereg Sep 26, 2024
2112755
Make sure default is public
Supereg Sep 26, 2024
cb8bc55
Last few additions and changes
Supereg Sep 26, 2024
263a3fc
Enable Swift 6 language mode
Supereg Sep 26, 2024
0d9e8b7
Remove preconcurrency
Supereg Sep 26, 2024
a51d935
Make it static
Supereg Sep 26, 2024
842acc7
Rever language mode, make nonisolated
Supereg Sep 26, 2024
8e8eeb1
Add some useful API
Supereg Sep 26, 2024
62e0170
Docc
Supereg Sep 26, 2024
7eb5def
Add swift error for askit
Supereg Sep 27, 2024
29a4749
Localize the error
Supereg Sep 27, 2024
804ca20
Actively check for poweredOff, make disconnect async and minor fixes
Supereg Sep 27, 2024
14786ac
discard all peripherals on central power off
Supereg Sep 27, 2024
c21724c
Allow to register event handlers synchronously
Supereg Oct 2, 2024
7eb3c3e
Allow to setup synchronous event handlers
Supereg Oct 2, 2024
e4072f6
Iterations on event handlers
Supereg Oct 2, 2024
3dd0a7e
Avoid the crash for now
Supereg Oct 2, 2024
4bffedc
Ensure compatibility with platforms
Supereg Oct 2, 2024
c9acb2c
typo
Supereg Oct 2, 2024
a9472fa
Minor notes and changes
Supereg Nov 4, 2024
dd79442
Update deprecation message
Supereg Nov 6, 2024
7b20c8f
Isolate AccessorySetupKit to the SpeziBluetooth actor
Supereg Nov 6, 2024
1368fbf
Immediately execute work on disaptch queue on delegate handlers if on…
Supereg Nov 6, 2024
0dcea17
Minor fixes
Supereg Nov 6, 2024
79a5a47
Minor fixes and adjusments
Supereg Nov 6, 2024
2543439
Make sure disconnect returns when already disconnected
Supereg Nov 6, 2024
cb7d1bc
Run SPM tests on watchOS, tvOS and visionOS
Supereg Nov 7, 2024
0b2225b
Update docs catalog
Supereg Nov 7, 2024
81e72c0
Minor docs changes
Supereg Nov 10, 2024
dbb560b
Merge branch 'main' into feature/accessory-setup-kit
Supereg Nov 10, 2024
ecf84d3
Fix compilation on macOS
Supereg Nov 10, 2024
e00b547
Fix Ci
Supereg Nov 10, 2024
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
28 changes: 23 additions & 5 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,32 @@ on:
workflow_dispatch:

jobs:
packageios:
package_ios:
name: Build and Test Swift Package iOS
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
runsonlabels: '["macOS", "self-hosted", "spezi"]'
scheme: SpeziBluetooth-Package
artifactname: SpeziBluetooth-Package.xcresult
resultBundle: SpeziBluetooth-Package.xcresult
artifactname: SpeziBluetooth-iOS.xcresult
resultBundle: SpeziBluetooth-iOS.xcresult
buildandtest_visionos:
name: Build and Test Swift Package visionOS
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
runsonlabels: '["macOS", "self-hosted"]'
scheme: SpeziBluetooth-Package
destination: 'platform=visionOS Simulator,name=Apple Vision Pro'
resultBundle: SpeziBluetooth-visionOS.xcresult
artifactname: SpeziBluetooth-visionOS.xcresult
buildandtest_watchos:
name: Build and Test Swift Package watchOS
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
runsonlabels: '["macOS", "self-hosted"]'
scheme: SpeziBluetooth-Package
destination: 'platform=watchOS Simulator,name=Apple Watch Series 10 (46mm)'
resultBundle: SpeziBluetooth-watchOS.xcresult
artifactname: SpeziBluetooth-watchOS.xcresult
ios:
name: Build and Test iOS
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
Expand All @@ -48,9 +66,9 @@ jobs:
secrets: inherit
uploadcoveragereport:
name: Upload Coverage Report
needs: [packageios, ios, macos]
needs: [package_ios, buildandtest_visionos, buildandtest_watchos, ios, macos]
uses: StanfordSpezi/.github/.github/workflows/create-and-upload-coverage-report.yml@v2
with:
coveragereports: SpeziBluetooth-Package.xcresult TestApp-iOS.xcresult TestApp-macOS.xcresult
coveragereports: SpeziBluetooth-iOS.xcresult SpeziBluetooth-visionOS.xcresult SpeziBluetooth-watchOS.xcresult TestApp-iOS.xcresult TestApp-macOS.xcresult
secrets:
token: ${{ secrets.CODECOV_TOKEN }}
17 changes: 11 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

//
// This source file is part of the Stanford Spezi open source project
//
//
// SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md)
//
//
// SPDX-License-Identifier: MIT
//

Expand All @@ -18,16 +18,20 @@ let package = Package(
platforms: [
.iOS(.v17),
.macCatalyst(.v17),
.macOS(.v14)
.macOS(.v14),
.visionOS(.v1),
.watchOS(.v10),
.tvOS(.v17)
],
products: [
.library(name: "SpeziBluetoothServices", targets: ["SpeziBluetoothServices"]),
.library(name: "SpeziBluetooth", targets: ["SpeziBluetooth"])
],
dependencies: [
.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/SpeziNetworking", from: "2.1.0"),
.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/SpeziNetworking.git", from: "2.1.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.59.0"),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.4"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.2.0"),
Expand All @@ -38,6 +42,7 @@ let package = Package(
name: "SpeziBluetooth",
dependencies: [
.product(name: "Spezi", package: "Spezi"),
.product(name: "SpeziViews", package: "SpeziViews"),
.product(name: "NIO", package: "swift-nio"),
.product(name: "OrderedCollections", package: "swift-collections"),
.product(name: "SpeziFoundation", package: "SpeziFoundation"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// 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
//

#if canImport(AccessorySetupKit) && !os(macOS)
import AccessorySetupKit


extension ASAccessoryEventType: @retroactive CustomStringConvertible, @retroactive CustomDebugStringConvertible {
public var description: String {
switch self {
case .unknown:
"unknown"
case .activated:
"activated"
case .invalidated:
"invalidated"
case .migrationComplete:
"migrationComplete"
case .accessoryAdded:
"accessoryAdded"
case .accessoryRemoved:
"accessoryRemoved"
case .accessoryChanged:
"accessoryChanged"
case .pickerDidPresent:
"pickerDidPresent"
case .pickerDidDismiss:
"pickerDidDismiss"
case .pickerSetupBridging:
"pickerSetupBridging"
case .pickerSetupFailed:
"pickerSetupFailed"
case .pickerSetupPairing:
"pickerSetupPairing"
case .pickerSetupRename:
"pickerSetupRename"
@unknown default:
"ASAccessoryEventType(rawValue: \(rawValue))"
}
}

Check warning on line 45 in Sources/SpeziBluetooth/AccessorySetupKit/ASAccessoryEventType+Description.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziBluetooth/AccessorySetupKit/ASAccessoryEventType+Description.swift#L14-L45

Added lines #L14 - L45 were not covered by tests

public var debugDescription: String {
description
}

Check warning on line 49 in Sources/SpeziBluetooth/AccessorySetupKit/ASAccessoryEventType+Description.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziBluetooth/AccessorySetupKit/ASAccessoryEventType+Description.swift#L47-L49

Added lines #L47 - L49 were not covered by tests
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// 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
//

#if canImport(AccessorySetupKit) && !os(macOS)
import AccessorySetupKit


@available(iOS 18, *)
@available(macCatalyst, unavailable)
@available(visionOS, unavailable)
extension ASDiscoveryDescriptor.Range: @retroactive CustomStringConvertible, @retroactive CustomDebugStringConvertible {
public var description: String {
switch self {
case .default:
"default"
case .immediate:
"immediate"
@unknown default:
"Range(rawValue: \(rawValue))"
}
}

Check warning on line 26 in Sources/SpeziBluetooth/AccessorySetupKit/ASDiscoveryDescriptor.Range+Description.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziBluetooth/AccessorySetupKit/ASDiscoveryDescriptor.Range+Description.swift#L17-L26

Added lines #L17 - L26 were not covered by tests

public var debugDescription: String {
description
}

Check warning on line 30 in Sources/SpeziBluetooth/AccessorySetupKit/ASDiscoveryDescriptor.Range+Description.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziBluetooth/AccessorySetupKit/ASDiscoveryDescriptor.Range+Description.swift#L28-L30

Added lines #L28 - L30 were not covered by tests
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// 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 Foundation


/// An event handler registration for accessory events.
///
/// It automatically cancels the subscription once this value is de-initialized.
public struct AccessoryEventRegistration: ~Copyable, Sendable {
private let id: UUID
private weak var setupKit: (AnyObject & Sendable)? // type erased as AccessorySetupKit is only available on iOS 18 platform.

@available(iOS 18.0, *)
@available(macCatalyst, unavailable)
init(id: UUID, setupKit: AccessorySetupKit?) {
self.id = id
self.setupKit = setupKit
}

Check warning on line 24 in Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift#L21-L24

Added lines #L21 - L24 were not covered by tests

static func cancel(id: UUID, setupKit: (AnyObject & Sendable)?, isolation: isolated (any Actor)? = #isolation) {

Check warning on line 26 in Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift#L26

Added line #L26 was not covered by tests
#if os(iOS) && !targetEnvironment(macCatalyst)
guard #available(iOS 18, *) else {
return
}

guard let setupKit, let typedSetupKit = setupKit as? AccessorySetupKit else {
return
}

typedSetupKit.cancelHandler(for: id)

Check warning on line 36 in Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift#L28-L36

Added lines #L28 - L36 were not covered by tests
#else
preconditionFailure("Not available on this platform!")

Check warning on line 38 in Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift#L38

Added line #L38 was not covered by tests
#endif
}

Check warning on line 40 in Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift#L40

Added line #L40 was not covered by tests

/// Cancel the subscription.
/// - Parameter isolation: Inherits the current actor isolation. If running on the MainActor cancellation is processed instantly.
public func cancel(isolation: isolated (any Actor)? = #isolation) {
Self.cancel(id: id, setupKit: setupKit)
}

Check warning on line 46 in Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziBluetooth/AccessorySetupKit/AccessoryEventRegistration.swift#L44-L46

Added lines #L44 - L46 were not covered by tests

deinit {
Self.cancel(id: id, setupKit: setupKit)
}
}
Loading
Loading