Skip to content

Commit

Permalink
Merge branch 'main' into feature/accessory-setup-kit
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Nov 10, 2024
2 parents 81e72c0 + 4d64dfa commit dbb560b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ jobs:
contents: read
with:
runsonlabels: '["macOS", "self-hosted", "bluetooth"]'
setupsigning: true
path: 'Tests/UITests'
setupsigning: true
artifactname: TestApp-macOS.xcresult
resultBundle: TestApp-macOS.xcresult
customcommand: "set -o pipefail && xcodebuild test -scheme 'TestApp' -configuration 'Test' -destination 'platform=macOS,arch=arm64,variant=Mac Catalyst' -derivedDataPath '.derivedData' -resultBundlePath 'TestApp-macOS.xcresult' -skipPackagePluginValidation -skipMacroValidation | xcbeautify"
Expand Down
3 changes: 0 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ let package = Package(
resources: [
.process("Resources")
],
swiftSettings: [
.swiftLanguageMode(.v5) // see https://github.com/swiftlang/swift/issues/76005
],
plugins: [] + swiftLintPlugin()
),
.target(
Expand Down
15 changes: 8 additions & 7 deletions Sources/SpeziBluetooth/Bluetooth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,17 @@ public final class Bluetooth: Module, EnvironmentAccessible, @unchecked Sendable

nonisolated static let logger = Logger(subsystem: "edu.stanford.spezi.bluetooth", category: "Bluetooth")

@SpeziBluetooth private let bluetoothManager = BluetoothManager()
private let bluetoothManager = BluetoothManager()

/// The Bluetooth device configuration.
///
/// Set of configured ``BluetoothDevice`` with their corresponding ``DiscoveryCriteria``.
public nonisolated let configuration: Set<DeviceDiscoveryDescriptor>

// sadly Swifts "lazy var" won't work here with strict concurrency as it doesn't isolate the underlying lazy storage
@SpeziBluetooth private var _lazy_discoveryConfiguration: Set<DiscoveryDescription>?
private var _lazy_discoveryConfiguration: Set<DiscoveryDescription>?
// swiftlint:disable:previous discouraged_optional_collection identifier_name
@SpeziBluetooth private var discoveryConfiguration: Set<DiscoveryDescription> {
private var discoveryConfiguration: Set<DiscoveryDescription> {
guard let discoveryConfiguration = _lazy_discoveryConfiguration else {
let discovery = configuration.parseDiscoveryDescription()
self._lazy_discoveryConfiguration = discovery
Expand Down Expand Up @@ -306,8 +306,10 @@ public final class Bluetooth: Module, EnvironmentAccessible, @unchecked Sendable

/// Stores the connected device instance for every configured ``BluetoothDevice`` type.
@Model @MainActor private var connectedDevicesModel = ConnectedDevicesModel()

// we need to manually declare the synthesized property wrapper to avoid https://github.com/swiftlang/swift/issues/76005#issuecomment-2466703851
/// Injects the ``BluetoothDevice`` instances from the `ConnectedDevices` model into the SwiftUI environment.
@Modifier @MainActor private var devicesInjector: ConnectedDevicesEnvironmentModifier
@MainActor private var _devicesInjector: Modifier<ConnectedDevicesEnvironmentModifier>


/// Configure the Bluetooth Module.
Expand All @@ -324,13 +326,12 @@ public final class Bluetooth: Module, EnvironmentAccessible, @unchecked Sendable
/// - Parameter devices: The set of configured devices.
@MainActor
public init(
@DiscoveryDescriptorBuilder _ devices: @Sendable () -> Set<DeviceDiscoveryDescriptor>
@DiscoveryDescriptorBuilder _ devices: () -> Set<DeviceDiscoveryDescriptor>
) {
let configuration = devices()
let deviceTypes = configuration.deviceTypes

self.configuration = configuration
self.devicesInjector = ConnectedDevicesEnvironmentModifier(configuredDeviceTypes: deviceTypes)
self._devicesInjector = Modifier(wrappedValue: ConnectedDevicesEnvironmentModifier(from: configuration))

Task { @SpeziBluetooth in
self.observeDiscoveredDevices()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ public final class GATTCharacteristic {
}

if shouldNotifyCapture {
Task { @MainActor in
self.withMutation(keyPath: \.captured) {}
// self is never mutated or even accessed in the withMutation call
nonisolated(unsafe) let this = self
Task { @Sendable @MainActor in
this.withMutation(keyPath: \.captured) {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ struct ConnectedDevicesEnvironmentModifier: ViewModifier {
var connectedDevices


init(configuredDeviceTypes: [any BluetoothDevice.Type]) {
nonisolated init(configuredDeviceTypes: [any BluetoothDevice.Type]) {
self.configuredDeviceTypes = configuredDeviceTypes
}

nonisolated init(from configuration: Set<DeviceDiscoveryDescriptor>) {
self.init(configuredDeviceTypes: configuration.deviceTypes)
}


func body(content: Content) -> some View {
let modifiers = configuredDeviceTypes.map { $0.deviceEnvironmentModifier }
Expand Down
24 changes: 6 additions & 18 deletions Tests/UITests/UITests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1540;
LastUpgradeCheck = 1610;
TargetAttributes = {
2F6D139128F5F384007C25D6 = {
CreatedOnToolsVersion = 14.1;
Expand Down Expand Up @@ -445,12 +445,11 @@
2F6D13B728F5F386007C25D6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 637867499T;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 637867499T;
ENABLE_HARDENED_RUNTIME = NO;
Expand Down Expand Up @@ -485,16 +484,14 @@
2F6D13B828F5F386007C25D6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = 637867499T;
DEVELOPMENT_TEAM = 637867499T;
ENABLE_HARDENED_RUNTIME = NO;
ENABLE_PREVIEWS = YES;
ENABLE_TESTING_SEARCH_PATHS = YES;
Expand Down Expand Up @@ -528,7 +525,6 @@
2F6D13BD28F5F386007C25D6 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 637867499T;
Expand All @@ -551,13 +547,10 @@
2F6D13BE28F5F386007C25D6 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = 637867499T;
DEVELOPMENT_TEAM = 637867499T;
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.0;
Expand Down Expand Up @@ -644,16 +637,14 @@
2FB07588299DDB6000C0B37F /* Test */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = 637867499T;
DEVELOPMENT_TEAM = 637867499T;
ENABLE_HARDENED_RUNTIME = NO;
ENABLE_PREVIEWS = YES;
ENABLE_TESTING_SEARCH_PATHS = YES;
Expand Down Expand Up @@ -687,13 +678,10 @@
2FB07589299DDB6000C0B37F /* Test */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = 637867499T;
DEVELOPMENT_TEAM = 637867499T;
GENERATE_INFOPLIST_FILE = YES;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
LastUpgradeVersion = "1610"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

0 comments on commit dbb560b

Please sign in to comment.