install.dart 1.24 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
import '../application_package.dart';
8
import '../cache.dart';
9
import '../device.dart';
10
import '../globals.dart';
11
import '../runner/flutter_command.dart';
12

13
class InstallCommand extends FlutterCommand {
14
  @override
15
  final String name = 'install';
16 17

  @override
18
  final String description = 'Install a Flutter app on an attached device.';
19

20
  @override
21
  bool get requiresDevice => true;
22 23

  @override
24
  Future<int> runInProject() async {
25 26 27
    Device device = deviceForCommand;
    ApplicationPackage package = applicationPackages.getPackageForPlatform(device.platform);

28 29
    Cache.releaseLockEarly();

30 31 32
    printStatus('Installing $package to $device...');

    return installApp(device, package) ? 0 : 2;
33
  }
34
}
35

36
bool installApp(Device device, ApplicationPackage package, { bool uninstall: true }) {
37 38
  if (package == null)
    return false;
39

40
  if (uninstall && device.isAppInstalled(package)) {
41 42 43 44
    printStatus('Uninstalling old version...');
    if (!device.uninstallApp(package))
      printError('Warning: uninstalling old version failed');
  }
45

46
  return device.installApp(package);
47
}