blob: d29ded1df3e3aaa9555597dfc9ce5e27fb1d7356 [file] [log] [blame]
Ian Fischer81746e92015-09-11 12:20:20 -07001// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5library sky_tools.install;
6
7import 'dart:async';
8
Ian Fischercae053c2015-09-24 11:13:20 -07009import 'package:args/command_runner.dart';
Ian Fischer81746e92015-09-11 12:20:20 -070010
Ian Fischer0cc758d2015-09-18 17:11:30 -070011import 'application_package.dart';
Ian Fischer81746e92015-09-11 12:20:20 -070012import 'device.dart';
13
Ian Fischercae053c2015-09-24 11:13:20 -070014class InstallCommand extends Command {
15 final name = 'install';
16 final description = 'Install your Flutter app on attached devices.';
Devon Carew03645902015-10-06 11:36:48 -070017
Ian Fischerc5ea4092015-09-16 12:33:11 -070018 AndroidDevice android = null;
Ian Fischer12192d02015-10-02 08:34:09 -070019 IOSDevice ios;
Devon Carew03645902015-10-06 11:36:48 -070020
Ian Fischer12192d02015-10-02 08:34:09 -070021 InstallCommand({this.android, this.ios});
Ian Fischer81746e92015-09-11 12:20:20 -070022
23 @override
Ian Fischercae053c2015-09-24 11:13:20 -070024 Future<int> run() async {
Ian Fischer8cac55a2015-09-25 16:29:47 -070025 if (install()) {
26 return 0;
27 } else {
28 return 2;
29 }
30 }
31
32 bool install() {
Ian Fischer12192d02015-10-02 08:34:09 -070033 if (android == null) {
34 android = new AndroidDevice();
35 }
36 if (ios == null) {
37 ios = new IOSDevice();
38 }
39
Ian Fischer81746e92015-09-11 12:20:20 -070040 bool installedSomewhere = false;
41
Ian Fischer0cc758d2015-09-18 17:11:30 -070042 Map<BuildPlatform, ApplicationPackage> packages =
43 ApplicationPackageFactory.getAvailableApplicationPackages();
Ian Fischer0cc758d2015-09-18 17:11:30 -070044 ApplicationPackage androidApp = packages[BuildPlatform.android];
Ian Fischer12192d02015-10-02 08:34:09 -070045 ApplicationPackage iosApp = packages[BuildPlatform.iOS];
46
Ian Fischer0cc758d2015-09-18 17:11:30 -070047 if (androidApp != null && android.isConnected()) {
Ian Fischer8cac55a2015-09-25 16:29:47 -070048 installedSomewhere = android.installApp(androidApp) || installedSomewhere;
Ian Fischer81746e92015-09-11 12:20:20 -070049 }
50
Ian Fischer12192d02015-10-02 08:34:09 -070051 if (iosApp != null && ios.isConnected()) {
52 installedSomewhere = ios.installApp(iosApp) || installedSomewhere;
53 }
54
Ian Fischer8cac55a2015-09-25 16:29:47 -070055 return installedSomewhere;
Ian Fischer81746e92015-09-11 12:20:20 -070056 }
57}