Skip to content

Commit 56a0e26

Browse files
authored
Move JX Browser engine initialization to a separate thread (#7576)
Sometimes starting the JX Browser engine is causing the UI freezes. This is trying to move some work out of the UI thread according to info from https://plugins.jetbrains.com/docs/intellij/general-threading-rules.html
1 parent 193b5bc commit 56a0e26

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

flutter-idea/src/io/flutter/FlutterUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ private static ModuleSourceOrderEntry findModuleSourceEntry(@NotNull Module modu
639639
return null;
640640
}
641641

642+
// TODO(helin24): Make other usages of embedded browser initialization safe for UI?
642643
@Nullable
643644
public static EmbeddedBrowser embeddedBrowser(Project project) {
644645
if (project == null || project.isDisposed()) {

flutter-idea/src/io/flutter/view/FlutterView.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import com.intellij.openapi.diagnostic.Logger;
1717
import com.intellij.openapi.editor.colors.EditorColorsListener;
1818
import com.intellij.openapi.editor.colors.EditorColorsManager;
19+
import com.intellij.openapi.progress.EmptyProgressIndicator;
20+
import com.intellij.openapi.progress.ProgressIndicator;
21+
import com.intellij.openapi.progress.ProgressManager;
1922
import com.intellij.openapi.project.Project;
2023
import com.intellij.openapi.ui.VerticalFlowLayout;
2124
import com.intellij.openapi.util.Disposer;
@@ -211,16 +214,24 @@ private void addBrowserInspectorViewContent(FlutterApp app,
211214
.build();
212215

213216
//noinspection CodeBlock2Expr
214-
ApplicationManager.getApplication().invokeLater(() -> {
215-
embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.openPanel(toolWindow, tabName, devToolsUrl, (String error) -> {
216-
// If the embedded browser doesn't work, offer a link to open in the regular browser.
217-
final List<LabelInput> inputs = Arrays.asList(
218-
new LabelInput("The embedded browser failed to load. Error: " + error),
219-
openDevToolsLabel(app, toolWindow, ideFeature)
220-
);
221-
presentClickableLabel(toolWindow, inputs);
222-
}));
223-
});
217+
218+
Runnable task = () -> {
219+
embeddedBrowserOptional().ifPresent(
220+
embeddedBrowser -> ApplicationManager.getApplication().invokeLater(() -> {
221+
embeddedBrowser.openPanel(toolWindow, tabName, devToolsUrl, (String error) -> {
222+
// If the embedded browser doesn't work, offer a link to open in the regular browser.
223+
final List<LabelInput> inputs = Arrays.asList(
224+
new LabelInput("The embedded browser failed to load. Error: " + error),
225+
openDevToolsLabel(app, toolWindow, ideFeature)
226+
);
227+
presentClickableLabel(toolWindow, inputs);
228+
});
229+
}));
230+
};
231+
final ProgressManager progressManager = ProgressManager.getInstanceOrNull();
232+
if (progressManager != null) {
233+
progressManager.runProcess(task, new EmptyProgressIndicator());
234+
}
224235

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

0 commit comments

Comments
 (0)