Search in sources :

Example 1 with DeviceService

use of io.flutter.run.daemon.DeviceService in project flutter-intellij by flutter.

the class DeviceSelectorAction method updateActions.

private void updateActions(@NotNull Project project, Presentation presentation) {
    actions.clear();
    final DeviceService service = DeviceService.getInstance(project);
    final Collection<FlutterDevice> devices = service.getConnectedDevices();
    for (FlutterDevice device : devices) {
        actions.add(new SelectDeviceAction(device, devices));
    }
    if (actions.isEmpty()) {
        final boolean isLoading = service.getStatus() == DeviceService.State.LOADING;
        final String message = isLoading ? FlutterBundle.message("devicelist.loading") : FlutterBundle.message("devicelist.empty");
        actions.add(new NoDevicesAction(message));
    }
    // Show the 'Open iOS Simulator' action.
    if (SystemInfo.isMac) {
        boolean simulatorOpen = false;
        for (AnAction action : actions) {
            if (action instanceof SelectDeviceAction) {
                final SelectDeviceAction deviceAction = (SelectDeviceAction) action;
                final FlutterDevice device = deviceAction.device;
                if (device.isIOS() && device.emulator()) {
                    simulatorOpen = true;
                }
            }
        }
        actions.add(new Separator());
        actions.add(new OpenSimulatorAction(!simulatorOpen));
    }
    // Add Open Android emulators actions.
    final List<OpenEmulatorAction> emulatorActions = OpenEmulatorAction.getEmulatorActions(project);
    if (!emulatorActions.isEmpty()) {
        actions.add(new Separator());
        actions.addAll(emulatorActions);
    }
    selectedDeviceAction = null;
    final FlutterDevice selectedDevice = service.getSelectedDevice();
    for (AnAction action : actions) {
        if (action instanceof SelectDeviceAction) {
            final SelectDeviceAction deviceAction = (SelectDeviceAction) action;
            if (Objects.equals(deviceAction.device, selectedDevice)) {
                selectedDeviceAction = deviceAction;
                final Presentation template = action.getTemplatePresentation();
                presentation.setIcon(template.getIcon());
                presentation.setText(deviceAction.deviceName());
                presentation.setEnabled(true);
                return;
            }
        }
    }
    if (devices.isEmpty()) {
        presentation.setText("<no devices>");
    } else {
        presentation.setText(null);
    }
}
Also used : DeviceService(io.flutter.run.daemon.DeviceService) FlutterDevice(io.flutter.run.daemon.FlutterDevice)

Aggregations

DeviceService (io.flutter.run.daemon.DeviceService)1 FlutterDevice (io.flutter.run.daemon.FlutterDevice)1