use of io.flutter.devtools.DevToolsUrl in project flutter-intellij by flutter.
the class PerfViewAppState method addPerformanceViewContent.
private void addPerformanceViewContent(FlutterApp app, ToolWindow toolWindow) {
final ContentManager contentManager = toolWindow.getContentManager();
final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true);
final FlutterDevice device = app.device();
final List<FlutterDevice> existingDevices = new ArrayList<>();
for (FlutterApp otherApp : perAppViewState.keySet()) {
existingDevices.add(otherApp.device());
}
final String tabName = device.getUniqueName(existingDevices);
// mainContentPanel contains the toolbar, perfViewsPanel, and the footer
final JPanel mainContentPanel = new JPanel(new BorderLayout());
final Content content = contentManager.getFactory().createContent(null, tabName, false);
content.setComponent(mainContentPanel);
content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
content.setIcon(FlutterIcons.Phone);
contentManager.addContent(content);
// perfViewsPanel contains the three performance views
final JComponent perfViewsPanel = Box.createVerticalBox();
perfViewsPanel.setBorder(JBUI.Borders.empty(0, 3));
mainContentPanel.add(perfViewsPanel, BorderLayout.CENTER);
if (emptyContent != null) {
contentManager.removeContent(emptyContent, true);
emptyContent = null;
}
toolWindow.setIcon(ExecutionUtil.getLiveIndicator(FlutterIcons.Flutter_13));
final PerfViewAppState state = getOrCreateStateForApp(app);
assert (state.content == null);
state.content = content;
final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, this);
toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterPerfViewToolbar", toolbarGroup, true).getComponent());
final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("PerformanceToolbar", toolbarGroup, true);
final JComponent toolbarComponent = toolbar.getComponent();
toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
mainContentPanel.add(toolbarComponent, BorderLayout.NORTH);
// devtools link and run mode footer
final JPanel footer = new JPanel(new BorderLayout());
footer.setBorder(new CompoundBorder(IdeBorderFactory.createBorder(SideBorder.TOP), JBUI.Borders.empty(5, 7)));
final JLabel runModeLabel = new JBLabel("Run mode: " + app.getLaunchMode());
if (app.getLaunchMode() == FlutterLaunchMode.DEBUG) {
runModeLabel.setIcon(AllIcons.General.BalloonInformation);
runModeLabel.setToolTipText("Note: debug mode frame rendering times are not indicative of release mode performance");
}
final LinkLabel<String> openDevtools = new LinkLabel<>("Open DevTools...", null);
openDevtools.setListener((linkLabel, data) -> {
AsyncUtils.whenCompleteUiThread(DevToolsService.getInstance(app.getProject()).getDevToolsInstance(), (instance, ex) -> {
if (app.getProject().isDisposed()) {
return;
}
if (ex != null) {
LOG.error(ex);
return;
}
BrowserLauncher.getInstance().browse((new DevToolsUrl(instance.host, instance.port, app.getConnector().getBrowserUrl(), null, false, null, null)).getUrlString(), null);
});
}, null);
footer.add(runModeLabel, BorderLayout.WEST);
footer.add(openDevtools, BorderLayout.EAST);
mainContentPanel.add(footer, BorderLayout.SOUTH);
final boolean debugConnectionAvailable = app.getLaunchMode().supportsDebugConnection();
final boolean isInProfileMode = app.getMode().isProfiling() || app.getLaunchMode().isProfiling();
// If the inspector is available (non-release mode), then show it.
if (debugConnectionAvailable) {
state.disposable = Disposer.newDisposable();
// Create the three FPS, memory, and widget recount areas.
final PerfFPSPanel fpsPanel = new PerfFPSPanel(app, this);
perfViewsPanel.add(fpsPanel);
final PerfMemoryPanel memoryPanel = new PerfMemoryPanel(app, this);
perfViewsPanel.add(memoryPanel);
final PerfWidgetRebuildsPanel widgetRebuildsPanel = new PerfWidgetRebuildsPanel(app, this);
perfViewsPanel.add(widgetRebuildsPanel);
// If in profile mode, auto-open the performance tool window.
if (isInProfileMode) {
activateToolWindow();
}
} else {
// Add a message about the inspector not being available in release mode.
final JBLabel label = new JBLabel("Profiling is not available in release mode", SwingConstants.CENTER);
label.setForeground(UIUtil.getLabelDisabledForeground());
mainContentPanel.add(label, BorderLayout.CENTER);
}
}
use of io.flutter.devtools.DevToolsUrl in project flutter-intellij by flutter.
the class LabelInput method addBrowserInspectorViewContent.
private void addBrowserInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow, boolean isEmbedded, DevToolsInstance devToolsInstance) {
assert (SwingUtilities.isEventDispatchThread());
final ContentManager contentManager = toolWindow.getContentManager();
final FlutterDevice device = app.device();
final List<FlutterDevice> existingDevices = new ArrayList<>();
for (FlutterApp otherApp : perAppViewState.keySet()) {
existingDevices.add(otherApp.device());
}
final String tabName = device.getUniqueName(existingDevices);
if (emptyContent != null) {
contentManager.removeContent(emptyContent, true);
emptyContent = null;
}
final String browserUrl = app.getConnector().getBrowserUrl();
if (isEmbedded) {
final String color = ColorUtil.toHex(UIUtil.getEditorPaneBackground());
final DevToolsUrl devToolsUrl = new DevToolsUrl(devToolsInstance.host, devToolsInstance.port, browserUrl, "inspector", true, color, UIUtil.getFontSize(UIUtil.FontSize.NORMAL));
// noinspection CodeBlock2Expr
ApplicationManager.getApplication().invokeLater(() -> {
embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.openPanel(contentManager, tabName, devToolsUrl, () -> {
// 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."), openDevToolsLabel(app, inspectorService, toolWindow));
presentClickableLabel(toolWindow, inputs);
}));
});
if (!busSubscribed) {
busConnection.subscribe(EditorColorsManager.TOPIC, scheme -> embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.updateColor(ColorUtil.toHex(UIUtil.getEditorPaneBackground()))));
busConnection.subscribe(UISettingsListener.TOPIC, scheme -> embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.updateFontSize(UIUtil.getFontSize(UIUtil.FontSize.NORMAL))));
busSubscribed = true;
}
} else {
BrowserLauncher.getInstance().browse((new DevToolsUrl(devToolsInstance.host, devToolsInstance.port, browserUrl, "inspector", false, null, null).getUrlString()), null);
presentLabel(toolWindow, "DevTools inspector has been opened in the browser.");
}
}
use of io.flutter.devtools.DevToolsUrl in project flutter-intellij by flutter.
the class OpenDevToolsAction method actionPerformed.
@Override
public void actionPerformed(@NotNull final AnActionEvent event) {
FlutterInitializer.sendAnalyticsAction(this);
Project project = event.getProject();
if (project == null) {
return;
}
AsyncUtils.whenCompleteUiThread(DevToolsService.getInstance(project).getDevToolsInstance(), (instance, ex) -> {
if (project.isDisposed()) {
return;
}
if (ex != null) {
LOG.error(ex);
return;
}
final String serviceUrl = myConnector != null && myConnector.getBrowserUrl() != null ? myConnector.getBrowserUrl() : null;
BrowserLauncher.getInstance().browse((new DevToolsUrl(instance.host, instance.port, serviceUrl, null, false, null, null).getUrlString()), null);
});
}
use of io.flutter.devtools.DevToolsUrl in project flutter-intellij by flutter.
the class LabelInput method perform.
@Override
public void perform(AnActionEvent event) {
if (app.isSessionActive()) {
final String urlString = app.getConnector().getBrowserUrl();
if (urlString == null) {
return;
}
AsyncUtils.whenCompleteUiThread(DevToolsService.getInstance(app.getProject()).getDevToolsInstance(), (instance, ex) -> {
if (app.getProject().isDisposed()) {
return;
}
if (ex != null) {
LOG.error(ex);
return;
}
BrowserLauncher.getInstance().browse((new DevToolsUrl(instance.host, instance.port, urlString, null, false, null, null).getUrlString()), null);
});
}
}
Aggregations