mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 09:22:45 +00:00
refactor: register gateway service adapters
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user