Skip to content

Commit a9f433c

Browse files
authored
Remove automatic refresh of inspector window on theme change and check during manual refresh (#7638)
This change: - Removes an automatic refresh of the inspector tool window when theming changes - Adds check for theming during manual refresh of all of the DevTools windows
1 parent d9f3db3 commit a9f433c

File tree

4 files changed

+21
-42
lines changed

4 files changed

+21
-42
lines changed

flutter-idea/src/io/flutter/devtools/DevToolsUrl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
package io.flutter.devtools;
77

8+
import com.intellij.openapi.editor.colors.EditorColorsManager;
9+
import com.intellij.openapi.editor.colors.EditorColorsScheme;
10+
import com.intellij.util.ui.JBFont;
11+
import com.intellij.util.ui.UIUtil;
812
import io.flutter.bazel.WorkspaceCache;
913
import io.flutter.sdk.FlutterSdkUtil;
1014
import io.flutter.sdk.FlutterSdkVersion;
@@ -225,4 +229,12 @@ public void maybeUpdateColor() {
225229
colorHexCode = newColor;
226230
isBright = devToolsUtils.getIsBackgroundBright();
227231
}
232+
233+
public void maybeUpdateFontSize() {
234+
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
235+
final Float newFontSize = (float) scheme.getEditorFontSize();
236+
if (fontSize == null || !fontSize.equals(newFontSize)) {
237+
fontSize = newFontSize;
238+
}
239+
}
228240
}

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,6 @@ public void updatePanelToWidget(String widgetId) {
243243
});
244244
}
245245

246-
public void updateColor(String newColor) {
247-
updateUrlAndReload(devToolsUrl -> {
248-
devToolsUrl.maybeUpdateColor();
249-
return devToolsUrl;
250-
});
251-
}
252-
253-
public void updateFontSize(float newFontSize) {
254-
updateUrlAndReload(devToolsUrl -> {
255-
if (devToolsUrl.fontSize.equals(newFontSize)) {
256-
return null;
257-
}
258-
devToolsUrl.fontSize = newFontSize;
259-
return devToolsUrl;
260-
});
261-
}
262-
263246
public void updateVmServiceUri(@NotNull String newVmServiceUri) {
264247
updateUrlAndReload(devToolsUrl -> {
265248
if (newVmServiceUri.equals(devToolsUrl.vmServiceUri)) {
@@ -284,6 +267,8 @@ public void refresh(String toolWindowId) {
284267
if (tab == null || tab.devToolsUrlFuture == null) return;
285268
tab.devToolsUrlFuture.thenAccept(devToolsUrl -> {
286269
if (devToolsUrl == null) return;
270+
devToolsUrl.maybeUpdateColor();
271+
devToolsUrl.maybeUpdateFontSize();
287272
tab.embeddedTab.loadUrl(devToolsUrl.getUrlString());
288273
});
289274
});

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ public class FlutterView implements PersistentStateComponent<FlutterViewState>,
101101
@NotNull
102102
private final Project myProject;
103103

104-
private final MessageBusConnection busConnection;
105-
private boolean busSubscribed = false;
106-
107104
private Content emptyContent;
108105

109106
private FlutterViewToolWindowManagerListener toolWindowListener;
@@ -112,16 +109,15 @@ public class FlutterView implements PersistentStateComponent<FlutterViewState>,
112109
private final JxBrowserManager jxBrowserManager;
113110

114111
public FlutterView(@NotNull Project project) {
115-
this(project, JxBrowserManager.getInstance(), new JxBrowserUtils(), InspectorGroupManagerService.getInstance(project), ApplicationManager.getApplication().getMessageBus().connect());
112+
this(project, JxBrowserManager.getInstance(), new JxBrowserUtils(), InspectorGroupManagerService.getInstance(project));
116113
}
117114

118115
@VisibleForTesting
119116
@NonInjectable
120-
protected FlutterView(@NotNull Project project, @NotNull JxBrowserManager jxBrowserManager, JxBrowserUtils jxBrowserUtils, InspectorGroupManagerService inspectorGroupManagerService, MessageBusConnection messageBusConnection) {
117+
protected FlutterView(@NotNull Project project, @NotNull JxBrowserManager jxBrowserManager, JxBrowserUtils jxBrowserUtils, InspectorGroupManagerService inspectorGroupManagerService) {
121118
myProject = project;
122119
this.jxBrowserUtils = jxBrowserUtils;
123120
this.jxBrowserManager = jxBrowserManager;
124-
this.busConnection = messageBusConnection;
125121

126122
shouldAutoHorizontalScroll.listen(state::setShouldAutoScroll);
127123
highlightNodesShownInBothTrees.listen(state::setHighlightNodesShownInBothTrees);
@@ -153,7 +149,6 @@ public void onSelectionChanged(DiagnosticsNode selection) {
153149

154150
@Override
155151
public void dispose() {
156-
busConnection.disconnect();
157152
Disposer.dispose(this);
158153
}
159154

@@ -236,18 +231,6 @@ private void addBrowserInspectorViewContent(FlutterApp app,
236231
progressManager.runProcess(task, new EmptyProgressIndicator());
237232
}
238233

239-
if (!busSubscribed) {
240-
busConnection.subscribe(EditorColorsManager.TOPIC, (EditorColorsListener)scheme ->
241-
embeddedBrowserOptional()
242-
.ifPresent(embeddedBrowser -> embeddedBrowser.updateColor(ColorUtil.toHex(UIUtil.getEditorPaneBackground())))
243-
);
244-
busConnection.subscribe(UISettingsListener.TOPIC, (UISettingsListener)scheme ->
245-
embeddedBrowserOptional()
246-
.ifPresent(embeddedBrowser -> embeddedBrowser.updateFontSize(UIUtil.getFontSize(UIUtil.FontSize.NORMAL)))
247-
);
248-
busSubscribed = true;
249-
}
250-
251234
toolWindow.setTitleActions(List.of(new RefreshToolWindowAction(TOOL_WINDOW_ID)));
252235
} else {
253236
BrowserLauncher.getInstance().browse(

flutter-idea/testSrc/unit/io/flutter/view/FlutterViewTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public class FlutterViewTest {
3838
JxBrowserUtils mockUtils = mock(JxBrowserUtils.class);
3939
JxBrowserManager mockJxBrowserManager = mock(JxBrowserManager.class);
4040
InspectorGroupManagerService mockInspectorGroupManagerService = mock(InspectorGroupManagerService.class);
41-
MessageBusConnection mockBusConnection = mock(MessageBusConnection.class);
4241

4342
@Test
4443
public void testHandleJxBrowserInstalled() {
@@ -59,7 +58,7 @@ public void testHandleJxBrowserInstallationFailed() {
5958
when(mockJxBrowserManager.getLatestFailureReason()).thenReturn(new InstallationFailedReason(FailureType.FILE_DOWNLOAD_FAILED));
6059

6160
// If JxBrowser failed to install, we should show a failure message that allows the user to manually retry.
62-
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockJxBrowserUtils, mockInspectorGroupManagerService, mockBusConnection);
61+
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockJxBrowserUtils, mockInspectorGroupManagerService);
6362
final FlutterView spy = spy(flutterView);
6463
doNothing().when(spy).presentClickableLabel(
6564
eq(mockToolWindow),
@@ -79,7 +78,7 @@ public void testHandleJxBrowserInstallationInProgressWithSuccessfulInstall() {
7978

8079
// If the JxBrowser installation is initially in progress, we should show a message about the installation.
8180
// If the installation quickly finishes (on the first re-check), then we should call the function to handle successful installation.
82-
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockUtils, mockInspectorGroupManagerService, mockBusConnection);
81+
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockUtils, mockInspectorGroupManagerService);
8382
final FlutterView spy = spy(flutterView);
8483

8584
doNothing().when(spy).presentOpenDevToolsOptionWithMessage(any(), any(), any(), any());
@@ -97,7 +96,7 @@ public void testHandleJxBrowserInstallationInProgressWaiting() {
9796

9897
// If the JxBrowser installation is in progress and is not finished on the first re-check, we should start a thread to wait for the
9998
// installation to finish.
100-
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockUtils, mockInspectorGroupManagerService, mockBusConnection);
99+
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockUtils, mockInspectorGroupManagerService);
101100
final FlutterView spy = spy(flutterView);
102101

103102
doNothing().when(spy).presentOpenDevToolsOptionWithMessage(any(), any(), any(), any());
@@ -115,7 +114,7 @@ public void testWaitForJxBrowserInstallationWithoutTimeout() throws TimeoutExcep
115114
when(mockJxBrowserManager.waitForInstallation(INSTALLATION_WAIT_LIMIT_SECONDS)).thenReturn(JxBrowserStatus.INSTALLATION_FAILED);
116115

117116
// If waiting for JxBrowser installation completes without timing out, then we should return to event thread.
118-
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockUtils, mockInspectorGroupManagerService, mockBusConnection);
117+
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockUtils, mockInspectorGroupManagerService);
119118
final FlutterView spy = spy(flutterView);
120119

121120
doNothing().when(spy).handleUpdatedJxBrowserStatusOnEventThread(any(), any(), any(), any());
@@ -132,7 +131,7 @@ public void testWaitForJxBrowserInstallationWithTimeout() throws TimeoutExceptio
132131
when(mockJxBrowserManager.waitForInstallation(INSTALLATION_WAIT_LIMIT_SECONDS)).thenThrow(new TimeoutException());
133132

134133
// If the JxBrowser installation doesn't complete on time, we should show a timed out message.
135-
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockUtils, mockInspectorGroupManagerService, mockBusConnection);
134+
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockUtils, mockInspectorGroupManagerService);
136135
final FlutterView spy = spy(flutterView);
137136

138137
doNothing().when(spy).presentOpenDevToolsOptionWithMessage(any(), any(), any(), any());

0 commit comments

Comments
 (0)