Files
openidea/src/features/debugger/attachPopup.ts
T
itcodesandsliencio aa8822d9a3 feat(debugger): attach to a running Unity Editor (#2919)
Unity projects get a debug-only "Unity Editor" run configuration, selected by default. Debug opens a picker of local Unity Editor processes with the current project first; Run > Attach to Unity Process is also available. The tool installer fetches the pinned Unity Debugger 3.0.1 adapter with SHA-256 verification, and the session reports ready once the Mono runtime is up. A missing Mono executable on macOS and Linux is reported in the picker.

Refs #1436

Co-authored-by: sliencio <20137430+sliencio@users.noreply.github.com>
2026-11-16 10:16:50 +08:00

45 lines
1.9 KiB
TypeScript

import { executeAction } from "@/platform/actions";
import { call, commands, isTauri, type RunConfig } from "@/platform/ipc";
import { useProject } from "@/platform/project";
import { notifications } from "@/workbench/contributions";
import { missingAdapter } from "./missingAdapter";
import { useOverlays } from "./ui/popoverStore";
/** Applies only the latest request of the open popup; results for a closed or refreshed one are dropped. */
export async function openAttachPopup(mode: "all" | "unity" = "all", runConfig?: RunConfig) {
if (!isTauri()) {
notifications().notify({ group: "run", level: "warning", title: "Attaching needs the desktop app" });
return;
}
const projectRoot = useProject.getState().project?.root ?? null;
const pending = { processes: null, error: null, mode, projectRoot, runConfig };
useOverlays.setState({ attach: pending });
const current = () =>
useOverlays.getState().attach === pending && (useProject.getState().project?.root ?? null) === projectRoot;
try {
const processes = await call(
mode === "unity" ? commands.debugUnityProcesses() : commands.debugAttachableProcesses(),
);
if (current()) useOverlays.setState({ attach: { ...pending, processes } });
} catch (e) {
if (current())
useOverlays.setState({
attach: {
...pending,
processes: [],
error: e instanceof Error ? e.message : String(e),
installTool: mode === "unity" ? missingAdapter("unity", e)?.tool : undefined,
},
});
}
}
export async function installAttachAdapter() {
const state = useOverlays.getState().attach;
if (!state?.installTool) return;
await executeAction("tools.install", state.installTool);
if (useOverlays.getState().attach === state && useProject.getState().project?.root === state.projectRoot) {
await openAttachPopup(state.mode, state.runConfig);
}
}