[flutter_tools] Ensure flutter daemon clients can detect preview device (#140112)
Part of https://github.com/flutter/flutter/issues/130277
This commit is contained in:
committed by
GitHub
parent
90badf7050
commit
674fbd26bc
@@ -416,36 +416,167 @@ class DaemonDomain extends Domain {
|
||||
/// is correct.
|
||||
Future<Map<String, Object>> getSupportedPlatforms(Map<String, Object?> args) async {
|
||||
final String? projectRoot = _getStringArg(args, 'projectRoot', required: true);
|
||||
final List<String> result = <String>[];
|
||||
final List<String> platformTypes = <String>[];
|
||||
final Map<String, Object> platformTypesMap = <String, Object>{};
|
||||
try {
|
||||
final FlutterProject flutterProject = FlutterProject.fromDirectory(globals.fs.directory(projectRoot));
|
||||
final Set<SupportedPlatform> supportedPlatforms = flutterProject.getSupportedPlatforms().toSet();
|
||||
if (featureFlags.isLinuxEnabled && supportedPlatforms.contains(SupportedPlatform.linux)) {
|
||||
result.add('linux');
|
||||
}
|
||||
if (featureFlags.isMacOSEnabled && supportedPlatforms.contains(SupportedPlatform.macos)) {
|
||||
result.add('macos');
|
||||
}
|
||||
if (featureFlags.isWindowsEnabled && supportedPlatforms.contains(SupportedPlatform.windows)) {
|
||||
result.add('windows');
|
||||
}
|
||||
if (featureFlags.isIOSEnabled && supportedPlatforms.contains(SupportedPlatform.ios)) {
|
||||
result.add('ios');
|
||||
}
|
||||
if (featureFlags.isAndroidEnabled && supportedPlatforms.contains(SupportedPlatform.android)) {
|
||||
result.add('android');
|
||||
}
|
||||
if (featureFlags.isWebEnabled && supportedPlatforms.contains(SupportedPlatform.web)) {
|
||||
result.add('web');
|
||||
}
|
||||
if (featureFlags.isFuchsiaEnabled && supportedPlatforms.contains(SupportedPlatform.fuchsia)) {
|
||||
result.add('fuchsia');
|
||||
}
|
||||
if (featureFlags.areCustomDevicesEnabled) {
|
||||
result.add('custom');
|
||||
|
||||
void handlePlatformType(
|
||||
PlatformType platform,
|
||||
) {
|
||||
final List<Map<String, Object>> reasons = <Map<String, Object>>[];
|
||||
switch (platform) {
|
||||
case PlatformType.linux:
|
||||
if (!featureFlags.isLinuxEnabled) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Linux feature is not enabled',
|
||||
'fixText': 'Run "flutter config --enable-linux-desktop"',
|
||||
'fixCode': _ReasonCode.config.name,
|
||||
});
|
||||
}
|
||||
if (!supportedPlatforms.contains(SupportedPlatform.linux)) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Linux platform is not enabled for this project',
|
||||
'fixText': 'Run "flutter create --platforms=linux ." in your application directory',
|
||||
'fixCode': _ReasonCode.create.name,
|
||||
});
|
||||
}
|
||||
case PlatformType.macos:
|
||||
if (!featureFlags.isMacOSEnabled) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the macOS feature is not enabled',
|
||||
'fixText': 'Run "flutter config --enable-macos-desktop"',
|
||||
'fixCode': _ReasonCode.config.name,
|
||||
});
|
||||
}
|
||||
if (!supportedPlatforms.contains(SupportedPlatform.macos)) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the macOS platform is not enabled for this project',
|
||||
'fixText': 'Run "flutter create --platforms=macos ." in your application directory',
|
||||
'fixCode': _ReasonCode.create.name,
|
||||
});
|
||||
}
|
||||
case PlatformType.windows:
|
||||
if (!featureFlags.isWindowsEnabled) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Windows feature is not enabled',
|
||||
'fixText': 'Run "flutter config --enable-windows-desktop"',
|
||||
'fixCode': _ReasonCode.config.name,
|
||||
});
|
||||
}
|
||||
if (!supportedPlatforms.contains(SupportedPlatform.windows)) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Windows platform is not enabled for this project',
|
||||
'fixText': 'Run "flutter create --platforms=windows ." in your application directory',
|
||||
'fixCode': _ReasonCode.create.name,
|
||||
});
|
||||
}
|
||||
case PlatformType.ios:
|
||||
if (!featureFlags.isIOSEnabled) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the iOS feature is not enabled',
|
||||
'fixText': 'Run "flutter config --enable-ios"',
|
||||
'fixCode': _ReasonCode.config.name,
|
||||
});
|
||||
}
|
||||
if (!supportedPlatforms.contains(SupportedPlatform.ios)) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the iOS platform is not enabled for this project',
|
||||
'fixText': 'Run "flutter create --platforms=ios ." in your application directory',
|
||||
'fixCode': _ReasonCode.create.name,
|
||||
});
|
||||
}
|
||||
case PlatformType.android:
|
||||
if (!featureFlags.isAndroidEnabled) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Android feature is not enabled',
|
||||
'fixText': 'Run "flutter config --enable-android"',
|
||||
'fixCode': _ReasonCode.config.name,
|
||||
});
|
||||
}
|
||||
if (!supportedPlatforms.contains(SupportedPlatform.android)) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Android platform is not enabled for this project',
|
||||
'fixText': 'Run "flutter create --platforms=android ." in your application directory',
|
||||
'fixCode': _ReasonCode.create.name,
|
||||
});
|
||||
}
|
||||
case PlatformType.web:
|
||||
if (!featureFlags.isWebEnabled) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Web feature is not enabled',
|
||||
'fixText': 'Run "flutter config --enable-web"',
|
||||
'fixCode': _ReasonCode.config.name,
|
||||
});
|
||||
}
|
||||
if (!supportedPlatforms.contains(SupportedPlatform.web)) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Web platform is not enabled for this project',
|
||||
'fixText': 'Run "flutter create --platforms=web ." in your application directory',
|
||||
'fixCode': _ReasonCode.create.name,
|
||||
});
|
||||
}
|
||||
case PlatformType.fuchsia:
|
||||
if (!featureFlags.isFuchsiaEnabled) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Fuchsia feature is not enabled',
|
||||
'fixText': 'Run "flutter config --enable-fuchsia"',
|
||||
'fixCode': _ReasonCode.config.name,
|
||||
});
|
||||
}
|
||||
if (!supportedPlatforms.contains(SupportedPlatform.fuchsia)) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Fuchsia platform is not enabled for this project',
|
||||
'fixText': 'Run "flutter create --platforms=fuchsia ." in your application directory',
|
||||
'fixCode': _ReasonCode.create.name,
|
||||
});
|
||||
}
|
||||
case PlatformType.custom:
|
||||
if (!featureFlags.areCustomDevicesEnabled) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the custom devices feature is not enabled',
|
||||
'fixText': 'Run "flutter config --enable-custom-devices"',
|
||||
'fixCode': _ReasonCode.config.name,
|
||||
});
|
||||
}
|
||||
case PlatformType.windowsPreview:
|
||||
// TODO(fujino): detect if there any plugins with native code
|
||||
if (!featureFlags.isPreviewDeviceEnabled) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Preview Device feature is not enabled',
|
||||
'fixText': 'Run "flutter config --enable-flutter-preview',
|
||||
'fixCode': _ReasonCode.config.name,
|
||||
});
|
||||
}
|
||||
if (!supportedPlatforms.contains(SupportedPlatform.windows)) {
|
||||
reasons.add(<String, Object>{
|
||||
'reasonText': 'the Windows platform is not enabled for this project',
|
||||
'fixText': 'Run "flutter create --platforms=windows ." in your application directory',
|
||||
'fixCode': _ReasonCode.create.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (reasons.isEmpty) {
|
||||
platformTypes.add(platform.name);
|
||||
platformTypesMap[platform.name] = const <String, Object>{
|
||||
'isSupported': true,
|
||||
};
|
||||
} else {
|
||||
platformTypesMap[platform.name] = <String, Object>{
|
||||
'isSupported': false,
|
||||
'reasons': reasons,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
PlatformType.values.forEach(handlePlatformType);
|
||||
|
||||
return <String, Object>{
|
||||
'platforms': result,
|
||||
// TODO(fujino): delete this key https://github.com/flutter/flutter/issues/140473
|
||||
'platforms': platformTypes,
|
||||
'platformTypes': platformTypesMap,
|
||||
};
|
||||
} on Exception catch (err, stackTrace) {
|
||||
sendEvent('log', <String, Object?>{
|
||||
@@ -454,12 +585,16 @@ class DaemonDomain extends Domain {
|
||||
'error': true,
|
||||
});
|
||||
// On any sort of failure, fall back to Android and iOS for backwards
|
||||
// comparability.
|
||||
return <String, Object>{
|
||||
// compatibility.
|
||||
return const <String, Object>{
|
||||
'platforms': <String>[
|
||||
'android',
|
||||
'ios',
|
||||
],
|
||||
'platformTypes': <String, Object>{
|
||||
'android': <String, Object>{'isSupported': true},
|
||||
'ios': <String, Object>{'isSupported': true},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -470,6 +605,14 @@ class DaemonDomain extends Domain {
|
||||
}
|
||||
}
|
||||
|
||||
/// The reason a [PlatformType] is not currently supported.
|
||||
///
|
||||
/// The [name] of this value will be sent as a response to daemon client.
|
||||
enum _ReasonCode {
|
||||
create,
|
||||
config,
|
||||
}
|
||||
|
||||
typedef RunOrAttach = Future<void> Function({
|
||||
Completer<DebugConnectionInfo>? connectionInfoCompleter,
|
||||
Completer<void>? appStartedCompleter,
|
||||
|
||||
@@ -45,34 +45,20 @@ enum Category {
|
||||
|
||||
/// The platform sub-folder that a device type supports.
|
||||
enum PlatformType {
|
||||
web._('web'),
|
||||
android._('android'),
|
||||
ios._('ios'),
|
||||
linux._('linux'),
|
||||
macos._('macos'),
|
||||
windows._('windows'),
|
||||
fuchsia._('fuchsia'),
|
||||
custom._('custom');
|
||||
|
||||
const PlatformType._(this.value);
|
||||
|
||||
final String value;
|
||||
web,
|
||||
android,
|
||||
ios,
|
||||
linux,
|
||||
macos,
|
||||
windows,
|
||||
fuchsia,
|
||||
custom,
|
||||
windowsPreview;
|
||||
|
||||
@override
|
||||
String toString() => value;
|
||||
String toString() => name;
|
||||
|
||||
static PlatformType? fromString(String platformType) {
|
||||
return const <String, PlatformType>{
|
||||
'web': web,
|
||||
'android': android,
|
||||
'ios': ios,
|
||||
'linux': linux,
|
||||
'macos': macos,
|
||||
'windows': windows,
|
||||
'fuchsia': fuchsia,
|
||||
'custom': custom,
|
||||
}[platformType];
|
||||
}
|
||||
static PlatformType? fromString(String platformType) => values.asNameMap()[platformType];
|
||||
}
|
||||
|
||||
/// A discovery mechanism for flutter-supported development devices.
|
||||
|
||||
@@ -29,7 +29,7 @@ BundleBuilder _defaultBundleBuilder() {
|
||||
return BundleBuilder();
|
||||
}
|
||||
|
||||
class PreviewDeviceDiscovery extends DeviceDiscovery {
|
||||
class PreviewDeviceDiscovery extends PollingDeviceDiscovery {
|
||||
PreviewDeviceDiscovery({
|
||||
required Platform platform,
|
||||
required Artifacts artifacts,
|
||||
@@ -42,7 +42,8 @@ class PreviewDeviceDiscovery extends DeviceDiscovery {
|
||||
_processManager = processManager,
|
||||
_fileSystem = fileSystem,
|
||||
_platform = platform,
|
||||
_features = featureFlags;
|
||||
_features = featureFlags,
|
||||
super('Flutter preview device');
|
||||
|
||||
final Platform _platform;
|
||||
final Artifacts _artifacts;
|
||||
@@ -61,9 +62,8 @@ class PreviewDeviceDiscovery extends DeviceDiscovery {
|
||||
List<String> get wellKnownIds => <String>['preview'];
|
||||
|
||||
@override
|
||||
Future<List<Device>> devices({
|
||||
Future<List<Device>> pollingGetDevices({
|
||||
Duration? timeout,
|
||||
DeviceDiscoveryFilter? filter,
|
||||
}) async {
|
||||
final File previewBinary = _fileSystem.file(_artifacts.getArtifactPath(Artifact.flutterPreviewDevice));
|
||||
if (!previewBinary.existsSync()) {
|
||||
@@ -76,16 +76,8 @@ class PreviewDeviceDiscovery extends DeviceDiscovery {
|
||||
processManager: _processManager,
|
||||
previewBinary: previewBinary,
|
||||
);
|
||||
final bool matchesRequirements;
|
||||
if (!_features.isPreviewDeviceEnabled) {
|
||||
matchesRequirements = false;
|
||||
} else if (filter == null) {
|
||||
matchesRequirements = true;
|
||||
} else {
|
||||
matchesRequirements = await filter.matchesRequirements(device);
|
||||
}
|
||||
return <Device>[
|
||||
if (matchesRequirements)
|
||||
if (_features.isPreviewDeviceEnabled)
|
||||
device,
|
||||
];
|
||||
}
|
||||
@@ -114,7 +106,7 @@ class PreviewDevice extends Device {
|
||||
_fileSystem = fileSystem,
|
||||
_bundleBuilderFactory = builderFactory,
|
||||
_artifacts = artifacts,
|
||||
super('preview', ephemeral: false, category: Category.desktop, platformType: PlatformType.custom);
|
||||
super('preview', ephemeral: false, category: Category.desktop, platformType: PlatformType.windowsPreview);
|
||||
|
||||
final ProcessManager _processManager;
|
||||
final Logger _logger;
|
||||
@@ -161,7 +153,7 @@ class PreviewDevice extends Device {
|
||||
bool isSupportedForProject(FlutterProject flutterProject) => true;
|
||||
|
||||
@override
|
||||
String get name => 'preview';
|
||||
String get name => 'Preview';
|
||||
|
||||
@override
|
||||
DevicePortForwarder get portForwarder => const NoOpDevicePortForwarder();
|
||||
|
||||
Reference in New Issue
Block a user