Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Chris Bracken | 53c2f70 | 2021-05-12 20:45:30 -0700 | [diff] [blame] | 5 | import 'dart:async'; |
| 6 | |
Jonah Williams | 021311e | 2021-02-08 09:21:46 -0800 | [diff] [blame] | 7 | import 'package:process/process.dart'; |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 8 | |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 9 | import '../base/file_system.dart'; |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 10 | import '../base/logger.dart'; |
| 11 | import '../base/os.dart'; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 12 | import '../build_info.dart'; |
stuartmorgan | d992d6d | 2019-10-09 16:28:10 -0700 | [diff] [blame] | 13 | import '../desktop_device.dart'; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 14 | import '../device.dart'; |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 15 | import '../project.dart'; |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 16 | import 'application_package.dart'; |
| 17 | import 'build_windows.dart'; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 18 | import 'windows_workflow.dart'; |
| 19 | |
| 20 | /// A device that represents a desktop Windows target. |
stuartmorgan | d992d6d | 2019-10-09 16:28:10 -0700 | [diff] [blame] | 21 | class WindowsDevice extends DesktopDevice { |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 22 | WindowsDevice({ |
Jenn Magder | 6cbed01 | 2021-11-07 01:27:34 -0700 | [diff] [blame] | 23 | required ProcessManager processManager, |
| 24 | required Logger logger, |
| 25 | required FileSystem fileSystem, |
| 26 | required OperatingSystemUtils operatingSystemUtils, |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 27 | }) : super( |
James D. Lin | bdbe677 | 2020-06-18 15:30:00 -0700 | [diff] [blame] | 28 | 'windows', |
Jonah Williams | 5c52498 | 2019-06-18 15:23:14 -0700 | [diff] [blame] | 29 | platformType: PlatformType.windows, |
| 30 | ephemeral: false, |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 31 | processManager: processManager, |
| 32 | logger: logger, |
| 33 | fileSystem: fileSystem, |
| 34 | operatingSystemUtils: operatingSystemUtils, |
Jonah Williams | 5c52498 | 2019-06-18 15:23:14 -0700 | [diff] [blame] | 35 | ); |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 36 | |
| 37 | @override |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 38 | bool isSupported() => true; |
| 39 | |
| 40 | @override |
James D. Lin | cf8fbc3 | 2020-06-30 11:28:02 -0700 | [diff] [blame] | 41 | String get name => 'Windows'; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 42 | |
| 43 | @override |
Jonah Williams | 14992c5 | 2020-06-23 17:19:29 -0700 | [diff] [blame] | 44 | Future<TargetPlatform> get targetPlatform async => TargetPlatform.windows_x64; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 45 | |
Jonah Williams | 6b19184 | 2019-04-25 12:25:12 -0700 | [diff] [blame] | 46 | @override |
| 47 | bool isSupportedForProject(FlutterProject flutterProject) { |
| 48 | return flutterProject.windows.existsSync(); |
| 49 | } |
stuartmorgan | d992d6d | 2019-10-09 16:28:10 -0700 | [diff] [blame] | 50 | |
| 51 | @override |
Jenn Magder | ada4460 | 2022-12-15 11:59:34 -0800 | [diff] [blame] | 52 | Future<void> buildForDevice({ |
Jenn Magder | 6cbed01 | 2021-11-07 01:27:34 -0700 | [diff] [blame] | 53 | String? mainPath, |
| 54 | required BuildInfo buildInfo, |
stuartmorgan | d992d6d | 2019-10-09 16:28:10 -0700 | [diff] [blame] | 55 | }) async { |
| 56 | await buildWindows( |
| 57 | FlutterProject.current().windows, |
| 58 | buildInfo, |
| 59 | target: mainPath, |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | @override |
Chris Bracken | d272a3a | 2023-01-31 09:37:46 -0800 | [diff] [blame] | 64 | String executablePathForDevice(covariant WindowsApp package, BuildInfo buildInfo) { |
| 65 | return package.executable(buildInfo.mode); |
stuartmorgan | d992d6d | 2019-10-09 16:28:10 -0700 | [diff] [blame] | 66 | } |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | class WindowsDevices extends PollingDeviceDiscovery { |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 70 | WindowsDevices({ |
Jenn Magder | 6cbed01 | 2021-11-07 01:27:34 -0700 | [diff] [blame] | 71 | required ProcessManager processManager, |
| 72 | required Logger logger, |
| 73 | required FileSystem fileSystem, |
| 74 | required OperatingSystemUtils operatingSystemUtils, |
| 75 | required WindowsWorkflow windowsWorkflow, |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 76 | }) : _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 Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 88 | |
| 89 | @override |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 90 | bool get supportsPlatform => _windowsWorkflow.appliesToHostPlatform; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 91 | |
| 92 | @override |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 93 | bool get canListAnything => _windowsWorkflow.canListDevices; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 94 | |
| 95 | @override |
Jenn Magder | 6cbed01 | 2021-11-07 01:27:34 -0700 | [diff] [blame] | 96 | Future<List<Device>> pollingGetDevices({ Duration? timeout }) async { |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 97 | if (!canListAnything) { |
| 98 | return const <Device>[]; |
| 99 | } |
| 100 | return <Device>[ |
Jonah Williams | ddb8177 | 2020-10-02 21:52:53 -0700 | [diff] [blame] | 101 | WindowsDevice( |
| 102 | fileSystem: _fileSystem, |
| 103 | logger: _logger, |
| 104 | processManager: _processManager, |
| 105 | operatingSystemUtils: _operatingSystemUtils, |
| 106 | ), |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 107 | ]; |
| 108 | } |
| 109 | |
| 110 | @override |
| 111 | Future<List<String>> getDiagnostics() async => const <String>[]; |
Jonah Williams | 88e756d | 2021-06-24 18:46:04 -0700 | [diff] [blame] | 112 | |
| 113 | @override |
Jonah Williams | 944fcda | 2022-04-26 11:19:07 -0700 | [diff] [blame] | 114 | List<String> get wellKnownIds => const <String>['windows']; |
Jonah Williams | 3a694a6 | 2019-01-15 07:45:04 -0800 | [diff] [blame] | 115 | } |