Auto launch (window.Electron.autoLaunch)
Launch-at-login, backed by Electron's login item settings. Source: src/main/auto-launch.ts, channel prefix autoLaunch:*. Always on, no config needed — this is a runtime on/off switch, not something you enable in electron.config.ts.
macOS/Windows only. app.setLoginItemSettings() is a silent no-op on Linux (there's no consistent autostart mechanism across distros for Electron to hook into), so this module gates it explicitly rather than let a caller believe setEnabled(true) took effect when it didn't.
Methods
| Method | Returns | Notes |
|---|---|---|
isEnabled() |
Promise<boolean> |
Throws UNSUPPORTED_OS on Linux. |
setEnabled(enabled: boolean) |
Promise<boolean> |
Throws UNSUPPORTED_OS on Linux. Resolves the resulting openAtLogin state. |
getSettings() |
Promise<Electron.LoginItemSettings> |
Works on every platform — returns whatever app.getLoginItemSettings() reports (empty/default values on Linux, since nothing was ever set). |
Example
import { isIpcError } from '@devioarts/electron';
try {
await window.Electron.autoLaunch.setEnabled(true);
} catch (e) {
if (isIpcError(e) && e.code === 'UNSUPPORTED_OS') return; // expected on Linux
throw e;
}
Or with .safe, without a try/catch:
const result = await window.Electron.safe.autoLaunch.setEnabled(true);
if (!result.ok && result.error.code !== 'UNSUPPORTED_OS') console.error(result.error.message);
.safe
Fully mirrored — window.Electron.safe.autoLaunch.* resolves { ok: true, data } / { ok: false, error: { code: 'UNSUPPORTED_OS', ... } } instead of throwing. This is the module the README/Usage examples reach for first when explaining .safe, since UNSUPPORTED_OS on Linux is an expected, everyday branch rather than an exceptional failure.