Skip to content

Restore LaunchAtLogin migration - #1336

Merged
lujjjh merged 1 commit into
linearmouse:mainfrom
YuriNachos:fix/launch-at-login-reRegister-1328
Aug 8, 2026
Merged

lujjjh merged 1 commit into
linearmouse:mainfrom
YuriNachos:fix/launch-at-login-reRegister-1328

Conversation

@YuriNachos

@YuriNachos YuriNachos commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Commit 5437d88 (PR #835) accidentally deleted AppDelegate's override init() that ran LaunchAtLogin.migrateIfNeeded(), so the macOS 13 legacy → SMAppService login-item migration stopped running and import LaunchAtLogin became 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).
  • Full suite green: 531 tests, 0 failures (8 new in LinearMouseUnitTests/AppDelegate/LoginItemManagerTests).

Closes #1328

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Defaults key (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.

Comment thread LinearMouse/AppDelegate.swift Outdated
Comment on lines +283 to +288
guard isEnabled() else {
return .failed(
status: previousStatus,
errorDescription: "registration did not take effect"
)
}
Comment thread LinearMouse/AppDelegate.swift Outdated
Comment on lines +97 to +99
private func ensureLoginItemRegistration() {
let outcome = LoginItemManager.live.ensureRegistration(intent: Defaults[.startAtLoginIntent])
switch outcome {
@lujjjh

lujjjh commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Thanks for investigating this and for the thorough tests. Restoring LaunchAtLogin.migrateIfNeeded() is definitely useful, but that method only performs the one-time migration from the legacy login helper to SMAppService; it does not restore a modern registration that macOS has subsequently lost.

For the latter case, I’m not sure we should persist a separate intent and automatically re-register. Once the system status becomes notRegistered, we cannot reliably distinguish between macOS losing the registration and the user disabling it in System Settings. Automatically restoring it could therefore override an explicit user choice.

I think the simpler and safer approach would be to:

  • Restore the migrateIfNeeded() call directly.
  • Continue treating the actual system status as the single source of truth.
  • Let the user enable “Start at login” again if the registration is lost.
  • Surface .requiresApproval to the user when appropriate.

This would also avoid introducing the new Defaults key and the additional recovery state. One detail to watch is the menu item: LaunchAtLogin.publisher publishes the requested value even if registration fails, so it may not reflect the actual system status in that case.

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]>
@YuriNachos
YuriNachos force-pushed the fix/launch-at-login-reRegister-1328 branch from 1a8de2b to bd1f97c Compare August 7, 2026 21:38
@lujjjh

lujjjh commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

@lujjjh lujjjh changed the title Restore LaunchAtLogin migration and re-register when macOS drops the login item Restore LaunchAtLogin migration Aug 8, 2026
@lujjjh lujjjh added the bug Something isn't working label Aug 8, 2026
@lujjjh
lujjjh merged commit 0790b4f into linearmouse:main Aug 8, 2026
1 check passed
@YuriNachos
YuriNachos deleted the fix/launch-at-login-reRegister-1328 branch August 10, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start at login silently breaks when macOS loses the registration; the app never re-registers (and #445's migration call was accidentally removed)

3 participants