Skip to content

Remove automatic refresh of inspector window on theme change and check during manual refresh #7638

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
Sep 6, 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
12 changes: 12 additions & 0 deletions flutter-idea/src/io/flutter/devtools/DevToolsUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/
package io.flutter.devtools;

import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.util.ui.JBFont;
import com.intellij.util.ui.UIUtil;
import io.flutter.bazel.WorkspaceCache;
import io.flutter.sdk.FlutterSdkUtil;
import io.flutter.sdk.FlutterSdkVersion;
Expand Down Expand Up @@ -225,4 +229,12 @@ public void maybeUpdateColor() {
colorHexCode = newColor;
isBright = devToolsUtils.getIsBackgroundBright();
}

public void maybeUpdateFontSize() {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
final Float newFontSize = (float) scheme.getEditorFontSize();
if (fontSize == null || !fontSize.equals(newFontSize)) {
fontSize = newFontSize;
}
}
}
19 changes: 2 additions & 17 deletions flutter-idea/src/io/flutter/view/EmbeddedBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,23 +243,6 @@ public void updatePanelToWidget(String widgetId) {
});
}

public void updateColor(String newColor) {
updateUrlAndReload(devToolsUrl -> {
devToolsUrl.maybeUpdateColor();
return devToolsUrl;
});
}

public void updateFontSize(float newFontSize) {
updateUrlAndReload(devToolsUrl -> {
if (devToolsUrl.fontSize.equals(newFontSize)) {
return null;
}
devToolsUrl.fontSize = newFontSize;
return devToolsUrl;
});
}

public void updateVmServiceUri(@NotNull String newVmServiceUri) {
updateUrlAndReload(devToolsUrl -> {
if (newVmServiceUri.equals(devToolsUrl.vmServiceUri)) {
Expand All @@ -284,6 +267,8 @@ public void refresh(String toolWindowId) {
if (tab == null || tab.devToolsUrlFuture == null) return;
tab.devToolsUrlFuture.thenAccept(devToolsUrl -> {
if (devToolsUrl == null) return;
devToolsUrl.maybeUpdateColor();
devToolsUrl.maybeUpdateFontSize();
tab.embeddedTab.loadUrl(devToolsUrl.getUrlString());
});
});
Expand Down
21 changes: 2 additions & 19 deletions flutter-idea/src/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ public class FlutterView implements PersistentStateComponent<FlutterViewState>,
@NotNull
private final Project myProject;

private final MessageBusConnection busConnection;
private boolean busSubscribed = false;

private Content emptyContent;

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

public FlutterView(@NotNull Project project) {
this(project, JxBrowserManager.getInstance(), new JxBrowserUtils(), InspectorGroupManagerService.getInstance(project), ApplicationManager.getApplication().getMessageBus().connect());
this(project, JxBrowserManager.getInstance(), new JxBrowserUtils(), InspectorGroupManagerService.getInstance(project));
}

@VisibleForTesting
@NonInjectable
protected FlutterView(@NotNull Project project, @NotNull JxBrowserManager jxBrowserManager, JxBrowserUtils jxBrowserUtils, InspectorGroupManagerService inspectorGroupManagerService, MessageBusConnection messageBusConnection) {
protected FlutterView(@NotNull Project project, @NotNull JxBrowserManager jxBrowserManager, JxBrowserUtils jxBrowserUtils, InspectorGroupManagerService inspectorGroupManagerService) {
myProject = project;
this.jxBrowserUtils = jxBrowserUtils;
this.jxBrowserManager = jxBrowserManager;
this.busConnection = messageBusConnection;

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

@Override
public void dispose() {
busConnection.disconnect();
Disposer.dispose(this);
}

Expand Down Expand Up @@ -236,18 +231,6 @@ private void addBrowserInspectorViewContent(FlutterApp app,
progressManager.runProcess(task, new EmptyProgressIndicator());
}

if (!busSubscribed) {
busConnection.subscribe(EditorColorsManager.TOPIC, (EditorColorsListener)scheme ->
embeddedBrowserOptional()
.ifPresent(embeddedBrowser -> embeddedBrowser.updateColor(ColorUtil.toHex(UIUtil.getEditorPaneBackground())))
);
busConnection.subscribe(UISettingsListener.TOPIC, (UISettingsListener)scheme ->
embeddedBrowserOptional()
.ifPresent(embeddedBrowser -> embeddedBrowser.updateFontSize(UIUtil.getFontSize(UIUtil.FontSize.NORMAL)))
);
busSubscribed = true;
}

toolWindow.setTitleActions(List.of(new RefreshToolWindowAction(TOOL_WINDOW_ID)));
} else {
BrowserLauncher.getInstance().browse(
Expand Down
11 changes: 5 additions & 6 deletions flutter-idea/testSrc/unit/io/flutter/view/FlutterViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class FlutterViewTest {
JxBrowserUtils mockUtils = mock(JxBrowserUtils.class);
JxBrowserManager mockJxBrowserManager = mock(JxBrowserManager.class);
InspectorGroupManagerService mockInspectorGroupManagerService = mock(InspectorGroupManagerService.class);
MessageBusConnection mockBusConnection = mock(MessageBusConnection.class);

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

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

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

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

// 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
// installation to finish.
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockUtils, mockInspectorGroupManagerService, mockBusConnection);
final FlutterView flutterView = new FlutterView(mockProject, mockJxBrowserManager, mockUtils, mockInspectorGroupManagerService);
final FlutterView spy = spy(flutterView);

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

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

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

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

doNothing().when(spy).presentOpenDevToolsOptionWithMessage(any(), any(), any(), any());
Expand Down