-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add embedded view for other DevTools tabs (#7496)
No app running: <img width="498" alt="Screenshot 2024-06-07 at 2 22 32 PM" src="https://github.com/flutter/flutter-intellij/assets/6379305/240f0fab-76b9-4c1f-a955-fa47c8fdf960"> App running: <img width="522" alt="Screenshot 2024-06-07 at 2 23 24 PM" src="https://github.com/flutter/flutter-intellij/assets/6379305/55c8663e-92c3-471c-9c9b-638ee3faf022"> Review after #7417 is merged Partially addresses #7195
- Loading branch information
Showing
7 changed files
with
174 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
flutter-idea/src/io/flutter/devtools/RemainingDevToolsViewFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2024 The Chromium Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package io.flutter.devtools; | ||
|
||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.wm.ToolWindow; | ||
import com.intellij.openapi.wm.ToolWindowFactory; | ||
import com.intellij.ui.content.ContentManager; | ||
import io.flutter.FlutterUtils; | ||
import io.flutter.bazel.WorkspaceCache; | ||
import io.flutter.run.daemon.DevToolsService; | ||
import io.flutter.sdk.FlutterSdk; | ||
import io.flutter.sdk.FlutterSdkVersion; | ||
import io.flutter.utils.AsyncUtils; | ||
import io.flutter.view.FlutterViewMessages; | ||
import kotlin.coroutines.Continuation; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Optional; | ||
|
||
public class RemainingDevToolsViewFactory implements ToolWindowFactory { | ||
public static void init(Project project) { | ||
project.getMessageBus().connect().subscribe( | ||
FlutterViewMessages.FLUTTER_DEBUG_TOPIC, (FlutterViewMessages.FlutterDebugNotifier)event -> initView(project, event) | ||
); | ||
} | ||
|
||
private static void initView(Project project, FlutterViewMessages.FlutterDebugEvent event) { | ||
RemainingDevToolsViewService service = project.getService(RemainingDevToolsViewService.class); | ||
String vmServiceUri = event.app.getConnector().getBrowserUrl(); | ||
if (vmServiceUri == null) return; | ||
service.updateVmServiceUri(vmServiceUri); | ||
} | ||
|
||
|
||
@Override | ||
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow window) { | ||
final ContentManager contentManager = window.getContentManager(); | ||
FlutterSdk sdk = FlutterSdk.getFlutterSdk(project); | ||
FlutterSdkVersion sdkVersion = sdk == null ? null : sdk.getVersion(); | ||
RemainingDevToolsViewService service = project.getService(RemainingDevToolsViewService.class); | ||
|
||
AsyncUtils.whenCompleteUiThread( | ||
DevToolsService.getInstance(project).getDevToolsInstance(), | ||
(instance, error) -> { | ||
// Skip displaying if the project has been closed. | ||
if (!project.isOpen()) { | ||
return; | ||
} | ||
|
||
if (error != null) { | ||
return; | ||
} | ||
|
||
if (instance == null) { | ||
return; | ||
} | ||
|
||
final DevToolsUrl devToolsUrl = new DevToolsUrl.Builder() | ||
.setDevToolsHost(instance.host) | ||
.setDevToolsPort(instance.port) | ||
.setHide("home,inspector,deep-links,extensions") | ||
.setEmbed(true).setFlutterSdkVersion(sdkVersion) | ||
.setWorkspaceCache(WorkspaceCache.getInstance(project)) | ||
.setIdeFeature(DevToolsIdeFeature.TOOL_WINDOW) | ||
.build(); | ||
|
||
ApplicationManager.getApplication().invokeLater(() -> { | ||
Optional.ofNullable( | ||
FlutterUtils.embeddedBrowser(project)) | ||
.ifPresent(embeddedBrowser -> { | ||
service.setEmbeddedBrowser(embeddedBrowser); | ||
embeddedBrowser.openPanel(window, "Flutter DevTools", devToolsUrl, (String err) -> { | ||
System.out.println(err); | ||
}); | ||
}); | ||
}); | ||
} | ||
); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Object isApplicableAsync(@NotNull Project project, @NotNull Continuation<? super Boolean> $completion) { | ||
FlutterSdk sdk = FlutterSdk.getFlutterSdk(project); | ||
FlutterSdkVersion sdkVersion = sdk == null ? null : sdk.getVersion(); | ||
return sdkVersion != null && sdkVersion.canUseDevToolsMultiEmbed(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
flutter-idea/src/io/flutter/devtools/RemainingDevToolsViewService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2024 The Chromium Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package io.flutter.devtools; | ||
|
||
import com.intellij.openapi.components.Service; | ||
import com.intellij.openapi.project.Project; | ||
import io.flutter.view.EmbeddedBrowser; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@Service(Service.Level.PROJECT) | ||
public final class RemainingDevToolsViewService { | ||
private final Project myProject; | ||
private EmbeddedBrowser embeddedBrowser; | ||
|
||
RemainingDevToolsViewService(Project project) { | ||
this.myProject = project; | ||
} | ||
|
||
public void setEmbeddedBrowser(EmbeddedBrowser embeddedBrowser) { | ||
this.embeddedBrowser = embeddedBrowser; | ||
} | ||
|
||
public void updateVmServiceUri(@NotNull String vmServiceUri) { | ||
if (this.embeddedBrowser == null) return; | ||
this.embeddedBrowser.updateVmServiceUri(vmServiceUri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters