LaunchAtLogin

repository·main·Indexed 20 days ago

https://github.com/sindresorhus/launchatlogin-modern

A minimal, SwiftUI-optimized API for adding 'Launch at Login' functionality to macOS apps targeting macOS 13 or later. Provides a LaunchAtLogin.Toggle view for settings scenes and the LaunchAtLogin.isEnabled property for programmatic state management.

Tokens
597
Snippets
4
Records
5
Agent score
19%

What's inside launchatlogin-modern

  1. Add a Launch at Login toggle to your SwiftUI app

    main

    The easiest way to implement this functionality is to place LaunchAtLogin.Toggle() inside your app's Settings scene. The toggle manages its own state and provides a predefined label.

    import SwiftUI
    import LaunchAtLogin
    
    @main
    struct MyApp: App {
    	var body: some Scene {
    		Settings {
    			Form {
    				LaunchAtLogin.Toggle()
    			}
    		}
    	}
    }
  2. Access or modify the launch at login state programmatically

    main

    You can read or write the current launch at login status using the LaunchAtLogin.isEnabled property.

    import LaunchAtLogin
    
    // Read the current state
    print(LaunchAtLogin.isEnabled)
    
    // Set the state
    LaunchAtLogin.isEnabled = true
    
    print(LaunchAtLogin.isEnabled)
  3. Customize the LaunchAtLogin.Toggle label

    main

    The LaunchAtLogin.Toggle view behaves like a standard SwiftUI Toggle but uses a predefined binding. You can override the default label ("Launch at login") by passing a string directly to the initializer or by using a ViewBuilder closure.

    import SwiftUI
    import LaunchAtLogin
    
    struct SettingsScreen: View {
    	var body: some View {
    		// Using a string label
    		LaunchAtLogin.Toggle("Launch at login 🦄")
    
    		// Or using a ViewBuilder closure
    		LaunchAtLogin.Toggle {
    			Text("Launch at login 🦄")
    		}
    	}
    }