|
11 | 11 | import com.google.gson.JsonSyntaxException;
|
12 | 12 | import com.intellij.execution.ExecutionException;
|
13 | 13 | import com.intellij.execution.configurations.GeneralCommandLine;
|
14 |
| -import com.intellij.execution.process.*; |
| 14 | +import com.intellij.execution.process.ProcessAdapter; |
| 15 | +import com.intellij.execution.process.ProcessEvent; |
| 16 | +import com.intellij.execution.process.ProcessHandler; |
| 17 | +import com.intellij.execution.process.ProcessOutput; |
15 | 18 | import com.intellij.openapi.application.ApplicationManager;
|
16 | 19 | import com.intellij.openapi.diagnostic.Logger;
|
17 | 20 | import com.intellij.openapi.project.Project;
|
18 | 21 | import com.intellij.openapi.project.ProjectManager;
|
19 | 22 | import com.intellij.openapi.project.ProjectManagerListener;
|
20 | 23 | import com.intellij.openapi.util.Key;
|
21 |
| -import com.intellij.openapi.util.registry.Registry; |
22 | 24 | import com.intellij.openapi.util.Version;
|
23 | 25 | import com.intellij.openapi.util.io.FileUtil;
|
| 26 | +import com.intellij.openapi.util.registry.Registry; |
24 | 27 | import com.jetbrains.lang.dart.ide.devtools.DartDevToolsService;
|
25 | 28 | import com.jetbrains.lang.dart.ide.toolingDaemon.DartToolingDaemonService;
|
26 | 29 | import com.jetbrains.lang.dart.sdk.DartSdk;
|
@@ -185,12 +188,8 @@ private void startServer() {
|
185 | 188 | ImmutableList.of("devtools", "--machine")));
|
186 | 189 | }
|
187 | 190 | }
|
188 |
| - else if (sdk != null && sdk.getVersion().useDaemonForDevTools()) { |
189 |
| - setUpWithDaemon(); |
190 |
| - } |
191 | 191 | else {
|
192 |
| - // For earlier flutter versions we need to use pub directly to run the latest DevTools server. |
193 |
| - setUpWithPub(); |
| 192 | + setUpWithDaemon(); |
194 | 193 | }
|
195 | 194 | });
|
196 | 195 | }
|
@@ -310,76 +309,6 @@ public void projectClosing(@NotNull Project project) {
|
310 | 309 | });
|
311 | 310 | }
|
312 | 311 |
|
313 |
| - private void setUpWithPub() { |
314 |
| - final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project); |
315 |
| - if (sdk == null) { |
316 |
| - logExceptionAndComplete("Flutter SDK is null"); |
317 |
| - return; |
318 |
| - } |
319 |
| - |
320 |
| - pubActivateDevTools(sdk).thenAccept(success -> { |
321 |
| - if (success) { |
322 |
| - pubRunDevTools(sdk); |
323 |
| - } |
324 |
| - else { |
325 |
| - logExceptionAndComplete("pub activate of DevTools failed"); |
326 |
| - } |
327 |
| - }); |
328 |
| - } |
329 |
| - |
330 |
| - private void pubRunDevTools(FlutterSdk sdk) { |
331 |
| - final FlutterCommand command = sdk.flutterPub(null, "global", "run", "devtools", "--machine", "--port=0"); |
332 |
| - |
333 |
| - final ColoredProcessHandler handler = command.startProcessOrShowError(project); |
334 |
| - if (handler == null) { |
335 |
| - logExceptionAndComplete("Handler was null for pub global run command"); |
336 |
| - return; |
337 |
| - } |
338 |
| - |
339 |
| - handler.addProcessListener(new ProcessAdapter() { |
340 |
| - @Override |
341 |
| - public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) { |
342 |
| - final String text = event.getText().trim(); |
343 |
| - |
344 |
| - if (text.startsWith("{") && text.endsWith("}")) { |
345 |
| - // {"event":"server.started","params":{"host":"127.0.0.1","port":9100}} |
346 |
| - |
347 |
| - try { |
348 |
| - final JsonElement element = JsonUtils.parseString(text); |
349 |
| - |
350 |
| - // params.port |
351 |
| - final JsonObject obj = element.getAsJsonObject(); |
352 |
| - final JsonObject params = obj.getAsJsonObject("params"); |
353 |
| - final String host = JsonUtils.getStringMember(params, "host"); |
354 |
| - final int port = JsonUtils.getIntMember(params, "port"); |
355 |
| - |
356 |
| - if (port != -1) { |
357 |
| - devToolsFutureRef.get().complete(new DevToolsInstance(host, port)); |
358 |
| - } |
359 |
| - else { |
360 |
| - logExceptionAndComplete("DevTools port was invalid"); |
361 |
| - handler.destroyProcess(); |
362 |
| - } |
363 |
| - } |
364 |
| - catch (JsonSyntaxException e) { |
365 |
| - logExceptionAndComplete(e); |
366 |
| - handler.destroyProcess(); |
367 |
| - } |
368 |
| - } |
369 |
| - } |
370 |
| - }); |
371 |
| - |
372 |
| - handler.startNotify(); |
373 |
| - |
374 |
| - ProjectManager.getInstance().addProjectManagerListener(project, new ProjectManagerListener() { |
375 |
| - @Override |
376 |
| - public void projectClosing(@NotNull Project project) { |
377 |
| - devToolsFutureRef.set(null); |
378 |
| - handler.destroyProcess(); |
379 |
| - } |
380 |
| - }); |
381 |
| - } |
382 |
| - |
383 | 312 | private CompletableFuture<Boolean> pubActivateDevTools(FlutterSdk sdk) {
|
384 | 313 | final FlutterCommand command = sdk.flutterPub(null, "global", "activate", "devtools");
|
385 | 314 |
|
|
0 commit comments