mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
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>
23 lines
1.2 KiB
TypeScript
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");
|