1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:process/process.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/logger.dart';
import '../base/os.dart';
import '../base/platform.dart';
import '../build_info.dart';
import '../desktop_device.dart';
import '../device.dart';
import '../macos/application_package.dart';
import '../project.dart';
import 'build_macos.dart';
import 'macos_workflow.dart';
/// A device that represents a desktop MacOS target.
class MacOSDevice extends DesktopDevice {
MacOSDevice({
required ProcessManager processManager,
required Logger logger,
required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils,
}) : _processManager = processManager,
_logger = logger,
_operatingSystemUtils = operatingSystemUtils,
super(
'macos',
platformType: PlatformType.macos,
ephemeral: false,
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
operatingSystemUtils: operatingSystemUtils,
);
final ProcessManager _processManager;
final Logger _logger;
final OperatingSystemUtils _operatingSystemUtils;
@override
bool isSupported() => true;
@override
String get name => 'macOS';
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.darwin;
@override
Future<String> get targetPlatformDisplayName async {
if (_operatingSystemUtils.hostPlatform == HostPlatform.darwin_arm) {
return 'darwin-arm64';
} else {
return 'darwin-x64';
}
}
@override
bool isSupportedForProject(FlutterProject flutterProject) {
return flutterProject.macos.existsSync();
}
@override
Future<void> buildForDevice(
covariant MacOSApp package, {
required BuildInfo buildInfo,
String? mainPath,
}) async {
await buildMacOS(
flutterProject: FlutterProject.current(),
buildInfo: buildInfo,
targetOverride: mainPath,
verboseLogging: _logger.isVerbose,
);
}
@override
String? executablePathForDevice(covariant MacOSApp package, BuildMode buildMode) {
return package.executable(buildMode);
}
@override
void onAttached(covariant MacOSApp package, BuildMode buildMode, Process process) {
// Bring app to foreground. Ideally this would be done post-launch rather
// than post-attach, since this won't run for release builds, but there's
// no general-purpose way of knowing when a process is far enough along in
// the launch process for 'open' to foreground it.
final String? applicationBundle = package.applicationBundle(buildMode);
if (applicationBundle == null) {
_logger.printError('Failed to foreground app; application bundle not found');
return;
}
_processManager.run(<String>[
'open', applicationBundle,
]).then((ProcessResult result) {
if (result.exitCode != 0) {
_logger.printError('Failed to foreground app; open returned ${result.exitCode}');
}
});
}
}
class MacOSDevices extends PollingDeviceDiscovery {
MacOSDevices({
required Platform platform,
required MacOSWorkflow macOSWorkflow,
required ProcessManager processManager,
required Logger logger,
required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils,
}) : _logger = logger,
_platform = platform,
_macOSWorkflow = macOSWorkflow,
_processManager = processManager,
_fileSystem = fileSystem,
_operatingSystemUtils = operatingSystemUtils,
super('macOS devices');
final MacOSWorkflow _macOSWorkflow;
final Platform _platform;
final ProcessManager _processManager;
final Logger _logger;
final FileSystem _fileSystem;
final OperatingSystemUtils _operatingSystemUtils;
@override
bool get supportsPlatform => _platform.isMacOS;
@override
bool get canListAnything => _macOSWorkflow.canListDevices;
@override
Future<List<Device>> pollingGetDevices({ Duration? timeout }) async {
if (!canListAnything) {
return const <Device>[];
}
return <Device>[
MacOSDevice(
processManager: _processManager,
logger: _logger,
fileSystem: _fileSystem,
operatingSystemUtils: _operatingSystemUtils,
),
];
}
@override
Future<List<String>> getDiagnostics() async => const <String>[];
@override
List<String> get wellKnownIds => const <String>['macos'];
}