feat: add startup launch support (#1421)
Add launch-at-startup support across the Electron desktop app and the web CLI. Electron now supports macOS launch-at-login through the native login item API. Login launches start OpenChamber in the background without opening a window, while Dock activation, deep links, and second-instance launches still open or focus the normal app window. The desktop Settings UI now exposes a localized launch-at-login toggle in Desktop Network Access. The web CLI now includes `openchamber startup status|enable|disable`, backed by native user services: - macOS: launchd LaunchAgent - Linux: systemd --user service - Windows: Task Scheduler Startup services run `openchamber serve --foreground` so the OS service manager owns process lifetime and restarts. Foreground service updates now defer restarts to the service manager instead of spawning duplicate CLI restarts. Startup services snapshot useful environment variables by default so provider tokens, PATH, SSH agent settings, and OpenCode configuration survive login/reboot starts. The snapshot avoids shell/session-only state, uses systemd-compatible env quoting on Linux, and avoids unused env artifacts on macOS. Also adds localized docs for startup services and environment variables.
This commit is contained in:
committed by
GitHub
parent
e97bf0d9dc
commit
2014303bc0
@@ -3,7 +3,14 @@ import * as React from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { getDesktopLanAddress, isDesktopLocalOriginActive, isDesktopShell, restartDesktopApp } from '@/lib/desktop';
|
||||
import {
|
||||
getDesktopLanAddress,
|
||||
getDesktopLaunchAtLogin,
|
||||
isDesktopLocalOriginActive,
|
||||
isDesktopShell,
|
||||
restartDesktopApp,
|
||||
setDesktopLaunchAtLogin,
|
||||
} from '@/lib/desktop';
|
||||
import { useI18n } from '@/lib/i18n';
|
||||
|
||||
export const DesktopNetworkSettings: React.FC = () => {
|
||||
@@ -15,6 +22,9 @@ export const DesktopNetworkSettings: React.FC = () => {
|
||||
const [draftPassword, setDraftPassword] = React.useState('');
|
||||
const [isLoading, setIsLoading] = React.useState(true);
|
||||
const [isSaving, setIsSaving] = React.useState(false);
|
||||
const [launchAtLoginSupported, setLaunchAtLoginSupported] = React.useState(false);
|
||||
const [launchAtLoginEnabled, setLaunchAtLoginEnabled] = React.useState(false);
|
||||
const [isSavingLaunchAtLogin, setIsSavingLaunchAtLogin] = React.useState(false);
|
||||
const [error, setError] = React.useState<string | null>(null);
|
||||
const [lanAddress, setLanAddress] = React.useState<string | null>(null);
|
||||
|
||||
@@ -66,6 +76,27 @@ export const DesktopNetworkSettings: React.FC = () => {
|
||||
};
|
||||
}, [isLocalDesktop, t]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!isLocalDesktop) {
|
||||
setLaunchAtLoginSupported(false);
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
const status = await getDesktopLaunchAtLogin();
|
||||
if (cancelled) {
|
||||
return;
|
||||
}
|
||||
setLaunchAtLoginSupported(status?.supported === true);
|
||||
setLaunchAtLoginEnabled(status?.enabled === true);
|
||||
})();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [isLocalDesktop]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!isLocalDesktop || !draftValue) {
|
||||
setLanAddress(null);
|
||||
@@ -101,6 +132,30 @@ export const DesktopNetworkSettings: React.FC = () => {
|
||||
setDraftValue((current) => !current);
|
||||
}, []);
|
||||
|
||||
const handleLaunchAtLoginToggle = React.useCallback(async () => {
|
||||
if (!launchAtLoginSupported || isSavingLaunchAtLogin) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextValue = !launchAtLoginEnabled;
|
||||
setLaunchAtLoginEnabled(nextValue);
|
||||
setIsSavingLaunchAtLogin(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const status = await setDesktopLaunchAtLogin(nextValue);
|
||||
if (!status?.supported) {
|
||||
throw new Error(t('settings.openchamber.desktopNetwork.error.launchAtLoginUnsupported'));
|
||||
}
|
||||
setLaunchAtLoginEnabled(status.enabled);
|
||||
} catch (cause) {
|
||||
setLaunchAtLoginEnabled(!nextValue);
|
||||
setError(cause instanceof Error ? cause.message : t('settings.openchamber.desktopNetwork.error.launchAtLoginSaveFailed'));
|
||||
} finally {
|
||||
setIsSavingLaunchAtLogin(false);
|
||||
}
|
||||
}, [isSavingLaunchAtLogin, launchAtLoginEnabled, launchAtLoginSupported, t]);
|
||||
|
||||
const handleSaveAndRestart = React.useCallback(async () => {
|
||||
if (!isDirty) {
|
||||
return;
|
||||
@@ -150,6 +205,34 @@ export const DesktopNetworkSettings: React.FC = () => {
|
||||
</div>
|
||||
|
||||
<section className="space-y-2 px-2 pb-2 pt-0">
|
||||
{launchAtLoginSupported ? (
|
||||
<div
|
||||
className="group flex cursor-pointer items-start gap-2 py-1.5"
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={handleLaunchAtLoginToggle}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Enter' || event.key === ' ') {
|
||||
event.preventDefault();
|
||||
handleLaunchAtLoginToggle();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Checkbox
|
||||
checked={launchAtLoginEnabled}
|
||||
onChange={handleLaunchAtLoginToggle}
|
||||
ariaLabel={t('settings.openchamber.desktopNetwork.field.launchAtLoginAria')}
|
||||
disabled={isSavingLaunchAtLogin}
|
||||
/>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="typography-ui-label text-foreground">{t('settings.openchamber.desktopNetwork.field.launchAtLogin')}</div>
|
||||
<div className="typography-micro text-muted-foreground/70">
|
||||
{t('settings.openchamber.desktopNetwork.field.launchAtLoginDescription')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="space-y-1 py-1.5">
|
||||
<label className="typography-ui-label text-foreground" htmlFor="desktop-ui-password">
|
||||
{t('settings.openchamber.desktopPassword.field.password')}
|
||||
|
||||
@@ -40,16 +40,16 @@ export const OpenChamberPage: React.FC<OpenChamberPageProps> = ({ section }) =>
|
||||
<div className="border-t border-border/40 pt-6">
|
||||
<DefaultsSettings />
|
||||
</div>
|
||||
{!isVSCode && (
|
||||
<div className="border-t border-border/40 pt-6">
|
||||
<OpenCodeCliSettings />
|
||||
</div>
|
||||
)}
|
||||
{showDesktopNetworkSettings && (
|
||||
<div className="border-t border-border/40 pt-6">
|
||||
<DesktopNetworkSettings />
|
||||
</div>
|
||||
)}
|
||||
{!isVSCode && (
|
||||
<div className="border-t border-border/40 pt-6">
|
||||
<OpenCodeCliSettings />
|
||||
</div>
|
||||
)}
|
||||
<div className="border-t border-border/40 pt-6">
|
||||
<SessionRetentionSettings />
|
||||
</div>
|
||||
@@ -139,16 +139,16 @@ const SessionsSectionContent: React.FC = () => {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<DefaultsSettings />
|
||||
{!isVSCode && (
|
||||
<div className="border-t border-border/40 pt-6">
|
||||
<OpenCodeCliSettings />
|
||||
</div>
|
||||
)}
|
||||
{showDesktopNetworkSettings && (
|
||||
<div className="border-t border-border/40 pt-6">
|
||||
<DesktopNetworkSettings />
|
||||
</div>
|
||||
)}
|
||||
{!isVSCode && (
|
||||
<div className="border-t border-border/40 pt-6">
|
||||
<OpenCodeCliSettings />
|
||||
</div>
|
||||
)}
|
||||
<div className="border-t border-border/40 pt-6">
|
||||
<SessionRetentionSettings />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user