Skip to content

macOS: notify about already-connected devices at the same time#363

Open
micolous wants to merge 1 commit into
mozilla:ctap2-2021from
micolous:macos-initial-enumeration
Open

macOS: notify about already-connected devices at the same time#363
micolous wants to merge 1 commit into
mozilla:ctap2-2021from
micolous:macos-initial-enumeration

Conversation

@micolous

@micolous micolous commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #362, unblocks #315

This calls IOHIDManagerCopyDevices before starting the CFRunLoop for IOHIDManager, so that there is a single DevicesAdded event containing all already-connected devices, much like you'd get on Linux. If there are zero connected devices, then it's effecttively DevicesAdded(vec![]).

This addresses a potential race condition if IOHIDManager is slow to notify about a device which is already connected.

IOHIDManager still calls DeviceMatchingCallback for every already-connected device once a CFRunLoop has started, so this also ignores duplicate events.

… and notify about all existing devices at the same time (mozilla#362)
return Vec::with_capacity(0);
}

let s: CFSet<IOHIDDeviceRef> = CFSet::wrap_under_get_rule(devices);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since IOHIDManagerCopyDevices has Copy in the name, we need to use CFSet::wrap_under_create_rule here to avoid a leak.

}

/// Get all currently-connected devices.
fn get_devices(&mut self) -> Vec<IOHIDDeviceRef> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: get_devices(&self)

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.

macOS: potential race with initially-connected devices

2 participants