linux_device.dart 2.12 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 'package:meta/meta.dart';

7
import '../base/platform.dart';
8
import '../build_info.dart';
9
import '../desktop_device.dart';
10
import '../device.dart';
11
import '../features.dart';
12 13 14
import '../project.dart';
import 'application_package.dart';
import 'build_linux.dart';
15 16 17
import 'linux_workflow.dart';

/// A device that represents a desktop Linux target.
18
class LinuxDevice extends DesktopDevice {
19 20 21 22 23
  LinuxDevice() : super(
      'Linux',
      platformType: PlatformType.linux,
      ephemeral: false,
  );
24 25 26 27 28 29 30 31

  @override
  bool isSupported() => true;

  @override
  String get name => 'Linux';

  @override
32
  Future<TargetPlatform> get targetPlatform async => TargetPlatform.linux_x64;
33 34

  @override
35 36 37
  bool isSupportedForProject(FlutterProject flutterProject) {
    return flutterProject.linux.existsSync();
  }
38 39

  @override
40
  Future<void> buildForDevice(
41
    covariant LinuxApp package, {
42
    String mainPath,
43
    BuildInfo buildInfo,
44
  }) async {
45 46 47 48 49
    await buildLinux(
      FlutterProject.current().linux,
      buildInfo,
      target: mainPath,
    );
50 51 52
  }

  @override
53 54
  String executablePathForDevice(covariant LinuxApp package, BuildMode buildMode) {
    return package.executable(buildMode);
55
  }
56 57 58
}

class LinuxDevices extends PollingDeviceDiscovery {
59 60 61 62 63 64 65 66 67 68 69 70
  LinuxDevices({
    @required Platform platform,
    @required FeatureFlags featureFlags,
  }) : _platform = platform,
       _linuxWorkflow = LinuxWorkflow(
          platform: platform,
          featureFlags: featureFlags,
       ),
       super('linux devices');

  final Platform _platform;
  final LinuxWorkflow _linuxWorkflow;
71 72

  @override
73
  bool get supportsPlatform => _platform.isLinux;
74 75

  @override
76
  bool get canListAnything => _linuxWorkflow.canListDevices;
77 78

  @override
79
  Future<List<Device>> pollingGetDevices({ Duration timeout }) async {
80 81 82 83
    if (!canListAnything) {
      return const <Device>[];
    }
    return <Device>[
84
      LinuxDevice(),
85 86 87 88 89 90
    ];
  }

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