Repository navigation
Restore LaunchAtLogin migration - #1336
Conversation
There was a problem hiding this comment.
Pull request overview
Restores the LaunchAtLogin legacy→SMAppService migration on the app’s launch path and adds a launch-time recovery mechanism to re-register the login item when macOS drops the Background Task Management registration, keeping UI state in sync via LaunchAtLogin.isEnabled.
Changes:
- Reintroduce a launch-path migration hook in
AppDelegate.init()and add launch-time login item re-registration with structured logging. - Persist a new
Defaultskey (startAtLoginIntent) representing the user’s explicit “Start at login” choice, and route UI toggles through a helper that records intent. - Add unit tests covering migration wiring, re-registration behavior, intent capture, and decision predicates.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| LinearMouse/AppDelegate.swift | Restores migration call via an injectable hook; adds login-item recovery logic and a LoginItemManager abstraction/outcome enum. |
| LinearMouse/DefaultsKeys.swift | Introduces startAtLoginIntent defaults key to persist the user’s intent independently of live SMAppService status. |
| LinearMouse/UI/GeneralSettings/GeneralSettings.swift | Replaces LaunchAtLogin.Toggle with a custom binding that records intent on user toggles. |
| LinearMouse/UI/StatusItem.swift | Routes the menu-bar toggle through LoginItemManager.setUserEnabled to persist intent. |
| LinearMouseUnitTests/AppDelegate/LoginItemManagerTests.swift | Adds coverage for migration hook wiring, re-registration outcomes, intent persistence, and predicate logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| guard isEnabled() else { | ||
| return .failed( | ||
| status: previousStatus, | ||
| errorDescription: "registration did not take effect" | ||
| ) | ||
| } |
| private func ensureLoginItemRegistration() { | ||
| let outcome = LoginItemManager.live.ensureRegistration(intent: Defaults[.startAtLoginIntent]) | ||
| switch outcome { |
|
Thanks for investigating this and for the thorough tests. Restoring For the latter case, I’m not sure we should persist a separate intent and automatically re-register. Once the system status becomes I think the simpler and safer approach would be to:
This would also avoid introducing the new Defaults key and the additional recovery state. One detail to watch is the menu item: Thanks again for working on this! |
Commit 5437d88 accidentally removed `AppDelegate.override init()`, so the one-time legacy login-helper -> SMAppService migration (`LaunchAtLogin.migrateIfNeeded()`) stopped running on macOS 13+. Restore the call directly, matching the original wiring from 1220086. Per review, do NOT auto-recover a registration macOS has dropped: keep treating the actual `SMAppService` status as the single source of truth and let the user re-enable "Start at login" themselves. This drops the Defaults intent key and the recovery state introduced in the earlier revision of this branch. StatusItem: the menu checkmark now re-reads the actual `SMAppService` status inside the `LaunchAtLogin.publisher` sink instead of the *requested* value the publisher forwards (it publishes `newValue` unconditionally, even when the registration lands at `.requiresApproval` or fails). The checkmark therefore no longer shows a stale "on" state after a failed registration. Co-Authored-By: Claude <[email protected]>
1a8de2b to
bd1f97c
Compare
|
Thanks! |
Summary
Commit 5437d88 (PR #835) accidentally deleted
AppDelegate'soverride init()that ranLaunchAtLogin.migrateIfNeeded(), so the macOS 13 legacy →SMAppServicelogin-item migration stopped running andimport LaunchAtLoginbecame a dead import.This restores the migration on the launch path.
Verification
make configure clean lint test XCODEBUILD_ARGS="CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= DEVELOPMENT_TEAM="swiftformat --lint .clean;swiftlint .0 serious (96 pre-existing warnings, none in changed files).LinearMouseUnitTests/AppDelegate/LoginItemManagerTests).Closes #1328