1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:async';
6
7import 'package:process/process.dart';
8
9import '../application_package.dart';
10import '../base/file_system.dart';
11import '../base/logger.dart';
12import '../base/os.dart';
13import '../base/platform.dart';
14import '../build_info.dart';
15import '../desktop_device.dart';
16import '../device.dart';
17import '../device_vm_service_discovery_for_attach.dart';
18import '../ios/ios_workflow.dart';
19import '../project.dart';
20
21/// Represents an ARM macOS target that can run iPad apps.
22///
23/// https://developer.apple.com/documentation/apple-silicon/running-your-ios-apps-on-macos
24class MacOSDesignedForIPadDevice extends DesktopDevice {
25 MacOSDesignedForIPadDevice({
26 required ProcessManager processManager,
27 required Logger logger,
28 required FileSystem fileSystem,
29 required OperatingSystemUtils operatingSystemUtils,
30 }) : _operatingSystemUtils = operatingSystemUtils,
31 super(
32 'mac-designed-for-ipad',
33 platformType: PlatformType.macos,
34 ephemeral: false,
35 processManager: processManager,
36 logger: logger,
37 fileSystem: fileSystem,
38 operatingSystemUtils: operatingSystemUtils,
39 );
40
41 final OperatingSystemUtils _operatingSystemUtils;
42
43 @override
44 String get name => 'Mac Designed for iPad';
45
46 @override
47 Future<TargetPlatform> get targetPlatform async => TargetPlatform.darwin;
48
49 @override
50 bool isSupported() => _operatingSystemUtils.hostPlatform == HostPlatform.darwin_arm64;
51
52 @override
53 bool get supportsFlavors => true;
54
55 @override
56 bool isSupportedForProject(FlutterProject flutterProject) {
57 return flutterProject.ios.existsSync() && _operatingSystemUtils.hostPlatform == HostPlatform.darwin_arm64;
58 }
59
60 @override
61 String? executablePathForDevice(ApplicationPackage package, BuildInfo buildInfo) => null;
62
63 @override
64 VMServiceDiscoveryForAttach getVMServiceDiscoveryForAttach({
65 String? appId,
66 String? fuchsiaModule,
67 int? filterDevicePort,
68 int? expectedHostPort,
69 required bool ipv6,
70 required Logger logger,
71 }) {
72 final MdnsVMServiceDiscoveryForAttach mdnsVMServiceDiscoveryForAttach = MdnsVMServiceDiscoveryForAttach(
73 device: this,
74 appId: appId,
75 deviceVmservicePort: filterDevicePort,
76 hostVmservicePort: expectedHostPort,
77 usesIpv6: ipv6,
78 useDeviceIPAsHost: false,
79 );
80
81 return DelegateVMServiceDiscoveryForAttach(<VMServiceDiscoveryForAttach>[
82 mdnsVMServiceDiscoveryForAttach,
83 super.getVMServiceDiscoveryForAttach(
84 appId: appId,
85 fuchsiaModule: fuchsiaModule,
86 filterDevicePort: filterDevicePort,
87 expectedHostPort: expectedHostPort,
88 ipv6: ipv6,
89 logger: logger,
90 ),
91 ]);
92 }
93
94 @override
95 Future<LaunchResult> startApp(
96 ApplicationPackage? package, {
97 String? mainPath,
98 String? route,
99 required DebuggingOptions debuggingOptions,
100 Map<String, Object?> platformArgs = const <String, Object>{},
101 bool prebuiltApplication = false,
102 String? userIdentifier,
103 }) async {
104 // Only attaching to a running app launched from Xcode is supported.
105 throw UnimplementedError('Building for "$name" is not supported.');
106 }
107
108 @override
109 Future<bool> stopApp(
110 ApplicationPackage? app, {
111 String? userIdentifier,
112 }) async => false;
113
114 @override
115 Future<void> buildForDevice({
116 String? mainPath,
117 required BuildInfo buildInfo,
118 bool usingCISystem = false,
119 }) async {
120 // Only attaching to a running app launched from Xcode is supported.
121 throw UnimplementedError('Building for "$name" is not supported.');
122 }
123}
124
125class MacOSDesignedForIPadDevices extends PollingDeviceDiscovery {
126 MacOSDesignedForIPadDevices({
127 required Platform platform,
128 required IOSWorkflow iosWorkflow,
129 required ProcessManager processManager,
130 required Logger logger,
131 required FileSystem fileSystem,
132 required OperatingSystemUtils operatingSystemUtils,
133 }) : _logger = logger,
134 _platform = platform,
135 _iosWorkflow = iosWorkflow,
136 _processManager = processManager,
137 _fileSystem = fileSystem,
138 _operatingSystemUtils = operatingSystemUtils,
139 super('Mac designed for iPad devices');
140
141 final IOSWorkflow _iosWorkflow;
142 final Platform _platform;
143 final ProcessManager _processManager;
144 final Logger _logger;
145 final FileSystem _fileSystem;
146 final OperatingSystemUtils _operatingSystemUtils;
147
148 @override
149 bool get supportsPlatform => _platform.isMacOS;
150
151 /// iOS (not desktop macOS) development is enabled, the host is an ARM Mac,
152 /// and discovery is allowed for this command.
153 @override
154 bool get canListAnything =>
155 _iosWorkflow.canListDevices && _operatingSystemUtils.hostPlatform == HostPlatform.darwin_arm64;
156
157 @override
158 Future<List<Device>> pollingGetDevices({Duration? timeout}) async {
159 if (!canListAnything) {
160 return const <Device>[];
161 }
162 return <Device>[
163 MacOSDesignedForIPadDevice(
164 processManager: _processManager,
165 logger: _logger,
166 fileSystem: _fileSystem,
167 operatingSystemUtils: _operatingSystemUtils,
168 ),
169 ];
170 }
171
172 @override
173 Future<List<String>> getDiagnostics() async => const <String>[];
174
175 @override
176 List<String> get wellKnownIds => const <String>['mac-designed-for-ipad'];
177}
178

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com