дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-26 20:46:22 +02:00
Flutter apps started with Run now run through flutter run --machine. Hot Reload and Hot Restart send app.restart requests with the app's id instead of typing r / R into the process. The buttons are enabled once the app reports app.started and supportsRestart. The JSON protocol on stdout is decoded into plain console lines (app.log, progress, daemon messages, failed restarts). Lines outside the protocol show unchanged, and these runs never go through a terminal emulator. Run-mode apps are kept in a workbench store, so the Flutter Inspector, DevTools and Extensions windows connect to them through the wsUri of app.debugPort, the same way they connect to Debug sessions. The Inspector lists Debug and Run apps together. Part of #4096. Co-authored-by: wildcatDownstairs <[email protected]>
125 рядки
4.9 KiB
TypeScript
125 рядки
4.9 KiB
TypeScript
/**
|
|
* The Flutter device selector next to the run configuration. The daemon is stubbed at the IPC
|
|
* layer; `crates/ide-flutter` covers its protocol and process.
|
|
*/
|
|
import type { Page } from "@playwright/test";
|
|
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
|
|
|
|
const device = (id: string, name: string, category: string, unavailable: string | null = null) => ({
|
|
id,
|
|
name,
|
|
platformType: null,
|
|
category,
|
|
emulator: false,
|
|
unavailable,
|
|
});
|
|
const MACOS = device("macos", "macOS", "desktop");
|
|
const CHROME = device("chrome", "Chrome", "web");
|
|
const UNAUTHORIZED = device("R5C", "R5C", "mobile", "unauthorized");
|
|
|
|
async function stubFlutter(page: Page, status: unknown = { kind: "ready" }, emulators: unknown[] = []) {
|
|
await stubDesktop(page);
|
|
await page.evaluate(
|
|
async ({ list }) => {
|
|
const config = {
|
|
id: "flutter:run",
|
|
name: "flutter run",
|
|
kind: "flutter",
|
|
command: "flutter",
|
|
args: ["run", "-t", "lib/main.dart"],
|
|
cwd: null,
|
|
env: {},
|
|
detected: true,
|
|
isTest: false,
|
|
debugAdapter: "dart",
|
|
};
|
|
const h = window.__ipc.handlers;
|
|
h.run_configs = () => [config];
|
|
h.run_apply_settings = (args) => args.configs;
|
|
h.flutter_devices = () => list;
|
|
h.flutter_devices_refresh = () => null;
|
|
h.flutter_emulator_launch = () => null;
|
|
h.run_start = () => ({ id: 3, configId: config.id, name: config.name, pid: 42, running: true, pty: false });
|
|
const runModule = "/src/features/run/store.ts";
|
|
const { loadConfigs, selectConfig } = await import(/* @vite-ignore */ runModule);
|
|
await loadConfigs();
|
|
selectConfig(config.id);
|
|
},
|
|
{ list: { status, devices: [MACOS, CHROME, UNAUTHORIZED], emulators } },
|
|
);
|
|
}
|
|
|
|
const chooser = (page: Page) => page.getByRole("button", { name: /^Flutter device:/ });
|
|
|
|
test("the chosen device is used for Run, and replaced while it is disconnected", async ({ workbench: page }) => {
|
|
await stubFlutter(page);
|
|
await expect(chooser(page)).toContainText("macOS");
|
|
|
|
await chooser(page).click();
|
|
await expect(page.getByRole("menuitemcheckbox", { name: "R5C (unauthorized)" })).toBeDisabled();
|
|
await page.getByRole("menuitemcheckbox", { name: "Chrome" }).click();
|
|
await expect(chooser(page)).toContainText("Chrome");
|
|
|
|
await page.keyboard.press("Control+r");
|
|
await expect.poll(async () => (await ipcCalls(page, "run_start")).length).toBe(1);
|
|
const [started] = await ipcCalls(page, "run_start");
|
|
expect((started!.config as { args: string[] }).args).toEqual([
|
|
"run",
|
|
"-t",
|
|
"lib/main.dart",
|
|
"-d",
|
|
"chrome",
|
|
"--machine",
|
|
]);
|
|
|
|
const emit = (devices: unknown[]) =>
|
|
page.evaluate(
|
|
(devices) => window.__ipc.emit({ type: "flutterDevices", list: { status: { kind: "ready" }, devices } }),
|
|
devices,
|
|
);
|
|
await emit([MACOS]);
|
|
await expect(chooser(page)).toContainText("macOS");
|
|
await emit([MACOS, CHROME]);
|
|
await expect(chooser(page)).toContainText("Chrome");
|
|
});
|
|
|
|
test("says when the Flutter SDK is missing", async ({ workbench: page }) => {
|
|
await stubFlutter(page, { kind: "notInstalled" });
|
|
await expect(chooser(page)).toContainText("Flutter SDK not found");
|
|
});
|
|
|
|
test("starts an emulator and selects its device once it connects", async ({ workbench: page }) => {
|
|
const pixel = { id: "Pixel_9", name: "Pixel 9", platformType: "android" };
|
|
const simulator = { id: "apple_ios_simulator", name: "iOS Simulator", platformType: "ios" };
|
|
await stubFlutter(page, { kind: "ready" }, [pixel, simulator]);
|
|
await chooser(page).click();
|
|
await expect(page.getByRole("menuitem", { name: "Open iOS Simulator" })).toBeVisible();
|
|
await page.getByRole("menuitem", { name: "Open Android Emulator: Pixel 9" }).click();
|
|
await expect.poll(async () => ipcCalls(page, "flutter_emulator_launch")).toEqual([{ id: "Pixel_9" }]);
|
|
await expect(chooser(page)).toContainText("Starting Pixel 9…");
|
|
|
|
const booted = { ...device("emulator-5554", "sdk gphone64 arm64", "mobile"), emulator: true, emulatorId: "Pixel_9" };
|
|
await page.evaluate((list) => window.__ipc.emit({ type: "flutterDevices", list }), {
|
|
status: { kind: "ready" },
|
|
devices: [MACOS, booted],
|
|
emulators: [simulator],
|
|
});
|
|
await expect(chooser(page)).toContainText("sdk gphone64 arm64");
|
|
});
|
|
|
|
test("says why an emulator could not start", async ({ workbench: page }) => {
|
|
await stubFlutter(page, { kind: "ready" }, [
|
|
{ id: "apple_ios_simulator", name: "iOS Simulator", platformType: "ios" },
|
|
]);
|
|
await page.evaluate(() => {
|
|
window.__ipc.handlers.flutter_emulator_launch = () => {
|
|
throw { kind: "unavailable", message: "Unable to find Xcode" };
|
|
};
|
|
});
|
|
await chooser(page).click();
|
|
await page.getByRole("menuitem", { name: "Open iOS Simulator" }).click();
|
|
await expect(page.getByText("Could not start iOS Simulator")).toBeVisible();
|
|
await expect(page.getByText("Unable to find Xcode")).toBeVisible();
|
|
await expect(chooser(page)).toContainText("macOS");
|
|
});
|