Repository navigation
Fix BLE Logitech sleep wake handling - #1182
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses unintended wake-ups on macOS caused by BLE Logitech HID++ activity by stopping device observation/monitoring across sleep and inactive sessions, reducing background HID++ polling for direct BLE devices, and caching direct BLE battery readings to avoid unnecessary queries.
Changes:
- Stop LinearMouse services during
NSWorkspace.willSleepNotificationand inactive user sessions; restart only when allowed. - Avoid periodic HID++ inventory polling for direct BLE Logitech devices; refresh direct BLE battery opportunistically and cache results across sleep/wake.
- Harden teardown of HID resources and expand unit tests around Logitech BLE/USB matching and inventory behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Modules/PointerKit/Sources/PointerKit/PointerDevice.swift | Unregister HID callbacks before unscheduling/closing; deallocate report buffer after close. |
| LinearMouseUnitTests/Device/VendorSpecificDeviceMetadataTests.swift | Add/rename tests for Logitech BLE/USB matching, inventory BLE inclusion behavior, and controls monitor conditions. |
| LinearMouse/UI/Header/DeviceIndicator/DevicePickerSheet/DevicePickerState.swift | Stop triggering device-picker-driven BLE battery refresh on cached models. |
| LinearMouse/UI/Header/DeviceIndicator/DevicePickerSheet/DevicePickerBatteryCoordinator.swift | Remove device-picker coordinator that could query direct BLE metadata on startup. |
| LinearMouse/Model/DeviceModel.swift | Remove automatic device-picker battery refresh path from model initialization. |
| LinearMouse/Device/VendorSpecific/Logitech/LogitechHIDPPDeviceMetadataProvider.swift | Refine controls-monitor “needed” logic for direct BLE devices; add worker-stop coordination during shutdown. |
| LinearMouse/Device/VendorSpecific/ConnectedLogitechDeviceInventory.swift | Add opt-in BLE inclusion and cancellation hook to avoid implicit BLE polling. |
| LinearMouse/Device/VendorSpecific/BatteryDeviceMonitor.swift | Cache direct BLE Logitech battery readings across sleep/wake; add controlled refresh logic and cancellation checks. |
| LinearMouse/Device/DeviceManager.swift | Avoid applying pointer speed updates when the manager is not running. |
| LinearMouse/Device/Device.swift | Trigger direct BLE Logitech battery refresh based on real device activity (markActive). |
| LinearMouse/AppDelegate.swift | Gate start/stop based on session active state and sleep/wake notifications. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1736
to
+1741
| reconfigurationSemaphore.signal() | ||
| notificationEndpoint?.wake() | ||
| thread?.cancel() | ||
| if let thread, thread !== Thread.current { | ||
| _ = stoppedSemaphore?.wait(timeout: .now() + Constants.stopTimeout) | ||
| } |
Comment on lines
138
to
141
| func markActive(reason: String) { | ||
| manager?.markDeviceActive(self, reason: reason) | ||
| BatteryDeviceMonitor.shared.refreshDirectLogitechBluetoothBatteryIfNeeded(for: self) | ||
| } |
Comment on lines
+24
to
+30
| // Preserve direct BLE Logitech battery data across sleep/wake. DeviceManager may briefly | ||
| // report no BLE device while macOS rebuilds HID services after wake. | ||
| private var directLogitechBluetoothCache = [String: ConnectedBatteryDeviceInfo]() | ||
| private var directLogitechBluetoothSuccessfulRefreshDates = [String: Date]() | ||
| private var directLogitechBluetoothFailedRefreshDates = [String: Date]() | ||
| private var directLogitechBluetoothRefreshesInFlight = Set<String>() | ||
| private let directLogitechBluetoothLock = NSLock() |
This was referenced Aug 18, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #1177
Testing
git diff --checkxcodebuild -quiet -derivedDataPath /tmp/linearmouse-deriveddata-1177-review-build2 -project LinearMouse.xcodeproj -scheme LinearMouse -configuration Debug -destination 'platform=macOS' buildxcodebuild -quiet -derivedDataPath /tmp/linearmouse-deriveddata-1177-review-test -project LinearMouse.xcodeproj -scheme LinearMouse -configuration Debug -destination 'platform=macOS' test