Swiftpack.co - sindresorhus/LaunchAtLogin-Modern as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by sindresorhus.
sindresorhus/LaunchAtLogin-Modern v1.1.0
Add “Launch at Login” functionality to your macOS app in seconds
⭐️ 306
🕓 17 weeks ago
macOS macCatalyst
.package(url: "https://github.com/sindresorhus/LaunchAtLogin-Modern.git", from: "v1.1.0")

LaunchAtLogin

Add “Launch at Login” functionality to your macOS app in seconds

This package is meant for apps targeting macOS 13 or later. If you need backwards-compatibility, check out the old LaunchAtLogin package.

Requirements

macOS 13+

Install

Add https://github.com/sindresorhus/LaunchAtLogin-Modern in the “Swift Package Manager” tab in Xcode.

Usage

Put the toggle in your Settings scene. That's it.

import SwiftUI
import LaunchAtLogin

@main
struct MyApp: App {
	var body: some Scene {
		Settings {
			Form {
				LaunchAtLogin.Toggle()
			}
		}
	}
}

The LaunchAtLogin.Toggle view works similarly to the built-in Toggle except that is has a predefined binding and label.

The default label is "Launch at login", but it can be overridden:

import SwiftUI
import LaunchAtLogin

struct SettingsScreen: View {
	var body: some View {
		LaunchAtLogin.Toggle("Launch at login 🦄")

		// Or
		LaunchAtLogin.Toggle {
			Text("Launch at login 🦄")
		}
	}
}

You can also access the state directly:

import LaunchAtLogin

print(LaunchAtLogin.isEnabled)
//=> false

LaunchAtLogin.isEnabled = true

print(LaunchAtLogin.isEnabled)
//=> true

Note

The Mac App Store guidelines require “launch at login” functionality to be enabled in response to a user action. Your app will be rejected if you set the state to true by default.

FAQ

How is this different from the old package?

This is a new repo as the old package had a lot of bloat in its Git history. I also took the opportunity to make a more minimal API optimized for SwiftUI apps.

Related

GitHub

link
Stars: 307
Last commit: 14 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

17 weeks ago
  • Add wasLaunchedAtLogin property
  • Fix compatibility with Catalyst and usage in multi-platform apps

https://github.com/sindresorhus/LaunchAtLogin-Modern/compare/v1.0.0...v1.1.0

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics