feat: add Launch at Login toggle using SMAppService - #63
Merged
Conversation
Add a 'Launch at Login' toggle in Settings → General → Behavior that registers VocaMac as a login item using the modern SMAppService API (macOS 13+). No helper app or additional entitlements required. Implementation: - Wire up the existing launchAtLogin @AppStorage property to SMAppService.mainApp.register()/unregister() - Add setLaunchAtLogin() method with error handling that reverts the preference to match actual system state on failure - Add syncLaunchAtLogin() on init to reconcile persisted preference with system state (handles re-installs, manual System Settings changes) - Add Toggle in SettingsView General tab Behavior section - Use custom Binding to route through setLaunchAtLogin() instead of directly binding to @AppStorage Closes #60
Add a Launch at Login switch in the menu bar popover's actions section, above the Settings button. Uses the same Binding through setLaunchAtLogin() as the Settings toggle, ensuring both stay in sync.
Remove the Launch at Login toggle from the menu bar popover (it didn't fit well visually) and add it to the Setup Wizard's completion step. The toggle now appears on the 'You're All Set!' screen with a sunrise icon and description text, giving users a natural place to enable it during initial setup. It remains in sync with the Settings toggle.
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.
Closes #60
Summary
Adds a Launch at Login feature using the modern
SMAppServiceAPI (macOS 13+). The toggle appears in two places:Both toggles stay in sync via the same
setLaunchAtLogin()method. No helper app or additional entitlements required.Implementation
AppState (
AppState.swift)setLaunchAtLogin(_ enabled: Bool)— Registers/unregisters viaSMAppService.mainApp. On failure, reverts thelaunchAtLoginpreference to match the actual system state so the toggle never gets out of sync.syncLaunchAtLogin()— Called once on init to reconcile the persisted@AppStoragepreference with the system's login item state. Handles edge cases like re-installs, or the user toggling the setting directly in System Settings → General → Login Items.import ServiceManagementSettingsView (
SettingsView.swift)Toggle("Launch at Login", ...)as the first item in the Behavior sectionBindingthat routes throughsetLaunchAtLogin()OnboardingView (
OnboardingView.swift)BindingthroughsetLaunchAtLogin(), staying in sync with the Settings toggleNo entitlement changes needed
SMAppService.mainAppworks with both ad-hoc signed and Developer ID signed apps without any additional entitlements.Tests Added
5 new tests in
LaunchAtLoginTests:testLaunchAtLoginDefaultsToFalse— verifies the default preferencetestLaunchAtLoginPersistence— verifies@AppStorageround-triptestSetLaunchAtLoginEnableUpdatesPreference— verifies enable syncs with system statetestSetLaunchAtLoginDisableUpdatesPreference— verifies disable syncs with system statetestSetLaunchAtLoginToggleRoundTrip— verifies enable → disable doesn't crash and stays consistentTesting
All 62 tests pass (
swift test). Manually verified: