use of io.flutter.run.daemon.DevToolsInstance in project flutter-intellij by flutter.
the class LabelInput method addBrowserInspectorViewContent.
private void addBrowserInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow, boolean isEmbedded, DevToolsInstance devToolsInstance) {
assert (SwingUtilities.isEventDispatchThread());
final ContentManager contentManager = toolWindow.getContentManager();
final FlutterDevice device = app.device();
final List<FlutterDevice> existingDevices = new ArrayList<>();
for (FlutterApp otherApp : perAppViewState.keySet()) {
existingDevices.add(otherApp.device());
}
final String tabName = device.getUniqueName(existingDevices);
if (emptyContent != null) {
contentManager.removeContent(emptyContent, true);
emptyContent = null;
}
final String browserUrl = app.getConnector().getBrowserUrl();
if (isEmbedded) {
final String color = ColorUtil.toHex(UIUtil.getEditorPaneBackground());
final DevToolsUrl devToolsUrl = new DevToolsUrl(devToolsInstance.host, devToolsInstance.port, browserUrl, "inspector", true, color, UIUtil.getFontSize(UIUtil.FontSize.NORMAL));
// noinspection CodeBlock2Expr
ApplicationManager.getApplication().invokeLater(() -> {
embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.openPanel(contentManager, tabName, devToolsUrl, () -> {
// If the embedded browser doesn't work, offer a link to open in the regular browser.
final List<LabelInput> inputs = Arrays.asList(new LabelInput("The embedded browser failed to load."), openDevToolsLabel(app, inspectorService, toolWindow));
presentClickableLabel(toolWindow, inputs);
}));
});
if (!busSubscribed) {
busConnection.subscribe(EditorColorsManager.TOPIC, scheme -> embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.updateColor(ColorUtil.toHex(UIUtil.getEditorPaneBackground()))));
busConnection.subscribe(UISettingsListener.TOPIC, scheme -> embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.updateFontSize(UIUtil.getFontSize(UIUtil.FontSize.NORMAL))));
busSubscribed = true;
}
} else {
BrowserLauncher.getInstance().browse((new DevToolsUrl(devToolsInstance.host, devToolsInstance.port, browserUrl, "inspector", false, null, null).getUrlString()), null);
presentLabel(toolWindow, "DevTools inspector has been opened in the browser.");
}
}
use of io.flutter.run.daemon.DevToolsInstance in project flutter-intellij by flutter.
the class BazelFields method getLaunchCommand.
/**
* Returns the command to use to launch the Flutter app. (Via running the Bazel target.)
*/
GeneralCommandLine getLaunchCommand(@NotNull Project project, @Nullable FlutterDevice device, @NotNull RunMode mode) throws ExecutionException {
try {
checkRunnable(project);
} catch (RuntimeConfigurationError e) {
throw new ExecutionException(e);
}
final Workspace workspace = getWorkspace(project);
final String launchingScript = getRunScriptFromWorkspace(project);
// already checked
assert launchingScript != null;
// if the workspace is null, then so is the launching script, therefore this was already checked.
assert workspace != null;
final String target = getTarget();
// already checked
assert target != null;
final String additionalArgs = getAdditionalArgs();
final GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(workspace.getRoot().getPath());
commandLine.setCharset(StandardCharsets.UTF_8);
commandLine.setExePath(FileUtil.toSystemDependentName(launchingScript));
final String inputBazelArgs = StringUtil.notNullize(bazelArgs);
if (!inputBazelArgs.isEmpty()) {
commandLine.addParameter(String.format("--bazel-options=%s", inputBazelArgs));
}
// Potentially add the flag related to build mode.
if (enableReleaseMode) {
commandLine.addParameter("--release");
} else if (mode.equals(PROFILE)) {
commandLine.addParameter("--profile");
}
// Tell the flutter command-line tools that we want a machine interface on stdio.
commandLine.addParameter("--machine");
// Pause the app at startup in order to set breakpoints.
if (!enableReleaseMode && mode == DEBUG) {
commandLine.addParameter("--start-paused");
}
// User specified additional target arguments.
final CommandLineTokenizer additionalArgsTokenizer = new CommandLineTokenizer(StringUtil.notNullize(additionalArgs));
while (additionalArgsTokenizer.hasMoreTokens()) {
commandLine.addParameter(additionalArgsTokenizer.nextToken());
}
final String enableBazelHotRestartParam = "--enable-google3-hot-reload";
final String disableBazelHotRestartParam = "--no-enable-google3-hot-reload";
final boolean hasEnabledArg = StringUtil.notNullize(additionalArgs).contains(enableBazelHotRestartParam);
final boolean hasDisabledArg = StringUtil.notNullize(additionalArgs).contains(disableBazelHotRestartParam);
if (!FlutterSettings.getInstance().isEnableBazelHotRestart() && hasDisabledArg) {
final Notification notification = new Notification(FlutterMessages.FLUTTER_NOTIFICATION_GROUP_ID, "Google3-specific hot restart is disabled by default", "You can now remove this flag from your configuration's additional args: " + disableBazelHotRestartParam, NotificationType.INFORMATION);
Notifications.Bus.notify(notification, project);
} else if (FlutterSettings.getInstance().isEnableBazelHotRestart() && !hasEnabledArg && !hasDisabledArg) {
commandLine.addParameter(enableBazelHotRestartParam);
}
// Send in the deviceId.
if (device != null) {
commandLine.addParameter("-d");
commandLine.addParameter(device.deviceId());
}
try {
final ProgressManager progress = ProgressManager.getInstance();
final CompletableFuture<DevToolsInstance> devToolsFuture = new CompletableFuture<>();
progress.runProcessWithProgressSynchronously(() -> {
progress.getProgressIndicator().setIndeterminate(true);
try {
final DevToolsService service = this.devToolsService == null ? DevToolsService.getInstance(project) : this.devToolsService;
devToolsFuture.complete(service.getDevToolsInstance().get(30, TimeUnit.SECONDS));
} catch (Exception e) {
LOG.error(e);
}
}, "Starting DevTools", false, project);
final DevToolsInstance instance = devToolsFuture.get();
commandLine.addParameter("--devtools-server-address=http://" + instance.host + ":" + instance.port);
} catch (Exception e) {
LOG.error(e);
}
commandLine.addParameter(target);
return commandLine;
}
use of io.flutter.run.daemon.DevToolsInstance in project flutter-intellij by flutter.
the class SdkFields method createFlutterSdkRunCommand.
/**
* Create a command to run 'flutter run --machine'.
*/
public GeneralCommandLine createFlutterSdkRunCommand(@NotNull Project project, @NotNull RunMode runMode, @NotNull FlutterLaunchMode flutterLaunchMode, @NotNull FlutterDevice device, boolean firstRun) throws ExecutionException {
final MainFile main = MainFile.verify(filePath, project).get();
final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
if (flutterSdk == null) {
throw new ExecutionException(FlutterBundle.message("flutter.sdk.is.not.configured"));
}
final PubRoot root = PubRoot.forDirectory(main.getAppDir());
if (root == null) {
throw new ExecutionException("Entrypoint isn't within a Flutter pub root");
}
final FlutterCommand command;
String[] args = getAdditionalArgsParsed();
if (buildFlavor != null) {
args = ArrayUtil.append(args, "--flavor=" + buildFlavor);
}
if (FlutterSettings.getInstance().isShowStructuredErrors() && flutterSdk.getVersion().isDartDefineSupported()) {
args = ArrayUtil.append(args, "--dart-define=flutter.inspector.structuredErrors=true");
}
if (flutterSdk.getVersion().flutterRunSupportsDevToolsUrl()) {
try {
final ProgressManager progress = ProgressManager.getInstance();
final CompletableFuture<DevToolsInstance> devToolsFuture = new CompletableFuture<>();
progress.runProcessWithProgressSynchronously(() -> {
progress.getProgressIndicator().setIndeterminate(true);
try {
final CompletableFuture<DevToolsInstance> futureInstance = DevToolsService.getInstance(project).getDevToolsInstance();
if (firstRun) {
devToolsFuture.complete(futureInstance.get(30, TimeUnit.SECONDS));
} else {
// Skip waiting if this isn't the first time running this project. If DevTools isn't available by now, there's likely to be
// something wrong that won't be fixed by restarting, so we don't want to keep delaying run.
final DevToolsInstance instance = futureInstance.getNow(null);
if (instance == null) {
devToolsFuture.completeExceptionally(new Exception("DevTools instance not available after first run."));
} else {
devToolsFuture.complete(instance);
}
}
} catch (Exception e) {
devToolsFuture.completeExceptionally(e);
}
}, "Starting DevTools", false, project);
final DevToolsInstance instance = devToolsFuture.get();
args = ArrayUtil.append(args, "--devtools-server-address=http://" + instance.host + ":" + instance.port);
if (firstRun) {
FlutterInitializer.getAnalytics().sendEvent("devtools", "first-run-success");
}
} catch (Exception e) {
LOG.info(e);
FlutterInitializer.getAnalytics().sendExpectedException("devtools", e);
}
}
command = flutterSdk.flutterRun(root, main.getFile(), device, runMode, flutterLaunchMode, project, args);
final GeneralCommandLine commandLine = command.createGeneralCommandLine(project);
commandLine.getEnvironment().putAll(getEnvs());
commandLine.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE);
return commandLine;
}
use of io.flutter.run.daemon.DevToolsInstance in project flutter-intellij by flutter.
the class BazelFieldsTest method setUp.
@Before
public void setUp() {
final CompletableFuture<DevToolsInstance> future = new CompletableFuture<>();
future.complete(new DevToolsInstance("http://localhost", 1234));
}
use of io.flutter.run.daemon.DevToolsInstance in project flutter-intellij by flutter.
the class LaunchCommandsTest method setUp.
@Before
public void setUp() {
final CompletableFuture<DevToolsInstance> future = new CompletableFuture<>();
future.complete(new DevToolsInstance("http://localhost", 1234));
mockService = mock(DevToolsService.class);
when(mockService.getDevToolsInstance()).thenReturn(future);
}
Aggregations