install.dart 1.13 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 The Chromium 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 'dart:async';

7 8
import '../application_package.dart';
import '../device.dart';
9
import '../runner/flutter_command.dart';
10

11 12
class InstallCommand extends FlutterCommand {
  final String name = 'install';
13
  final String description = 'Install Flutter apps on attached devices.';
14

15
  bool get requiresDevice => true;
16 17

  @override
18
  Future<int> runInProject() async {
19
    await downloadApplicationPackagesAndConnectToDevices();
20
    bool installedAny = await installApp(devices, applicationPackages);
21
    return installedAny ? 0 : 2;
22
  }
23
}
24

25
Future<bool> installApp(
26
  DeviceStore devices,
27 28
  ApplicationPackageStore applicationPackages
) async {
29 30 31 32
  bool installedSomewhere = false;

  for (Device device in devices.all) {
    ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);
33
    if (package == null || device.isAppInstalled(package))
34 35 36
      continue;
    if (device.installApp(package))
      installedSomewhere = true;
37
  }
38 39

  return installedSomewhere;
40
}