diff --git a/src/io/flutter/run/LaunchState.java b/src/io/flutter/run/LaunchState.java index e82a8955b2..60c531947c 100644 --- a/src/io/flutter/run/LaunchState.java +++ b/src/io/flutter/run/LaunchState.java @@ -45,7 +45,6 @@ import io.flutter.dart.DartPlugin; import io.flutter.logging.FlutterLog; import io.flutter.logging.FlutterLogView; -import io.flutter.pub.PubRoot; import io.flutter.run.bazel.BazelRunConfig; import io.flutter.run.daemon.*; import org.jetbrains.annotations.NotNull; @@ -121,21 +120,9 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws final Project project = getEnvironment().getProject(); final FlutterDevice device = DeviceService.getInstance(project).getSelectedDevice(); - // If the device is null and the project is not a flutter web project, show a message that a device is required and return null. if (device == null) { - boolean isFlutterWeb = false; - final String filePath = ((SdkRunConfig)runConfig).getFields().getFilePath(); - if(filePath != null) { - final MainFile main = MainFile.verify(filePath, project).get(); - final PubRoot root = PubRoot.forDirectory(main.getAppDir()); - if (root != null) { - isFlutterWeb = FlutterUtils.declaresFlutterWeb(root.getPubspec()); - } - } - if (!isFlutterWeb) { - showNoDeviceConnectedMessage(project); - return null; - } + showNoDeviceConnectedMessage(project); + return null; } final FlutterApp app = myCreateAppCallback.createApp(device); @@ -160,9 +147,7 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws } } - if (device != null) { - device.bringToFront(); - } + device.bringToFront(); // Check for and display any analysis errors when we launch an app. if (env.getRunProfile() instanceof SdkRunConfig) { diff --git a/src/io/flutter/run/SdkFields.java b/src/io/flutter/run/SdkFields.java index 3c39cad0d7..642768d56d 100644 --- a/src/io/flutter/run/SdkFields.java +++ b/src/io/flutter/run/SdkFields.java @@ -14,7 +14,6 @@ import com.jetbrains.lang.dart.sdk.DartConfigurable; import com.jetbrains.lang.dart.sdk.DartSdk; import io.flutter.FlutterBundle; -import io.flutter.FlutterUtils; import io.flutter.dart.DartPlugin; import io.flutter.pub.PubRoot; import io.flutter.run.daemon.FlutterDevice; @@ -125,14 +124,11 @@ public GeneralCommandLine createFlutterSdkRunCommand(@NotNull Project project, throw new ExecutionException("Entrypoint isn't within a Flutter pub root"); } - String[] args = additionalArgs == null ? new String[]{ } : additionalArgs.split(" "); + String[] args = additionalArgs == null ? new String[]{} : additionalArgs.split(" "); if (buildFlavor != null) { args = ArrayUtil.append(args, "--flavor=" + buildFlavor); } - - final FlutterCommand command = FlutterUtils.declaresFlutterWeb(root.getPubspec()) ? - flutterSdk.flutterRunWeb(root, runMode) : - flutterSdk.flutterRun(root, main.getFile(), device, runMode, flutterLaunchMode, project, args); + final FlutterCommand command = flutterSdk.flutterRun(root, main.getFile(), device, runMode, flutterLaunchMode, project, args); return command.createGeneralCommandLine(project); } @@ -154,7 +150,7 @@ public GeneralCommandLine createFlutterSdkAttachCommand(@NotNull Project project throw new ExecutionException("Entrypoint isn't within a Flutter pub root"); } - String[] args = additionalArgs == null ? new String[]{ } : additionalArgs.split(" "); + String[] args = additionalArgs == null ? new String[]{} : additionalArgs.split(" "); if (buildFlavor != null) { args = ArrayUtil.append(args, "--flavor=" + buildFlavor); } diff --git a/src/io/flutter/run/SdkRunConfig.java b/src/io/flutter/run/SdkRunConfig.java index 5f4c32b4e1..0559092841 100644 --- a/src/io/flutter/run/SdkRunConfig.java +++ b/src/io/flutter/run/SdkRunConfig.java @@ -142,8 +142,7 @@ public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnviro final RunMode mode = RunMode.fromEnv(env); final Module module = ModuleUtilCore.findModuleForFile(mainFile.getFile(), env.getProject()); final LaunchState.CreateAppCallback createAppCallback = (device) -> { - // Up until the FlutterWeb support, device was checked for null and returned. The device - // can only be null if this is a FlutterWeb execution, this expecation is checked elsewhere. + if (device == null) return null; final GeneralCommandLine command = getCommand(env, device); { diff --git a/src/io/flutter/run/daemon/FlutterApp.java b/src/io/flutter/run/daemon/FlutterApp.java index e4abf22d3e..ebddee8186 100644 --- a/src/io/flutter/run/daemon/FlutterApp.java +++ b/src/io/flutter/run/daemon/FlutterApp.java @@ -68,8 +68,7 @@ public class FlutterApp { private final @NotNull Project myProject; private final @Nullable Module myModule; private final @NotNull RunMode myMode; - // TODO(github.com/flutter/flutter-intellij/issues/3293) myDevice is not-null for all run configurations except flutter web configurations - private final @Nullable FlutterDevice myDevice; + private final @NotNull FlutterDevice myDevice; private final @NotNull ProcessHandler myProcessHandler; private final @NotNull ExecutionEnvironment myExecutionEnvironment; private final @NotNull DaemonApi myDaemonApi; @@ -123,7 +122,7 @@ public static FlutterApp fromEnv(@NotNull ExecutionEnvironment env) { FlutterApp(@NotNull Project project, @Nullable Module module, @NotNull RunMode mode, - @Nullable FlutterDevice device, + @NotNull FlutterDevice device, @NotNull ProcessHandler processHandler, @NotNull ExecutionEnvironment executionEnvironment, @NotNull DaemonApi daemonApi, @@ -238,7 +237,7 @@ public static FlutterApp start(@NotNull ExecutionEnvironment env, @NotNull Project project, @Nullable Module module, @NotNull RunMode mode, - @Nullable FlutterDevice device, + @NotNull FlutterDevice device, @NotNull GeneralCommandLine command, @Nullable String analyticsStart, @Nullable String analyticsStop) @@ -594,12 +593,7 @@ public FlutterDevice device() { } public String deviceId() { - return myDevice != null ? myDevice.deviceId() : ""; - } - - // TODO this should be a temporary hack until there is some mocked out "browser" device - public boolean isWebDev() { - return myDevice == null; + return myDevice.deviceId(); } public void setFlutterDebugProcess(FlutterDebugProcess flutterDebugProcess) { diff --git a/src/io/flutter/sdk/FlutterCommand.java b/src/io/flutter/sdk/FlutterCommand.java index 43f48c4024..4953a536c4 100644 --- a/src/io/flutter/sdk/FlutterCommand.java +++ b/src/io/flutter/sdk/FlutterCommand.java @@ -48,28 +48,13 @@ public class FlutterCommand { @NotNull private final List args; - // TODO(github.com/flutter/flutter-intellij/issues/3293) This is a temporary "/bin/webdev" that can be provided to test some - // webdev directly. - @Nullable - private final String localWebDevExe = "webdev"; - - private final boolean isFlutterWeb; - /** * @see FlutterSdk for methods to create specific commands. */ FlutterCommand(@NotNull FlutterSdk sdk, @Nullable VirtualFile workDir, @NotNull Type type, String... args) { - this(sdk, workDir, type, false, args); - } - - /** - * @see FlutterSdk for methods to create specific commands. - */ - FlutterCommand(@NotNull FlutterSdk sdk, @Nullable VirtualFile workDir, @NotNull Type type, boolean isFlutterWeb, String... args) { this.sdk = sdk; this.workDir = workDir; this.type = type; - this.isFlutterWeb = isFlutterWeb; this.args = ImmutableList.copyOf(args); } @@ -260,59 +245,23 @@ public OSProcessHandler startProcessOrShowError(@Nullable Project project) { public GeneralCommandLine createGeneralCommandLine(@Nullable Project project) { final GeneralCommandLine line = new GeneralCommandLine(); line.setCharset(CharsetToolkit.UTF8_CHARSET); - if (isFlutterWeb) { - if (workDir != null) { - line.setWorkDirectory(workDir.getPath()); - } - if(localWebDevExe != null || !localWebDevExe.isEmpty()) { - line.setExePath(localWebDevExe); - line.addParameters("daemon"); - if(args.contains("--debug")) { - line.addParameters("--debug"); - } - if(args.contains("--hot-reload")) { - line.addParameters("--hot-reload"); - } - } else { - line.setExePath(FileUtil.toSystemDependentName(sdk.getHomePath() + "/bin/" + FlutterSdkUtil.flutterScriptName())); - line.addParameters(args); - } - } - else { - line.withEnvironment(FlutterSdkUtil.FLUTTER_HOST_ENV, FlutterSdkUtil.getFlutterHostEnvValue()); - final String androidHome = IntelliJAndroidSdk.chooseAndroidHome(project, false); - if (androidHome != null) { - line.withEnvironment("ANDROID_HOME", androidHome); - } + line.withEnvironment(FlutterSdkUtil.FLUTTER_HOST_ENV, FlutterSdkUtil.getFlutterHostEnvValue()); - line.setExePath(FileUtil.toSystemDependentName(sdk.getHomePath() + "/bin/" + FlutterSdkUtil.flutterScriptName())); - if (workDir != null) { - line.setWorkDirectory(workDir.getPath()); - } - if (!isDoctorCommand()) { - line.addParameter("--no-color"); - } - line.addParameters(type.subCommand); - line.addParameters(args); + final String androidHome = IntelliJAndroidSdk.chooseAndroidHome(project, false); + if (androidHome != null) { + line.withEnvironment("ANDROID_HOME", androidHome); } - return line; - } - - /** - * Creates a FlutterWeb command line to run. - */ - @NotNull - public GeneralCommandLine createFlutterWebCommandLine(@Nullable Project project) { - final GeneralCommandLine line = new GeneralCommandLine(); - line.setCharset(CharsetToolkit.UTF8_CHARSET); + line.setExePath(FileUtil.toSystemDependentName(sdk.getHomePath() + "/bin/" + FlutterSdkUtil.flutterScriptName())); if (workDir != null) { line.setWorkDirectory(workDir.getPath()); } + if (!isDoctorCommand()) { + line.addParameter("--no-color"); + } line.addParameters(type.subCommand); line.addParameters(args); - return line; } diff --git a/src/io/flutter/sdk/FlutterSdk.java b/src/io/flutter/sdk/FlutterSdk.java index 270506af8d..8a4bc7893b 100644 --- a/src/io/flutter/sdk/FlutterSdk.java +++ b/src/io/flutter/sdk/FlutterSdk.java @@ -269,18 +269,6 @@ else if (flutterLaunchMode == FlutterLaunchMode.RELEASE) { return new FlutterCommand(this, root.getRoot(), FlutterCommand.Type.ATTACH, args.toArray(new String[]{ })); } - public FlutterCommand flutterRunWeb(@NotNull PubRoot root, @NotNull RunMode mode) { - // flutter packages pub global run webdev serve [--debug] [--hot-reload] - final List args = new ArrayList<>(); - args.add("global"); - args.add("run"); - args.add("webdev"); - args.add("daemon"); - // TODO After debug is supported by webdev, this should be modified to check for debug and add any additional needed flags: - // i.e. if (mode == RunMode.DEBUG) { args.add("--debug"); } - return new FlutterCommand(this, root.getRoot(), FlutterCommand.Type.PACKAGES_PUB, true, args.toArray(new String[]{ })); - } - public FlutterCommand flutterRunOnTester(@NotNull PubRoot root, @NotNull String mainPath) { final List args = new ArrayList<>(); args.add("--machine"); diff --git a/src/io/flutter/server/vmService/DartVmServiceDebugProcess.java b/src/io/flutter/server/vmService/DartVmServiceDebugProcess.java index 117cc1baaf..2c25e7bdd4 100644 --- a/src/io/flutter/server/vmService/DartVmServiceDebugProcess.java +++ b/src/io/flutter/server/vmService/DartVmServiceDebugProcess.java @@ -41,7 +41,6 @@ import io.flutter.FlutterBundle; import io.flutter.FlutterUtils; import io.flutter.run.FlutterLaunchMode; -import io.flutter.run.daemon.FlutterApp; import io.flutter.server.vmService.frame.DartVmServiceEvaluator; import io.flutter.server.vmService.frame.DartVmServiceStackFrame; import io.flutter.server.vmService.frame.DartVmServiceSuspendContext; @@ -263,22 +262,17 @@ public void scheduleConnect() { // because "flutter run" has already connected to it. final VmService vmService; final VmOpenSourceLocationListener vmOpenSourceLocationListener; - // TODO(github.com/flutter/flutter-intellij/issues/3293, github.com/dart-lang/webdev/issues/233) The following check disables the - // WebSocket connection for all FlutterWeb run configurations, for some reason the WebSocket port can't be connected to, see listed - // issue above. - if (myConnector instanceof FlutterApp && (!((FlutterApp)myConnector).isWebDev())) { - try { - vmService = VmService.connect(url); - vmOpenSourceLocationListener = VmOpenSourceLocationListener.connect(url); - } - catch (IOException | RuntimeException e) { - onConnectFailed("Failed to connect to the VM observatory service at: " + url + "\n" - + e.toString() + "\n" + - formatStackTraces(e)); - return; - } - onConnectSucceeded(vmService, vmOpenSourceLocationListener); + try { + vmService = VmService.connect(url); + vmOpenSourceLocationListener = VmOpenSourceLocationListener.connect(url); + } + catch (IOException | RuntimeException e) { + onConnectFailed("Failed to connect to the VM observatory service at: " + url + "\n" + + e.toString() + "\n" + + formatStackTraces(e)); + return; } + onConnectSucceeded(vmService, vmOpenSourceLocationListener); }); } @@ -397,7 +391,7 @@ public void runToPosition(@NotNull XSourcePosition position, @Nullable XSuspendC public void isolateSuspended(@NotNull final IsolateRef isolateRef) { final String id = isolateRef.getId(); - assert (!mySuspendedIsolateIds.containsKey(id)); + assert(!mySuspendedIsolateIds.containsKey(id)); if (!mySuspendedIsolateIds.containsKey(id)) { mySuspendedIsolateIds.put(id, new CompletableFuture<>()); } @@ -412,10 +406,10 @@ public CompletableFuture whenIsolateResumed(String isolateId) { if (future == null) { // Isolate wasn't actually suspended. return CompletableFuture.completedFuture(null); - } - else { + } else { return future; } + } public boolean isIsolateAlive(@NotNull final String isolateId) {