Skip to content

Move JX Browser engine initialization to a separate thread #7576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flutter-idea/src/io/flutter/FlutterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ private static ModuleSourceOrderEntry findModuleSourceEntry(@NotNull Module modu
return null;
}

// TODO(helin24): Make other usages of embedded browser initialization safe for UI?
@Nullable
public static EmbeddedBrowser embeddedBrowser(Project project) {
if (project == null || project.isDisposed()) {
Expand Down
31 changes: 21 additions & 10 deletions flutter-idea/src/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.colors.EditorColorsListener;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.VerticalFlowLayout;
import com.intellij.openapi.util.Disposer;
Expand Down Expand Up @@ -211,16 +214,24 @@ private void addBrowserInspectorViewContent(FlutterApp app,
.build();

//noinspection CodeBlock2Expr
ApplicationManager.getApplication().invokeLater(() -> {
embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.openPanel(toolWindow, tabName, devToolsUrl, (String error) -> {
// 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. Error: " + error),
openDevToolsLabel(app, toolWindow, ideFeature)
);
presentClickableLabel(toolWindow, inputs);
}));
});

Runnable task = () -> {
embeddedBrowserOptional().ifPresent(
embeddedBrowser -> ApplicationManager.getApplication().invokeLater(() -> {
embeddedBrowser.openPanel(toolWindow, tabName, devToolsUrl, (String error) -> {
// 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. Error: " + error),
openDevToolsLabel(app, toolWindow, ideFeature)
);
presentClickableLabel(toolWindow, inputs);
});
}));
};
final ProgressManager progressManager = ProgressManager.getInstanceOrNull();
if (progressManager != null) {
progressManager.runProcess(task, new EmptyProgressIndicator());
}

if (!busSubscribed) {
busConnection.subscribe(EditorColorsManager.TOPIC, (EditorColorsListener)scheme ->
Expand Down