Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/launchatlogin-modern
Add “Launch at Login” functionality to your macOS app in seconds
https://github.com/sindresorhus/launchatlogin-modern
macos swift swift-package swiftui swiftui-components
Last synced: about 15 hours ago
JSON representation
Add “Launch at Login” functionality to your macOS app in seconds
- Host: GitHub
- URL: https://github.com/sindresorhus/launchatlogin-modern
- Owner: sindresorhus
- License: mit
- Created: 2022-11-13T16:00:10.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-11T20:35:45.000Z (9 months ago)
- Last Synced: 2024-04-14T11:09:13.995Z (5 months ago)
- Topics: macos, swift, swift-package, swiftui, swiftui-components
- Language: Swift
- Homepage:
- Size: 6.84 KB
- Stars: 304
- Watchers: 6
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# 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](https://github.com/sindresorhus/LaunchAtLogin).
## Requirements
macOS 13+
## Install
Add `https://github.com/sindresorhus/LaunchAtLogin-Modern` in the [“Swift Package Manager” tab in Xcode](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app).
## Usage
Put the toggle in your `Settings` scene. That's it.
```swift
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:
```swift
import SwiftUI
import LaunchAtLoginstruct 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:
```swift
import LaunchAtLoginprint(LaunchAtLogin.isEnabled)
//=> falseLaunchAtLogin.isEnabled = true
print(LaunchAtLogin.isEnabled)
//=> true
```## Note
The [Mac App Store guidelines](https://developer.apple.com/app-store/review/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
- [Defaults](https://github.com/sindresorhus/Defaults) - Swifty and modern UserDefaults
- [KeyboardShortcuts](https://github.com/sindresorhus/KeyboardShortcuts) - Add user-customizable global keyboard shortcuts to your macOS app
- [DockProgress](https://github.com/sindresorhus/DockProgress) - Show progress in your app's Dock icon
- [More…](https://github.com/search?q=user%3Asindresorhus+language%3Aswift+archived%3Afalse&type=repositories)