Launch at login
Enable, disable, and query launch at login from Kotlin with one API that picks the backend for the current packaging format.
The autolaunch module enables, disables, and queries launch at login with one API on Windows
(MSIX and Win32), macOS 13+, Linux and Flatpak. It respects choices the user made outside your app.
autolaunchGradle plugin: RecommendedWindow runtime: Not neededLogin detection and the MSIX startup task depend on the packaged build.Add the dependency
dependencies {
implementation("dev.nucleusframework:nucleus.autolaunch:3.0.0")
}For MSIX, set appx { addAutoLaunchExtension = true }. Without it, the API returns UNSUPPORTED.
Check and toggle auto-launch
when (AutoLaunch.state()) {
AutoLaunchState.ENABLED -> {}
AutoLaunchState.DISABLED -> AutoLaunch.enable()
AutoLaunchState.DISABLED_BY_USER -> AutoLaunch.openSystemSettings()
AutoLaunchState.UNSUPPORTED -> { /* macOS < 13, unsupported Linux setup */ }
else -> {}
}Do not retry on BLOCKED_BY_USER. After the user turns the app off in Task Manager or System
Settings, enable() returns BLOCKED_BY_USER until they turn it back on there. Send them to
openSystemSettings().
Detect a login launch
wasStartedAtLogin(args) reports whether login started the process, for example to start hidden.
nucleusApplication caches the answer at startup, so later calls can pass an empty array:
LaunchedEffect(Unit) {
startedAtLogin = AutoLaunch.wasStartedAtLogin(emptyArray())
}On macOS, a call made before nucleusApplication returns false. It returns false in dev runs.
Notes
- On MSIX, Task Manager's Startup apps tab refreshes only after the next login. The stored state is already correct.
- The Linux unit starts after
graphical-session.targetandgnome-session-x11-services-ready.target. systemd ignores the second target outside GNOME.
API reference
AutoLaunch | Returns | Notes |
|---|---|---|
state() | AutoLaunchState | Current state. |
enable() / disable() | AutoLaunchResult | Turns auto-launch on or off. |
openSystemSettings() | Boolean | Opens Startup apps (Windows) or Login Items (macOS). |
wasStartedAtLogin(args) | Boolean | Whether login started this process. |
isEnabled() | Boolean | ENABLED or ENABLED_BY_POLICY. |
isUserLocked() | Boolean | DISABLED_BY_USER. |
diagnostic() | String | Backend trace for support tickets. |
preload() | Unit | Call off the UI thread to avoid a first-call stall on macOS. |
AutoLaunchState:ENABLED,DISABLED,DISABLED_BY_USER,DISABLED_BY_POLICY,ENABLED_BY_POLICY(read-only, MSIX Group Policy),UNSUPPORTED.AutoLaunchResult:OK,UNCHANGED,BLOCKED_BY_USER,BLOCKED_BY_POLICY,UNSUPPORTED,ERROR.
AutoLaunchConfig, set before the first AutoLaunch call:
| Property | Default | Affects |
|---|---|---|
taskId | NucleusApp.startupTaskId, then appId | MSIX <uap5:StartupTask TaskId> |
executablePath | The running executable | Win32 Run command |
autostartArgument | "--nucleus-autostart" | Login marker; null omits it |
registryValueName | NucleusApp.appName, then appId | Win32 Run value name |
backgroundReason | null | Flatpak portal prompt |
What's next
- Service management: agents and daemons on macOS.
- Application entry point: what
nucleusApplicationprimes at startup. - Scheduler: background work after a login launch.
Last updated on