8
8
import com .google .common .annotations .VisibleForTesting ;
9
9
import com .intellij .ide .browsers .BrowserLauncher ;
10
10
import com .intellij .openapi .Disposable ;
11
- import com .intellij .openapi .application .ApplicationManager ;
12
11
import com .intellij .openapi .components .Storage ;
13
12
import com .intellij .openapi .diagnostic .Logger ;
14
13
import com .intellij .openapi .progress .EmptyProgressIndicator ;
@@ -84,8 +83,8 @@ public class InspectorView implements Disposable {
84
83
85
84
private InspectorViewToolWindowManagerListener toolWindowListener ;
86
85
private int devToolsInstallCount = 0 ;
87
- private final JxBrowserUtils jxBrowserUtils ;
88
- private final JxBrowserManager jxBrowserManager ;
86
+ private final @ NotNull JxBrowserUtils jxBrowserUtils ;
87
+ private final @ NotNull JxBrowserManager jxBrowserManager ;
89
88
90
89
public InspectorView (@ NotNull Project project ) {
91
90
this (project , JxBrowserManager .getInstance (), new JxBrowserUtils (), new ViewUtils ());
@@ -95,7 +94,7 @@ public InspectorView(@NotNull Project project) {
95
94
@ NonInjectable
96
95
protected InspectorView (@ NotNull Project project ,
97
96
@ NotNull JxBrowserManager jxBrowserManager ,
98
- JxBrowserUtils jxBrowserUtils ,
97
+ @ NotNull JxBrowserUtils jxBrowserUtils ,
99
98
ViewUtils viewUtils ) {
100
99
myProject = project ;
101
100
this .jxBrowserUtils = jxBrowserUtils ;
@@ -119,11 +118,11 @@ void initToolWindow(@NotNull ToolWindow window) {
119
118
updateForEmptyContent (window );
120
119
}
121
120
122
- private void addBrowserInspectorViewContent (FlutterApp app ,
123
- ToolWindow toolWindow ,
121
+ private void addBrowserInspectorViewContent (@ NotNull FlutterApp app ,
122
+ @ NotNull ToolWindow toolWindow ,
124
123
boolean isEmbedded ,
125
124
DevToolsIdeFeature ideFeature ,
126
- DevToolsInstance devToolsInstance ) {
125
+ @ NotNull DevToolsInstance devToolsInstance ) {
127
126
assert (SwingUtilities .isEventDispatchThread ());
128
127
129
128
final ContentManager contentManager = toolWindow .getContentManager ();
@@ -199,7 +198,7 @@ private void addBrowserInspectorViewContent(FlutterApp app,
199
198
}
200
199
}
201
200
202
- private Optional <EmbeddedBrowser > embeddedBrowserOptional () {
201
+ private @ NotNull Optional <EmbeddedBrowser > embeddedBrowserOptional () {
203
202
if (myProject .isDisposed ()) {
204
203
return Optional .empty ();
205
204
}
@@ -264,6 +263,10 @@ private void openInspectorWithDevTools(FlutterApp app,
264
263
boolean isEmbedded ,
265
264
DevToolsIdeFeature ideFeature ,
266
265
boolean forceDevToolsRestart ) {
266
+ if (toolWindow == null ) {
267
+ LOG .error ("Unable to open Inspector with DevTools: toolwindow is null" );
268
+ return ;
269
+ }
267
270
AsyncUtils .whenCompleteUiThread (
268
271
forceDevToolsRestart
269
272
? DevToolsService .getInstance (myProject ).getDevToolsInstanceWithForcedRestart ()
@@ -281,7 +284,7 @@ private void openInspectorWithDevTools(FlutterApp app,
281
284
return ;
282
285
}
283
286
284
- if (instance == null ) {
287
+ if (instance == null || app == null ) {
285
288
viewUtils .presentLabel (toolWindow , DEVTOOLS_FAILED_LABEL );
286
289
return ;
287
290
}
@@ -311,7 +314,7 @@ protected void handleJxBrowserInstallationInProgress(FlutterApp app, ToolWindow
311
314
312
315
protected void startJxBrowserInstallationWaitingThread (FlutterApp app , ToolWindow toolWindow ,
313
316
DevToolsIdeFeature ideFeature ) {
314
- ApplicationManager . getApplication (). executeOnPooledThread (() -> {
317
+ OpenApiUtils . safeExecuteOnPooledThread (() -> {
315
318
waitForJxBrowserInstallation (app , toolWindow , ideFeature );
316
319
});
317
320
}
@@ -393,21 +396,6 @@ protected void presentOpenDevToolsOptionWithMessage(FlutterApp app,
393
396
viewUtils .presentClickableLabel (toolWindow , inputs );
394
397
}
395
398
396
- private void replacePanelLabel (ToolWindow toolWindow , JComponent label ) {
397
- OpenApiUtils .safeInvokeLater (() -> {
398
- final ContentManager contentManager = toolWindow .getContentManager ();
399
- if (contentManager .isDisposed ()) {
400
- return ;
401
- }
402
-
403
- final JPanel panel = new JPanel (new BorderLayout ());
404
- panel .add (label , BorderLayout .CENTER );
405
- final Content content = contentManager .getFactory ().createContent (panel , null , false );
406
- contentManager .removeAllContents (true );
407
- contentManager .addContent (content );
408
- });
409
- }
410
-
411
399
private void debugActiveHelper (@ NotNull FlutterApp app ) {
412
400
final ToolWindowManager toolWindowManager = ToolWindowManager .getInstance (myProject );
413
401
if (!(toolWindowManager instanceof ToolWindowManagerEx )) {
@@ -478,7 +466,7 @@ else if (jxBrowserStatus.equals(JxBrowserStatus.NOT_INSTALLED) || jxBrowserStatu
478
466
}
479
467
}
480
468
481
- private void updateForEmptyContent (ToolWindow toolWindow ) {
469
+ private void updateForEmptyContent (@ NotNull ToolWindow toolWindow ) {
482
470
// There's a possible race here where the tool window gets disposed while we're displaying contents.
483
471
if (toolWindow .isDisposed ()) {
484
472
return ;
@@ -495,7 +483,7 @@ private void updateForEmptyContent(ToolWindow toolWindow) {
495
483
}
496
484
497
485
// Returns true if the toolWindow was initially closed but opened automatically on app launch.
498
- private DevToolsIdeFeature updateToolWindowVisibility (ToolWindow flutterToolWindow ) {
486
+ private @ Nullable DevToolsIdeFeature updateToolWindowVisibility (@ NotNull ToolWindow flutterToolWindow ) {
499
487
if (flutterToolWindow .isVisible ()) {
500
488
return DevToolsIdeFeature .TOOL_WINDOW_RELOAD ;
501
489
}
0 commit comments