From 6a80f886f3558603d2a8c0dbc798d863dc523960 Mon Sep 17 00:00:00 2001 From: Ian Fischer Date: Fri, 24 Jul 2015 11:35:25 -0700 Subject: [PATCH] =?UTF-8?q?Automatically=20launch=20the=20iOS=20simulator?= =?UTF-8?q?=20if=20it=20isn=E2=80=99t=20already=20running.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #262. --- .../src/flutter/build/config/ios/ios_sim.py | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/build/config/ios/ios_sim.py b/engine/src/flutter/build/config/ios/ios_sim.py index ad2557e4a1..3fa567c291 100755 --- a/engine/src/flutter/build/config/ios/ios_sim.py +++ b/engine/src/flutter/build/config/ios/ios_sim.py @@ -4,11 +4,16 @@ # found in the LICENSE file. import argparse -import os import errno +import os +import re import subprocess import sys -import re +import time + +IOS_SIM_PATH = [ + '/Applications/iOS Simulator.app/Contents/MacOS/iOS Simulator' +] SIMCTL_PATH = [ '/usr/bin/env', @@ -32,8 +37,30 @@ def ApplicationIdentifier(path): return identifier.strip() +def IsDeviceBooted(): + devices = subprocess.check_output( SIMCTL_PATH + [ 'list', 'devices' ]).strip().split('\n') + for device in devices: + if re.search(r'\(Booted\)', device): + return True + return False + +# Launch whatever simulator the user last used, rather than try to guess which of their simulators they might want to use +def Boot(args): + if IsDeviceBooted(): + return + + # Use Popen here because launching the simulator from the command line in this manner doesn't return, so we can't check the result. + if args.ios_sim_path: + subprocess.Popen( args.ios_sim_path ) + else: + subprocess.Popen( IOS_SIM_PATH ) + + while not IsDeviceBooted(): + print('Waiting for iOS Simulator to boot...') + time.sleep(0.5) def Install(args): + Boot(args) return subprocess.check_call( SIMCTL_PATH + [ 'install', 'booted', @@ -100,6 +127,10 @@ def Main(): default='localhost:8080', help='Sky server address.') + parser.add_argument('--ios_sim_path', dest='ios_sim_path', + help='Path to your iOS Simulator executable. ' + 'Not normally required.') + subparsers = parser.add_subparsers() launch_parser = subparsers.add_parser('launch', help='Launch')