Skip to content

Commit

Permalink
Automatically launch the iOS simulator if it isn’t
Browse files Browse the repository at this point in the history
already running.

Fixes #262.
  • Loading branch information
iansf committed Jul 28, 2015
1 parent 24b6312 commit 8dbc270
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions build/config/ios/ios_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 8dbc270

Please sign in to comment.