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 @@
import 'dart:async';
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:intl/intl_standalone.dart' as intl;
import 'package:meta/meta.dart';
import 'package:process/process.dart';
......@@ -53,6 +52,7 @@ import 'src/run_hot.dart';
import 'src/runner/flutter_command.dart';
import 'src/runner/flutter_command_runner.dart';
import 'src/usage.dart';
import 'src/version.dart';
/// Main entry point for commands.
///
......
......@@ -17,6 +17,7 @@ import '../base/process_manager.dart';
import '../build_info.dart';
import '../commands/build_apk.dart';
import '../device.dart';
import '../doctor.dart';
import '../globals.dart';
import '../protocol_discovery.dart';
......@@ -27,11 +28,14 @@ import 'android_sdk.dart';
const String _defaultAdbPath = 'adb';
class AndroidDevices extends PollingDeviceDiscovery {
AndroidDevices() : super('AndroidDevices');
AndroidDevices() : super('Android devices');
@override
bool get supportsPlatform => true;
@override
bool get canListAnything => doctor.androidWorkflow.canListDevices;
@override
List<Device> pollingGetDevices() => getAdbDevices();
}
......
......@@ -62,12 +62,7 @@ class DaemonCommand extends FlutterCommand {
final int code = await daemon.onExit;
if (code != 0)
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);
typedef Future<dynamic> CommandHandler(Map<String, dynamic> args);
class Daemon {
Daemon(Stream<Map<String, dynamic>> commandStream, this.sendCommand, {
Daemon(
Stream<Map<String, dynamic>> commandStream,
this.sendCommand, {
this.daemonCommand,
this.notifyingLogger,
this.logToStdout: false
......@@ -87,7 +84,7 @@ class Daemon {
_registerDomain(deviceDomain = new DeviceDomain(this));
// Start listening.
commandStream.listen(
_commandSubscription = commandStream.listen(
_handleRequest,
onDone: () {
if (!_onExitCompleter.isCompleted)
......@@ -99,6 +96,7 @@ class Daemon {
DaemonDomain daemonDomain;
AppDomain appDomain;
DeviceDomain deviceDomain;
StreamSubscription<Map<String, dynamic>> _commandSubscription;
final DispatchCommand sendCommand;
final DaemonCommand daemonCommand;
......@@ -143,10 +141,15 @@ class Daemon {
void _send(Map<String, dynamic> map) => sendCommand(map);
void shutdown() {
void shutdown({dynamic error}) {
_commandSubscription?.cancel();
_domainMap.values.forEach((Domain domain) => domain.dispose());
if (!_onExitCompleter.isCompleted)
_onExitCompleter.complete(0);
if (!_onExitCompleter.isCompleted) {
if (error == null)
_onExitCompleter.complete(0);
else
_onExitCompleter.completeError(error);
}
}
}
......@@ -539,6 +542,18 @@ class DeviceDomain extends Domain {
if (!discoverer.supportsPlatform)
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);
discoverer.onAdded.listen(_onDeviceEvent('device.added'));
......@@ -650,7 +665,8 @@ Stream<Map<String, dynamic>> get stdinCommandStream => stdin
});
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) {
......
......@@ -92,6 +92,11 @@ class DeviceManager {
/// An abstract class to discover and enumerate a specific type of devices.
abstract class DeviceDiscovery {
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;
}
......
......@@ -27,11 +27,14 @@ const String _kIdeviceinstallerInstructions =
const Duration kPortForwardTimeout = const Duration(seconds: 10);
class IOSDevices extends PollingDeviceDiscovery {
IOSDevices() : super('IOSDevices');
IOSDevices() : super('iOS devices');
@override
bool get supportsPlatform => platform.isMacOS;
@override
bool get canListAnything => doctor.iosWorkflow.canListDevices;
@override
List<Device> pollingGetDevices() => IOSDevice.getAttachedDevices();
}
......
......@@ -16,6 +16,7 @@ import '../base/process.dart';
import '../base/process_manager.dart';
import '../build_info.dart';
import '../device.dart';
import '../doctor.dart';
import '../flx.dart' as flx;
import '../globals.dart';
import '../protocol_discovery.dart';
......@@ -27,11 +28,14 @@ const String _xcrunPath = '/usr/bin/xcrun';
const String _kFlutterTestDeviceSuffix = '(Flutter)';
class IOSSimulators extends PollingDeviceDiscovery {
IOSSimulators() : super('IOSSimulators');
IOSSimulators() : super('iOS simulators');
@override
bool get supportsPlatform => platform.isMacOS;
@override
bool get canListAnything => doctor.iosWorkflow.canListDevices;
@override
List<Device> pollingGetDevices() => IOSSimulatorUtils.instance.getAttachedDevices();
}
......
......@@ -42,6 +42,9 @@ class MockPollingDeviceDiscovery extends PollingDeviceDiscovery {
@override
bool get supportsPlatform => true;
@override
bool get canListAnything => true;
void addDevice(MockAndroidDevice 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