blob: d94b8bbaef0ecf582c2583798af0e559c68018f0 [file] [log] [blame]
Ian Hickson449f4a62019-11-27 15:04:02 -08001// Copyright 2014 The Flutter Authors. All rights reserved.
Jonah Williams3a694a62019-01-15 07:45:04 -08002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Chris Bracken53c2f702021-05-12 20:45:30 -07005import 'dart:async';
6
Jonah Williams021311e2021-02-08 09:21:46 -08007import 'package:process/process.dart';
Jonah Williamsac36e442019-04-18 18:05:04 -07008
Jonah Williamsddb81772020-10-02 21:52:53 -07009import '../base/file_system.dart';
Jonah Williamsddb81772020-10-02 21:52:53 -070010import '../base/logger.dart';
11import '../base/os.dart';
Jonah Williams3a694a62019-01-15 07:45:04 -080012import '../build_info.dart';
stuartmorgand992d6d2019-10-09 16:28:10 -070013import '../desktop_device.dart';
Jonah Williams3a694a62019-01-15 07:45:04 -080014import '../device.dart';
Jonah Williamsac36e442019-04-18 18:05:04 -070015import '../project.dart';
Jonah Williamsac36e442019-04-18 18:05:04 -070016import 'application_package.dart';
17import 'build_windows.dart';
Jonah Williams3a694a62019-01-15 07:45:04 -080018import 'windows_workflow.dart';
19
20/// A device that represents a desktop Windows target.
stuartmorgand992d6d2019-10-09 16:28:10 -070021class WindowsDevice extends DesktopDevice {
Jonah Williamsddb81772020-10-02 21:52:53 -070022 WindowsDevice({
Jenn Magder6cbed012021-11-07 01:27:34 -070023 required ProcessManager processManager,
24 required Logger logger,
25 required FileSystem fileSystem,
26 required OperatingSystemUtils operatingSystemUtils,
Jonah Williamsddb81772020-10-02 21:52:53 -070027 }) : super(
James D. Linbdbe6772020-06-18 15:30:00 -070028 'windows',
Jonah Williams5c524982019-06-18 15:23:14 -070029 platformType: PlatformType.windows,
30 ephemeral: false,
Jonah Williamsddb81772020-10-02 21:52:53 -070031 processManager: processManager,
32 logger: logger,
33 fileSystem: fileSystem,
34 operatingSystemUtils: operatingSystemUtils,
Jonah Williams5c524982019-06-18 15:23:14 -070035 );
Jonah Williams3a694a62019-01-15 07:45:04 -080036
37 @override
Jonah Williams3a694a62019-01-15 07:45:04 -080038 bool isSupported() => true;
39
40 @override
James D. Lincf8fbc32020-06-30 11:28:02 -070041 String get name => 'Windows';
Jonah Williams3a694a62019-01-15 07:45:04 -080042
43 @override
Jonah Williams14992c52020-06-23 17:19:29 -070044 Future<TargetPlatform> get targetPlatform async => TargetPlatform.windows_x64;
Jonah Williams3a694a62019-01-15 07:45:04 -080045
Jonah Williams6b191842019-04-25 12:25:12 -070046 @override
47 bool isSupportedForProject(FlutterProject flutterProject) {
48 return flutterProject.windows.existsSync();
49 }
stuartmorgand992d6d2019-10-09 16:28:10 -070050
51 @override
Jenn Magderada44602022-12-15 11:59:34 -080052 Future<void> buildForDevice({
Jenn Magder6cbed012021-11-07 01:27:34 -070053 String? mainPath,
54 required BuildInfo buildInfo,
stuartmorgand992d6d2019-10-09 16:28:10 -070055 }) async {
56 await buildWindows(
57 FlutterProject.current().windows,
58 buildInfo,
59 target: mainPath,
60 );
61 }
62
63 @override
Chris Brackend272a3a2023-01-31 09:37:46 -080064 String executablePathForDevice(covariant WindowsApp package, BuildInfo buildInfo) {
65 return package.executable(buildInfo.mode);
stuartmorgand992d6d2019-10-09 16:28:10 -070066 }
Jonah Williams3a694a62019-01-15 07:45:04 -080067}
68
69class WindowsDevices extends PollingDeviceDiscovery {
Jonah Williamsddb81772020-10-02 21:52:53 -070070 WindowsDevices({
Jenn Magder6cbed012021-11-07 01:27:34 -070071 required ProcessManager processManager,
72 required Logger logger,
73 required FileSystem fileSystem,
74 required OperatingSystemUtils operatingSystemUtils,
75 required WindowsWorkflow windowsWorkflow,
Jonah Williamsddb81772020-10-02 21:52:53 -070076 }) : _fileSystem = fileSystem,
77 _logger = logger,
78 _processManager = processManager,
79 _operatingSystemUtils = operatingSystemUtils,
80 _windowsWorkflow = windowsWorkflow,
81 super('windows devices');
82
83 final FileSystem _fileSystem;
84 final Logger _logger;
85 final ProcessManager _processManager;
86 final OperatingSystemUtils _operatingSystemUtils;
87 final WindowsWorkflow _windowsWorkflow;
Jonah Williams3a694a62019-01-15 07:45:04 -080088
89 @override
Jonah Williamsddb81772020-10-02 21:52:53 -070090 bool get supportsPlatform => _windowsWorkflow.appliesToHostPlatform;
Jonah Williams3a694a62019-01-15 07:45:04 -080091
92 @override
Jonah Williamsddb81772020-10-02 21:52:53 -070093 bool get canListAnything => _windowsWorkflow.canListDevices;
Jonah Williams3a694a62019-01-15 07:45:04 -080094
95 @override
Jenn Magder6cbed012021-11-07 01:27:34 -070096 Future<List<Device>> pollingGetDevices({ Duration? timeout }) async {
Jonah Williams3a694a62019-01-15 07:45:04 -080097 if (!canListAnything) {
98 return const <Device>[];
99 }
100 return <Device>[
Jonah Williamsddb81772020-10-02 21:52:53 -0700101 WindowsDevice(
102 fileSystem: _fileSystem,
103 logger: _logger,
104 processManager: _processManager,
105 operatingSystemUtils: _operatingSystemUtils,
106 ),
Jonah Williams3a694a62019-01-15 07:45:04 -0800107 ];
108 }
109
110 @override
111 Future<List<String>> getDiagnostics() async => const <String>[];
Jonah Williams88e756d2021-06-24 18:46:04 -0700112
113 @override
Jonah Williams944fcda2022-04-26 11:19:07 -0700114 List<String> get wellKnownIds => const <String>['windows'];
Jonah Williams3a694a62019-01-15 07:45:04 -0800115}