windows_device.dart 3.05 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'dart:async';

7
import 'package:process/process.dart';
8

9 10 11
import '../base/file_system.dart';
import '../base/logger.dart';
import '../base/os.dart';
12
import '../build_info.dart';
13
import '../desktop_device.dart';
14
import '../device.dart';
15 16 17
import '../project.dart';
import 'application_package.dart';
import 'build_windows.dart';
18 19 20
import 'windows_workflow.dart';

/// A device that represents a desktop Windows target.
21
class WindowsDevice extends DesktopDevice {
22
  WindowsDevice({
23 24 25 26
    required ProcessManager processManager,
    required Logger logger,
    required FileSystem fileSystem,
    required OperatingSystemUtils operatingSystemUtils,
27
  }) : super(
28
      'windows',
29 30
      platformType: PlatformType.windows,
      ephemeral: false,
31 32 33 34
      processManager: processManager,
      logger: logger,
      fileSystem: fileSystem,
      operatingSystemUtils: operatingSystemUtils,
35
  );
36 37 38 39 40

  @override
  bool isSupported() => true;

  @override
41
  String get name => 'Windows';
42 43

  @override
44
  Future<TargetPlatform> get targetPlatform async => TargetPlatform.windows_x64;
45 46

  @override
47 48 49
  bool isSupportedForProject(FlutterProject flutterProject) {
    return flutterProject.windows.existsSync();
  }
50 51

  @override
52
  Future<void> buildForDevice({
53 54
    String? mainPath,
    required BuildInfo buildInfo,
55
  }) async {
56 57 58 59
    await buildWindows(
      FlutterProject.current().windows,
      buildInfo,
      target: mainPath,
60
    );
61 62 63
  }

  @override
64 65
  String executablePathForDevice(covariant WindowsApp package, BuildInfo buildInfo) {
    return package.executable(buildInfo.mode);
66
  }
67 68 69
}

class WindowsDevices extends PollingDeviceDiscovery {
70
  WindowsDevices({
71 72 73 74 75
    required ProcessManager processManager,
    required Logger logger,
    required FileSystem fileSystem,
    required OperatingSystemUtils operatingSystemUtils,
    required WindowsWorkflow windowsWorkflow,
76 77 78 79 80 81 82 83 84 85 86 87
  }) : _fileSystem = fileSystem,
      _logger = logger,
      _processManager = processManager,
      _operatingSystemUtils = operatingSystemUtils,
      _windowsWorkflow = windowsWorkflow,
      super('windows devices');

  final FileSystem _fileSystem;
  final Logger _logger;
  final ProcessManager _processManager;
  final OperatingSystemUtils _operatingSystemUtils;
  final WindowsWorkflow _windowsWorkflow;
88 89

  @override
90
  bool get supportsPlatform => _windowsWorkflow.appliesToHostPlatform;
91 92

  @override
93
  bool get canListAnything => _windowsWorkflow.canListDevices;
94 95

  @override
96
  Future<List<Device>> pollingGetDevices({ Duration? timeout }) async {
97 98 99 100
    if (!canListAnything) {
      return const <Device>[];
    }
    return <Device>[
101 102 103 104 105 106
      WindowsDevice(
        fileSystem: _fileSystem,
        logger: _logger,
        processManager: _processManager,
        operatingSystemUtils: _operatingSystemUtils,
      ),
107 108 109 110 111
    ];
  }

  @override
  Future<List<String>> getDiagnostics() async => const <String>[];
112 113

  @override
114
  List<String> get wellKnownIds => const <String>['windows'];
115
}