Files
openidea/src/features/run/flutterHotReload.ts
T
LU XIANGRUIandwildcatDownstairs a4de18796b feat(run): add Flutter Hot Reload and Hot Restart buttons to the Run tool window (#4415)
Flutter apps started with Run had no hot reload control. Hot Reload and Hot Restart now follow Stop in the Run tool window for flutter run configurations in a hot-reload mode, sending r / R to flutter run's stdin (plain console and terminal emulation); disabled once the process ends. Refs #4096

Co-authored-by: wildcatDownstairs <26499420+wildcatDownstairs@users.noreply.github.com>
2026-11-19 17:23:12 +08:00

23 lines
1.2 KiB
TypeScript

/** Hot reload from the Run tool window: `flutter run` takes `r` and `R` as commands on stdin. */
import type { RunConfig } from "@/platform/ipc";
import { acceptsInput, useRun, writeTerminal, type RunSession } from "./store";
/** Options that turn off `flutter run`'s hot mode, or (`--machine`) replace its key commands with JSON. */
const NO_HOT_KEYS = new Set(["--release", "--profile", "--jit-release", "--no-hot", "--trace-startup", "--machine"]);
export function supportsHotReload(config: RunConfig): boolean {
return config.kind === "flutter" && config.args[0] === "run" && !config.args.some((arg) => NO_HOT_KEYS.has(arg));
}
const canHotReload = (session: RunSession) => supportsHotReload(session.config) && acceptsInput(session);
/** The active session when it can reload, else the newest one that can. */
export function hotReloadSession(): RunSession | undefined {
const { sessions, activeSession } = useRun.getState();
const active = sessions.find((s) => s.id === activeSession);
return active && canHotReload(active) ? active : [...sessions].reverse().find(canHotReload);
}
export const hotReload = (sessionId: string) => writeTerminal(sessionId, "r");
export const hotRestart = (sessionId: string) => writeTerminal(sessionId, "R");