Commit 6a4b08be authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Make DeviceDomain echo a msg if doctor says it can't list anything (#9749)

This message will be picked up by IntelliJ and shown to the user in a toast.
parent b8b6a14d
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
import 'dart:async'; import 'dart:async';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:intl/intl_standalone.dart' as intl; import 'package:intl/intl_standalone.dart' as intl;
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -53,6 +52,7 @@ import 'src/run_hot.dart'; ...@@ -53,6 +52,7 @@ import 'src/run_hot.dart';
import 'src/runner/flutter_command.dart'; import 'src/runner/flutter_command.dart';
import 'src/runner/flutter_command_runner.dart'; import 'src/runner/flutter_command_runner.dart';
import 'src/usage.dart'; import 'src/usage.dart';
import 'src/version.dart';
/// Main entry point for commands. /// Main entry point for commands.
/// ///
......
...@@ -17,6 +17,7 @@ import '../base/process_manager.dart'; ...@@ -17,6 +17,7 @@ import '../base/process_manager.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../commands/build_apk.dart'; import '../commands/build_apk.dart';
import '../device.dart'; import '../device.dart';
import '../doctor.dart';
import '../globals.dart'; import '../globals.dart';
import '../protocol_discovery.dart'; import '../protocol_discovery.dart';
...@@ -27,11 +28,14 @@ import 'android_sdk.dart'; ...@@ -27,11 +28,14 @@ import 'android_sdk.dart';
const String _defaultAdbPath = 'adb'; const String _defaultAdbPath = 'adb';
class AndroidDevices extends PollingDeviceDiscovery { class AndroidDevices extends PollingDeviceDiscovery {
AndroidDevices() : super('AndroidDevices'); AndroidDevices() : super('Android devices');
@override @override
bool get supportsPlatform => true; bool get supportsPlatform => true;
@override
bool get canListAnything => doctor.androidWorkflow.canListDevices;
@override @override
List<Device> pollingGetDevices() => getAdbDevices(); List<Device> pollingGetDevices() => getAdbDevices();
} }
......
...@@ -62,12 +62,7 @@ class DaemonCommand extends FlutterCommand { ...@@ -62,12 +62,7 @@ class DaemonCommand extends FlutterCommand {
final int code = await daemon.onExit; final int code = await daemon.onExit;
if (code != 0) if (code != 0)
throwToolExit('Daemon exited with non-zero exit code: $code', exitCode: code); throwToolExit('Daemon exited with non-zero exit code: $code', exitCode: code);
}, onError: _handleError); });
}
dynamic _handleError(dynamic error, StackTrace stackTrace) {
printError('Error from flutter daemon: $error', stackTrace: stackTrace);
return null;
} }
} }
...@@ -76,7 +71,9 @@ typedef void DispatchCommand(Map<String, dynamic> command); ...@@ -76,7 +71,9 @@ typedef void DispatchCommand(Map<String, dynamic> command);
typedef Future<dynamic> CommandHandler(Map<String, dynamic> args); typedef Future<dynamic> CommandHandler(Map<String, dynamic> args);
class Daemon { class Daemon {
Daemon(Stream<Map<String, dynamic>> commandStream, this.sendCommand, { Daemon(
Stream<Map<String, dynamic>> commandStream,
this.sendCommand, {
this.daemonCommand, this.daemonCommand,
this.notifyingLogger, this.notifyingLogger,
this.logToStdout: false this.logToStdout: false
...@@ -87,7 +84,7 @@ class Daemon { ...@@ -87,7 +84,7 @@ class Daemon {
_registerDomain(deviceDomain = new DeviceDomain(this)); _registerDomain(deviceDomain = new DeviceDomain(this));
// Start listening. // Start listening.
commandStream.listen( _commandSubscription = commandStream.listen(
_handleRequest, _handleRequest,
onDone: () { onDone: () {
if (!_onExitCompleter.isCompleted) if (!_onExitCompleter.isCompleted)
...@@ -99,6 +96,7 @@ class Daemon { ...@@ -99,6 +96,7 @@ class Daemon {
DaemonDomain daemonDomain; DaemonDomain daemonDomain;
AppDomain appDomain; AppDomain appDomain;
DeviceDomain deviceDomain; DeviceDomain deviceDomain;
StreamSubscription<Map<String, dynamic>> _commandSubscription;
final DispatchCommand sendCommand; final DispatchCommand sendCommand;
final DaemonCommand daemonCommand; final DaemonCommand daemonCommand;
...@@ -143,10 +141,15 @@ class Daemon { ...@@ -143,10 +141,15 @@ class Daemon {
void _send(Map<String, dynamic> map) => sendCommand(map); void _send(Map<String, dynamic> map) => sendCommand(map);
void shutdown() { void shutdown({dynamic error}) {
_commandSubscription?.cancel();
_domainMap.values.forEach((Domain domain) => domain.dispose()); _domainMap.values.forEach((Domain domain) => domain.dispose());
if (!_onExitCompleter.isCompleted) if (!_onExitCompleter.isCompleted) {
if (error == null)
_onExitCompleter.complete(0); _onExitCompleter.complete(0);
else
_onExitCompleter.completeError(error);
}
} }
} }
...@@ -539,6 +542,18 @@ class DeviceDomain extends Domain { ...@@ -539,6 +542,18 @@ class DeviceDomain extends Domain {
if (!discoverer.supportsPlatform) if (!discoverer.supportsPlatform)
return; return;
if (!discoverer.canListAnything) {
sendEvent(
'daemon.showMessage',
<String, String>{
'title': 'Unable to list devices',
'message':
'Unable to discover ${discoverer.name}. Please run '
'"flutter doctor" to diagnose potential issues',
},
);
}
_discoverers.add(discoverer); _discoverers.add(discoverer);
discoverer.onAdded.listen(_onDeviceEvent('device.added')); discoverer.onAdded.listen(_onDeviceEvent('device.added'));
...@@ -650,7 +665,8 @@ Stream<Map<String, dynamic>> get stdinCommandStream => stdin ...@@ -650,7 +665,8 @@ Stream<Map<String, dynamic>> get stdinCommandStream => stdin
}); });
void stdoutCommandResponse(Map<String, dynamic> command) { void stdoutCommandResponse(Map<String, dynamic> command) {
stdout.writeln('[${JSON.encode(command, toEncodable: _jsonEncodeObject)}]'); final String encoded = JSON.encode(command, toEncodable: _jsonEncodeObject);
stdout.writeln('[$encoded]');
} }
dynamic _jsonEncodeObject(dynamic object) { dynamic _jsonEncodeObject(dynamic object) {
......
...@@ -92,6 +92,11 @@ class DeviceManager { ...@@ -92,6 +92,11 @@ class DeviceManager {
/// An abstract class to discover and enumerate a specific type of devices. /// An abstract class to discover and enumerate a specific type of devices.
abstract class DeviceDiscovery { abstract class DeviceDiscovery {
bool get supportsPlatform; bool get supportsPlatform;
/// Whether this device discovery is capable of listing any devices given the
/// current environment configuration.
bool get canListAnything;
List<Device> get devices; List<Device> get devices;
} }
......
...@@ -27,11 +27,14 @@ const String _kIdeviceinstallerInstructions = ...@@ -27,11 +27,14 @@ const String _kIdeviceinstallerInstructions =
const Duration kPortForwardTimeout = const Duration(seconds: 10); const Duration kPortForwardTimeout = const Duration(seconds: 10);
class IOSDevices extends PollingDeviceDiscovery { class IOSDevices extends PollingDeviceDiscovery {
IOSDevices() : super('IOSDevices'); IOSDevices() : super('iOS devices');
@override @override
bool get supportsPlatform => platform.isMacOS; bool get supportsPlatform => platform.isMacOS;
@override
bool get canListAnything => doctor.iosWorkflow.canListDevices;
@override @override
List<Device> pollingGetDevices() => IOSDevice.getAttachedDevices(); List<Device> pollingGetDevices() => IOSDevice.getAttachedDevices();
} }
......
...@@ -16,6 +16,7 @@ import '../base/process.dart'; ...@@ -16,6 +16,7 @@ import '../base/process.dart';
import '../base/process_manager.dart'; import '../base/process_manager.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../device.dart'; import '../device.dart';
import '../doctor.dart';
import '../flx.dart' as flx; import '../flx.dart' as flx;
import '../globals.dart'; import '../globals.dart';
import '../protocol_discovery.dart'; import '../protocol_discovery.dart';
...@@ -27,11 +28,14 @@ const String _xcrunPath = '/usr/bin/xcrun'; ...@@ -27,11 +28,14 @@ const String _xcrunPath = '/usr/bin/xcrun';
const String _kFlutterTestDeviceSuffix = '(Flutter)'; const String _kFlutterTestDeviceSuffix = '(Flutter)';
class IOSSimulators extends PollingDeviceDiscovery { class IOSSimulators extends PollingDeviceDiscovery {
IOSSimulators() : super('IOSSimulators'); IOSSimulators() : super('iOS simulators');
@override @override
bool get supportsPlatform => platform.isMacOS; bool get supportsPlatform => platform.isMacOS;
@override
bool get canListAnything => doctor.iosWorkflow.canListDevices;
@override @override
List<Device> pollingGetDevices() => IOSSimulatorUtils.instance.getAttachedDevices(); List<Device> pollingGetDevices() => IOSSimulatorUtils.instance.getAttachedDevices();
} }
......
...@@ -42,6 +42,9 @@ class MockPollingDeviceDiscovery extends PollingDeviceDiscovery { ...@@ -42,6 +42,9 @@ class MockPollingDeviceDiscovery extends PollingDeviceDiscovery {
@override @override
bool get supportsPlatform => true; bool get supportsPlatform => true;
@override
bool get canListAnything => true;
void addDevice(MockAndroidDevice device) { void addDevice(MockAndroidDevice device) {
_devices.add(device); _devices.add(device);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment