refactor: register gateway service adapters

This commit is contained in:
Peter Steinberger
2026-03-08 02:57:32 +00:00
parent 380eb1c072
commit bd413263b2
2 changed files with 82 additions and 44 deletions

View File

@@ -64,51 +64,49 @@ export type GatewayService = {
readRuntime: (env: GatewayServiceEnv) => Promise<GatewayServiceRuntime>;
};
const GATEWAY_SERVICE_REGISTRY = {
darwin: {
label: "LaunchAgent",
loadedText: "loaded",
notLoadedText: "not loaded",
install: ignoreInstallResult(installLaunchAgent),
uninstall: uninstallLaunchAgent,
stop: stopLaunchAgent,
restart: restartLaunchAgent,
isLoaded: isLaunchAgentLoaded,
readCommand: readLaunchAgentProgramArguments,
readRuntime: readLaunchAgentRuntime,
},
linux: {
label: "systemd",
loadedText: "enabled",
notLoadedText: "disabled",
install: ignoreInstallResult(installSystemdService),
uninstall: uninstallSystemdService,
stop: stopSystemdService,
restart: restartSystemdService,
isLoaded: isSystemdServiceEnabled,
readCommand: readSystemdServiceExecStart,
readRuntime: readSystemdServiceRuntime,
},
win32: {
label: "Scheduled Task",
loadedText: "registered",
notLoadedText: "missing",
install: ignoreInstallResult(installScheduledTask),
uninstall: uninstallScheduledTask,
stop: stopScheduledTask,
restart: restartScheduledTask,
isLoaded: isScheduledTaskInstalled,
readCommand: readScheduledTaskCommand,
readRuntime: readScheduledTaskRuntime,
},
} satisfies Partial<Record<NodeJS.Platform, GatewayService>>;
export function resolveGatewayService(): GatewayService {
if (process.platform === "darwin") {
return {
label: "LaunchAgent",
loadedText: "loaded",
notLoadedText: "not loaded",
install: ignoreInstallResult(installLaunchAgent),
uninstall: uninstallLaunchAgent,
stop: stopLaunchAgent,
restart: restartLaunchAgent,
isLoaded: isLaunchAgentLoaded,
readCommand: readLaunchAgentProgramArguments,
readRuntime: readLaunchAgentRuntime,
};
const service = GATEWAY_SERVICE_REGISTRY[process.platform];
if (service) {
return service;
}
if (process.platform === "linux") {
return {
label: "systemd",
loadedText: "enabled",
notLoadedText: "disabled",
install: ignoreInstallResult(installSystemdService),
uninstall: uninstallSystemdService,
stop: stopSystemdService,
restart: restartSystemdService,
isLoaded: isSystemdServiceEnabled,
readCommand: readSystemdServiceExecStart,
readRuntime: readSystemdServiceRuntime,
};
}
if (process.platform === "win32") {
return {
label: "Scheduled Task",
loadedText: "registered",
notLoadedText: "missing",
install: ignoreInstallResult(installScheduledTask),
uninstall: uninstallScheduledTask,
stop: stopScheduledTask,
restart: restartScheduledTask,
isLoaded: isScheduledTaskInstalled,
readCommand: readScheduledTaskCommand,
readRuntime: readScheduledTaskRuntime,
};
}
throw new Error(`Gateway service install not supported on ${process.platform}`);
}