Giter Site home page Giter Site logo

launchatlogin-modern's Introduction

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

launchatlogin-modern's People

Contributors

sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

launchatlogin-modern's Issues

'mainApp' is only available in Mac Catalyst 16.0 or newer

Hello, if I want to use LaunchAtLogin in a catalyst app, it only seems possible since 16.0, otherwise there are build errors 'mainApp' is only available in Mac Catalyst 16.0 or newer.

Could you please update Package.swift to reflect this (I don't have experience with authoring swift packages)?

not working for test flight builds.

I have implement this in my app which is working correctly in the device in which I have created the app. I have tested this by exporting app in my device but as soon as I upload the same on ten flight and I download it in another device and the app is not restarting by it self in that device after login though it is showing in system preferences in login items

Multi-platform build support

Perhaps I'm approaching this incorrectly, but I'm having problems previewing SwiftUI for iOS while this package is added to the project.

I have disabled LaunchAtLogin and MenuBarExtraAccess for iOS like this:

image

This makes it possible to build the project for iOS, but I still get a crash when previewing.

image

Any ideas on how to make previews work would be amazing. Otherwise, and it probably makes little sense for you to do it since this is explicitly a macOS package, adding #if os(macOS) around the code in this package and MenuBarExtraAccess, would make the package build on iOS.

Thank you

How to listen to toggle changed event?

The older version of LaunchAtLogin has an observable property that can be used to listen to change events.

How can I achieve the same with this version?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.