openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
60 lines (59 loc) • 2.55 kB
JavaScript
import { n as runCommandWithTimeout } from "./exec-runner-Br73vG-X.mjs";
import { t as note } from "./note-CnLgHvug.mjs";
import { r as inspectHostDesktop } from "./host-source-CLfafWHt.mjs";
//#region src/commands/doctor-host-desktop.ts
const SCREEN_SHARING_PORT = 5900;
const SCREEN_SHARING_COMMAND = "sudo launchctl enable system/com.apple.screensharing && sudo launchctl kickstart -k system/com.apple.screensharing";
const SCREEN_SHARING_SETTINGS = "System Settings → General → Sharing → Screen Sharing";
/** Collects the non-mutating host desktop diagnostic shared by doctor modes. */
async function collectHostDesktopHealthFindings(e) {
const { status: t, detail: n } = await inspectHostDesktop({ config: e.desktop?.host });
return [{
checkId: "core/doctor/host-desktop",
severity: t.state === "unavailable" || t.state === "managed" && t.managedState === "failed" ? "warning" : "info",
message: n,
path: "desktop.host"
}];
}
/** Renders host desktop health and offers an explicitly confirmed macOS service repair. */
async function noteHostDesktopHealth(e, t = {}) {
const n = process.platform;
const r = await inspectHostDesktop({
config: e.desktop?.host,
platform: n
});
note(r.detail, "Host desktop");
if (n !== "darwin" || e.desktop?.host?.enabled !== true || r.status.port !== SCREEN_SHARING_PORT || r.unavailableReason !== "not-listening") return;
note(`Repair command: ${SCREEN_SHARING_COMMAND}\nManual path: ${SCREEN_SHARING_SETTINGS}`, "Host desktop repair");
if (!t.prompter?.shouldRepair) return;
if (!await t.prompter.confirmRuntimeRepair({
message: "Enable macOS Screen Sharing now using sudo launchctl? This system service may accept connections from other network interfaces according to macOS Sharing settings.",
initialValue: false,
requiresInteractiveConfirmation: true
})) {
note(`Enable Screen Sharing manually in ${SCREEN_SHARING_SETTINGS}.`, "Host desktop repair");
return;
}
for (const e of [[
"sudo",
"launchctl",
"enable",
"system/com.apple.screensharing"
], [
"sudo",
"launchctl",
"kickstart",
"-k",
"system/com.apple.screensharing"
]]) if ((await runCommandWithTimeout(e, { timeoutMs: 12e4 })).code !== 0) {
note(`Screen Sharing repair failed. Run ${SCREEN_SHARING_COMMAND}, or enable it in ${SCREEN_SHARING_SETTINGS}.`, "Host desktop repair");
return;
}
const i = await inspectHostDesktop({
config: e.desktop.host,
platform: n
});
note(i.detail, "Host desktop");
}
//#endregion
export { collectHostDesktopHealthFindings, noteHostDesktopHealth };