Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 1 | // 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 | |
| 5 | library sky_tools.install; |
| 6 | |
| 7 | import 'dart:async'; |
| 8 | |
Ian Fischer | cae053c | 2015-09-24 11:13:20 -0700 | [diff] [blame] | 9 | import 'package:args/command_runner.dart'; |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 10 | |
Ian Fischer | 0cc758d | 2015-09-18 17:11:30 -0700 | [diff] [blame] | 11 | import 'application_package.dart'; |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 12 | import 'device.dart'; |
| 13 | |
Ian Fischer | cae053c | 2015-09-24 11:13:20 -0700 | [diff] [blame] | 14 | class InstallCommand extends Command { |
| 15 | final name = 'install'; |
| 16 | final description = 'Install your Flutter app on attached devices.'; |
Devon Carew | 0364590 | 2015-10-06 11:36:48 -0700 | [diff] [blame] | 17 | |
Ian Fischer | c5ea409 | 2015-09-16 12:33:11 -0700 | [diff] [blame] | 18 | AndroidDevice android = null; |
Ian Fischer | 12192d0 | 2015-10-02 08:34:09 -0700 | [diff] [blame] | 19 | IOSDevice ios; |
Devon Carew | 0364590 | 2015-10-06 11:36:48 -0700 | [diff] [blame] | 20 | |
Ian Fischer | 12192d0 | 2015-10-02 08:34:09 -0700 | [diff] [blame] | 21 | InstallCommand({this.android, this.ios}); |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 22 | |
| 23 | @override |
Ian Fischer | cae053c | 2015-09-24 11:13:20 -0700 | [diff] [blame] | 24 | Future<int> run() async { |
Ian Fischer | 8cac55a | 2015-09-25 16:29:47 -0700 | [diff] [blame] | 25 | if (install()) { |
| 26 | return 0; |
| 27 | } else { |
| 28 | return 2; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | bool install() { |
Ian Fischer | 12192d0 | 2015-10-02 08:34:09 -0700 | [diff] [blame] | 33 | if (android == null) { |
| 34 | android = new AndroidDevice(); |
| 35 | } |
| 36 | if (ios == null) { |
| 37 | ios = new IOSDevice(); |
| 38 | } |
| 39 | |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 40 | bool installedSomewhere = false; |
| 41 | |
Ian Fischer | 0cc758d | 2015-09-18 17:11:30 -0700 | [diff] [blame] | 42 | Map<BuildPlatform, ApplicationPackage> packages = |
| 43 | ApplicationPackageFactory.getAvailableApplicationPackages(); |
Ian Fischer | 0cc758d | 2015-09-18 17:11:30 -0700 | [diff] [blame] | 44 | ApplicationPackage androidApp = packages[BuildPlatform.android]; |
Ian Fischer | 12192d0 | 2015-10-02 08:34:09 -0700 | [diff] [blame] | 45 | ApplicationPackage iosApp = packages[BuildPlatform.iOS]; |
| 46 | |
Ian Fischer | 0cc758d | 2015-09-18 17:11:30 -0700 | [diff] [blame] | 47 | if (androidApp != null && android.isConnected()) { |
Ian Fischer | 8cac55a | 2015-09-25 16:29:47 -0700 | [diff] [blame] | 48 | installedSomewhere = android.installApp(androidApp) || installedSomewhere; |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Ian Fischer | 12192d0 | 2015-10-02 08:34:09 -0700 | [diff] [blame] | 51 | if (iosApp != null && ios.isConnected()) { |
| 52 | installedSomewhere = ios.installApp(iosApp) || installedSomewhere; |
| 53 | } |
| 54 | |
Ian Fischer | 8cac55a | 2015-09-25 16:29:47 -0700 | [diff] [blame] | 55 | return installedSomewhere; |
Ian Fischer | 81746e9 | 2015-09-11 12:20:20 -0700 | [diff] [blame] | 56 | } |
| 57 | } |