Search in sources :

Example 1 with InspectorService

use of io.flutter.inspector.InspectorService 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.");
    }
}
Also used : Storage(com.intellij.openapi.components.Storage) UIUtil(com.intellij.util.ui.UIUtil) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) AllIcons(com.intellij.icons.AllIcons) Event(org.dartlang.vm.service.element.Event) PersistentStateComponent(com.intellij.openapi.components.PersistentStateComponent) FlutterInitializer(io.flutter.FlutterInitializer) TimeoutException(java.util.concurrent.TimeoutException) InspectorService(io.flutter.inspector.InspectorService) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) JBLabel(com.intellij.ui.components.JBLabel) SideBorder(com.intellij.ui.SideBorder) AsyncUtils(io.flutter.utils.AsyncUtils) JBUI(com.intellij.util.ui.JBUI) InspectorSourceLocation(io.flutter.inspector.InspectorSourceLocation) Disposer(com.intellij.openapi.util.Disposer) LinkLabel(com.intellij.ui.components.labels.LinkLabel) InspectorGroupManagerService(io.flutter.inspector.InspectorGroupManagerService) Logger(com.intellij.openapi.diagnostic.Logger) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JxBrowserUtils(io.flutter.utils.JxBrowserUtils) ToolWindow(com.intellij.openapi.wm.ToolWindow) ColorUtil(com.intellij.ui.ColorUtil) UISettingsListener(com.intellij.ide.ui.UISettingsListener) NonInjectable(com.intellij.serviceContainer.NonInjectable) ActionCallback(com.intellij.openapi.util.ActionCallback) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) FlutterIcons(icons.FlutterIcons) Content(com.intellij.ui.content.Content) ServiceExtensions(io.flutter.vmService.ServiceExtensions) BrowserLauncher(com.intellij.ide.browsers.BrowserLauncher) FlutterBundle(io.flutter.FlutterBundle) Nullable(org.jetbrains.annotations.Nullable) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) ContentManagerEvent(com.intellij.ui.content.ContentManagerEvent) XSourcePosition(com.intellij.xdebugger.XSourcePosition) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ContentManager(com.intellij.ui.content.ContentManager) ExecutionUtil(com.intellij.execution.runners.ExecutionUtil) NotNull(org.jetbrains.annotations.NotNull) FlutterDevice(io.flutter.run.FlutterDevice) TabInfo(com.intellij.ui.tabs.TabInfo) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter) ActiveRunnable(com.intellij.openapi.util.ActiveRunnable) java.util(java.util) LinkListener(com.intellij.ui.components.labels.LinkListener) CompletableFuture(java.util.concurrent.CompletableFuture) FlutterSettings(io.flutter.settings.FlutterSettings) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) JBRunnerTabs(com.intellij.execution.ui.layout.impl.JBRunnerTabs) DevToolsUrl(io.flutter.devtools.DevToolsUrl) io.flutter.jxbrowser(io.flutter.jxbrowser) Project(com.intellij.openapi.project.Project) FlutterUtils(io.flutter.FlutterUtils) ContentManagerAdapter(com.intellij.ui.content.ContentManagerAdapter) FlutterApp(io.flutter.run.daemon.FlutterApp) DiagnosticsNode(io.flutter.inspector.DiagnosticsNode) FlutterViewToolWindowManagerListener(io.flutter.toolwindow.FlutterViewToolWindowManagerListener) StringUtil(com.intellij.openapi.util.text.StringUtil) DevToolsService(io.flutter.run.daemon.DevToolsService) VmService(org.dartlang.vm.service.VmService) Disposable(com.intellij.openapi.Disposable) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) EventStream(io.flutter.utils.EventStream) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DevToolsInstance(io.flutter.run.daemon.DevToolsInstance) javax.swing(javax.swing) FlutterDevice(io.flutter.run.FlutterDevice) FlutterApp(io.flutter.run.daemon.FlutterApp) DevToolsUrl(io.flutter.devtools.DevToolsUrl) ContentManager(com.intellij.ui.content.ContentManager) List(java.util.List)

Example 2 with InspectorService

use of io.flutter.inspector.InspectorService in project flutter-intellij by flutter.

the class VmServiceWidgetPerfProvider method setupConnection.

private void setupConnection(@NotNull VmService vmService) {
    if (isDisposed || connected) {
        return;
    }
    final VMServiceManager vmServiceManager = app.getVMServiceManager();
    assert vmServiceManager != null;
    connected = true;
    isolateRefStreamSubscription = vmServiceManager.getCurrentFlutterIsolate((isolateRef) -> requestRepaint(When.soon), false);
    vmService.addVmServiceListener(new VmServiceListenerAdapter() {

        @Override
        public void received(String streamId, Event event) {
            onVmServiceReceived(streamId, event);
        }

        @Override
        public void connectionClosed() {
        }
    });
    inspectorService = InspectorService.create(app, app.getFlutterDebugProcess(), app.getVmService());
    inspectorService.whenCompleteAsync((service, throwable) -> Disposer.register(this, service));
    requestRepaint(When.soon);
}
Also used : JsonObject(com.google.gson.JsonObject) DiagnosticsNode(io.flutter.inspector.DiagnosticsNode) IsolateRef(org.dartlang.vm.service.element.IsolateRef) Event(org.dartlang.vm.service.element.Event) StringUtil(com.intellij.openapi.util.text.StringUtil) VmService(org.dartlang.vm.service.VmService) InspectorService(io.flutter.inspector.InspectorService) VMServiceManager(io.flutter.vmService.VMServiceManager) CompletableFuture(java.util.concurrent.CompletableFuture) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StreamSubscription(io.flutter.utils.StreamSubscription) Disposer(com.intellij.openapi.util.Disposer) VmServiceListener(org.dartlang.vm.service.VmServiceListener) NotNull(org.jetbrains.annotations.NotNull) FlutterApp(io.flutter.run.daemon.FlutterApp) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter) VMServiceManager(io.flutter.vmService.VMServiceManager) Event(org.dartlang.vm.service.element.Event) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter)

Example 3 with InspectorService

use of io.flutter.inspector.InspectorService in project flutter-intellij by flutter.

the class WidgetEditToolbar method applyChangeAndShowException.

private void applyChangeAndShowException(SourceChange change) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        try {
            AssistUtils.applySourceChange(project, change, false);
            if (hotReloadOnAction) {
                final InspectorService inspectorService = InspectorGroupManagerService.getInstance(project).getInspectorService();
                if (inspectorService != null) {
                    final ArrayList<FlutterApp> apps = new ArrayList<>();
                    apps.add(inspectorService.getApp());
                    FlutterReloadManager.getInstance(project).saveAllAndReloadAll(apps, "Refactor widget");
                }
            }
        } catch (DartSourceEditException exception) {
            FlutterMessages.showError("Error applying change", exception.getMessage(), project);
        }
    });
}
Also used : FlutterApp(io.flutter.run.daemon.FlutterApp) DartSourceEditException(com.jetbrains.lang.dart.assists.DartSourceEditException) InspectorService(io.flutter.inspector.InspectorService)

Aggregations

Disposer (com.intellij.openapi.util.Disposer)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 InspectorService (io.flutter.inspector.InspectorService)2 FlutterApp (io.flutter.run.daemon.FlutterApp)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 JsonObject (com.google.gson.JsonObject)1 ExecutionUtil (com.intellij.execution.runners.ExecutionUtil)1 JBRunnerTabs (com.intellij.execution.ui.layout.impl.JBRunnerTabs)1 AllIcons (com.intellij.icons.AllIcons)1 BrowserLauncher (com.intellij.ide.browsers.BrowserLauncher)1 UISettingsListener (com.intellij.ide.ui.UISettingsListener)1 Disposable (com.intellij.openapi.Disposable)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 PersistentStateComponent (com.intellij.openapi.components.PersistentStateComponent)1 Storage (com.intellij.openapi.components.Storage)1 Logger (com.intellij.openapi.diagnostic.Logger)1 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 Project (com.intellij.openapi.project.Project)1