-
Notifications
You must be signed in to change notification settings - Fork 323
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
Ide feature #7108
Ide feature #7108
Changes from 3 commits
4503e23
871b570
b5091ff
7da5c70
27028a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2023 The Chromium Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package io.flutter.devtools; | ||
|
||
/** | ||
* This identifies from what feature DevTools is started. See https://github.com/flutter/flutter-intellij/issues/7100 for details. | ||
*/ | ||
public enum DevToolsIdeFeature { | ||
ON_DEBUG_AUTOMATIC("onDebugAutomatic"), | ||
RUN_CONSOLE("runConsole"), | ||
TOOL_WINDOW("toolWindow"); | ||
|
||
public final String value; | ||
|
||
DevToolsIdeFeature(String value) { | ||
this.value = value; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
import io.flutter.FlutterInitializer; | ||
import io.flutter.FlutterUtils; | ||
import io.flutter.bazel.WorkspaceCache; | ||
import io.flutter.devtools.DevToolsIdeFeature; | ||
import io.flutter.devtools.DevToolsUrl; | ||
import io.flutter.inspector.DiagnosticsNode; | ||
import io.flutter.inspector.InspectorGroupManagerService; | ||
|
@@ -243,6 +244,7 @@ private void addBrowserInspectorViewContent(FlutterApp app, | |
@Nullable InspectorService inspectorService, | ||
ToolWindow toolWindow, | ||
boolean isEmbedded, | ||
boolean openOnAppLaunch, | ||
DevToolsInstance devToolsInstance) { | ||
assert(SwingUtilities.isEventDispatchThread()); | ||
|
||
|
@@ -275,7 +277,8 @@ private void addBrowserInspectorViewContent(FlutterApp app, | |
color, | ||
UIUtil.getFontSize(UIUtil.FontSize.NORMAL), | ||
flutterSdkVersion, | ||
WorkspaceCache.getInstance(app.getProject()) | ||
WorkspaceCache.getInstance(app.getProject()), | ||
openOnAppLaunch ? DevToolsIdeFeature.ON_DEBUG_AUTOMATIC : DevToolsIdeFeature.TOOL_WINDOW | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible that a user can have the openOnAppLaunch setting on, and also manually open the Inspector tool window? I would think we would only want ON_DEBUG_AUTOMATIC if a user did not manually open the tool window. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm yeah a user could open their project, and then before they run their app open the inspector tool window. I can change how we're setting |
||
); | ||
|
||
//noinspection CodeBlock2Expr | ||
|
@@ -284,7 +287,7 @@ private void addBrowserInspectorViewContent(FlutterApp app, | |
// 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, inspectorService, toolWindow) | ||
openDevToolsLabel(app, inspectorService, toolWindow, openOnAppLaunch) | ||
); | ||
presentClickableLabel(toolWindow, inputs); | ||
})); | ||
|
@@ -304,7 +307,7 @@ private void addBrowserInspectorViewContent(FlutterApp app, | |
} else { | ||
BrowserLauncher.getInstance().browse( | ||
(new DevToolsUrl(devToolsInstance.host, devToolsInstance.port, browserUrl, "inspector", false, null, null, | ||
flutterSdkVersion, WorkspaceCache.getInstance(app.getProject())).getUrlString()), | ||
flutterSdkVersion, WorkspaceCache.getInstance(app.getProject()), openOnAppLaunch ? DevToolsIdeFeature.ON_DEBUG_AUTOMATIC : DevToolsIdeFeature.TOOL_WINDOW).getUrlString()), | ||
null | ||
); | ||
presentLabel(toolWindow, "DevTools inspector has been opened in the browser."); | ||
|
@@ -486,19 +489,15 @@ public void debugActive(@NotNull FlutterViewMessages.FlutterDebugEvent event) { | |
} | ||
} | ||
|
||
protected void handleJxBrowserInstalled(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow) { | ||
presentDevTools(app, inspectorService, toolWindow, true); | ||
} | ||
|
||
private void presentDevTools(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow, boolean isEmbedded) { | ||
private void presentDevTools(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow, boolean isEmbedded, boolean openOnAppLaunch) { | ||
verifyEventDispatchThread(); | ||
|
||
devToolsInstallCount += 1; | ||
presentLabel(toolWindow, getInstallingDevtoolsLabel()); | ||
|
||
openInspectorWithDevTools(app, inspectorService, toolWindow, isEmbedded); | ||
openInspectorWithDevTools(app, inspectorService, toolWindow, isEmbedded, openOnAppLaunch); | ||
|
||
setUpToolWindowListener(app, inspectorService, toolWindow, isEmbedded); | ||
setUpToolWindowListener(app, inspectorService, toolWindow, isEmbedded, openOnAppLaunch); | ||
} | ||
|
||
@VisibleForTesting | ||
|
@@ -507,14 +506,14 @@ protected void verifyEventDispatchThread() { | |
} | ||
|
||
@VisibleForTesting | ||
protected void setUpToolWindowListener(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow, boolean isEmbedded) { | ||
protected void setUpToolWindowListener(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow, boolean isEmbedded, boolean openOnAppLaunch) { | ||
if (this.toolWindowListener == null) { | ||
this.toolWindowListener = new FlutterViewToolWindowManagerListener(myProject, toolWindow); | ||
} | ||
this.toolWindowListener.updateOnWindowOpen(() -> { | ||
devToolsInstallCount += 1; | ||
presentLabel(toolWindow, getInstallingDevtoolsLabel()); | ||
openInspectorWithDevTools(app, inspectorService, toolWindow, isEmbedded, true); | ||
openInspectorWithDevTools(app, inspectorService, toolWindow, isEmbedded, openOnAppLaunch, true); | ||
}); | ||
} | ||
|
||
|
@@ -524,14 +523,15 @@ private String getInstallingDevtoolsLabel() { | |
} | ||
|
||
@VisibleForTesting | ||
protected void openInspectorWithDevTools(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow, boolean isEmbedded) { | ||
openInspectorWithDevTools(app, inspectorService, toolWindow, isEmbedded, false); | ||
protected void openInspectorWithDevTools(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow, boolean isEmbedded, boolean openOnAppLaunch) { | ||
openInspectorWithDevTools(app, inspectorService, toolWindow, isEmbedded, openOnAppLaunch, false); | ||
} | ||
|
||
private void openInspectorWithDevTools(FlutterApp app, | ||
InspectorService inspectorService, | ||
ToolWindow toolWindow, | ||
boolean isEmbedded, | ||
boolean openOnAppLaunch, | ||
boolean forceDevToolsRestart) { | ||
AsyncUtils.whenCompleteUiThread( | ||
forceDevToolsRestart | ||
|
@@ -555,14 +555,14 @@ private void openInspectorWithDevTools(FlutterApp app, | |
return; | ||
} | ||
|
||
addBrowserInspectorViewContent(app, inspectorService, toolWindow, isEmbedded, instance); | ||
addBrowserInspectorViewContent(app, inspectorService, toolWindow, isEmbedded, openOnAppLaunch, instance); | ||
} | ||
); | ||
} | ||
|
||
private LabelInput openDevToolsLabel(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow) { | ||
private LabelInput openDevToolsLabel(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow, boolean openOnAppLaunch) { | ||
return new LabelInput("Open DevTools in the browser?", (linkLabel, data) -> { | ||
presentDevTools(app, inspectorService, toolWindow, false); | ||
presentDevTools(app, inspectorService, toolWindow, false, openOnAppLaunch); | ||
}); | ||
} | ||
|
||
|
@@ -595,16 +595,6 @@ protected void presentClickableLabel(ToolWindow toolWindow, List<LabelInput> lab | |
replacePanelLabel(toolWindow, center); | ||
} | ||
|
||
protected void presentOpenDevToolsOptionWithMessage(FlutterApp app, | ||
InspectorService inspectorService, | ||
ToolWindow toolWindow, | ||
String message) { | ||
final List<LabelInput> inputs = new ArrayList<>(); | ||
inputs.add(new LabelInput(message)); | ||
inputs.add(openDevToolsLabel(app, inspectorService, toolWindow)); | ||
presentClickableLabel(toolWindow, inputs); | ||
} | ||
|
||
private void replacePanelLabel(ToolWindow toolWindow, JComponent label) { | ||
ApplicationManager.getApplication().invokeLater(() -> { | ||
final ContentManager contentManager = toolWindow.getContentManager(); | ||
|
@@ -631,12 +621,13 @@ private void debugActiveHelper(FlutterApp app, @Nullable InspectorService inspec | |
return; | ||
} | ||
|
||
final boolean openOnAppLaunch = FlutterSettings.getInstance().isOpenInspectorOnAppLaunch(); | ||
if (toolWindow.isAvailable()) { | ||
updateToolWindowVisibility(toolWindow); | ||
updateToolWindowVisibility(toolWindow, openOnAppLaunch); | ||
} | ||
else { | ||
toolWindow.setAvailable(true, () -> { | ||
updateToolWindowVisibility(toolWindow); | ||
updateToolWindowVisibility(toolWindow, openOnAppLaunch); | ||
}); | ||
} | ||
|
||
|
@@ -649,21 +640,21 @@ private void debugActiveHelper(FlutterApp app, @Nullable InspectorService inspec | |
toolWindow.setIcon(ExecutionUtil.getLiveIndicator(FlutterIcons.Flutter_13)); | ||
|
||
if (toolWindow.isVisible()) { | ||
displayEmbeddedBrowser(app, inspectorService, toolWindow); | ||
displayEmbeddedBrowser(app, inspectorService, toolWindow, openOnAppLaunch); | ||
} | ||
else { | ||
if (toolWindowListener == null) { | ||
toolWindowListener = new FlutterViewToolWindowManagerListener(myProject, toolWindow); | ||
} | ||
// If the window isn't visible yet, only executed embedded browser steps when it becomes visible. | ||
toolWindowListener.updateOnWindowFirstVisible(() -> { | ||
displayEmbeddedBrowser(app, inspectorService, toolWindow); | ||
displayEmbeddedBrowser(app, inspectorService, toolWindow, openOnAppLaunch); | ||
}); | ||
} | ||
} | ||
|
||
private void displayEmbeddedBrowser(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow) { | ||
presentDevTools(app, inspectorService, toolWindow, true); | ||
private void displayEmbeddedBrowser(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow, boolean openOnAppLaunch) { | ||
presentDevTools(app, inspectorService, toolWindow, true, openOnAppLaunch); | ||
} | ||
|
||
private void updateForEmptyContent(ToolWindow toolWindow) { | ||
|
@@ -765,12 +756,12 @@ private void onAppChanged(FlutterApp app) { | |
} | ||
} | ||
|
||
private void updateToolWindowVisibility(ToolWindow flutterToolWindow) { | ||
private void updateToolWindowVisibility(ToolWindow flutterToolWindow, boolean openOnAppLaunch) { | ||
if (flutterToolWindow.isVisible()) { | ||
return; | ||
} | ||
|
||
if (FlutterSettings.getInstance().isOpenInspectorOnAppLaunch()) { | ||
if (openOnAppLaunch) { | ||
flutterToolWindow.show(null); | ||
} | ||
} | ||
|
@@ -802,7 +793,7 @@ public void perform(AnActionEvent event) { | |
|
||
FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(app.getProject()); | ||
BrowserLauncher.getInstance().browse( | ||
(new DevToolsUrl(instance.host, instance.port, urlString, null, false, null, null, flutterSdk == null ? null : flutterSdk.getVersion(), WorkspaceCache.getInstance(app.getProject())).getUrlString()), | ||
(new DevToolsUrl(instance.host, instance.port, urlString, null, false, null, null, flutterSdk == null ? null : flutterSdk.getVersion(), WorkspaceCache.getInstance(app.getProject()), null).getUrlString()), | ||
null | ||
); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Add a URL reference here or in DevToolsUrl.java that points to #7100 for documentation.