Skip to content

Commit c6f62cb

Browse files
author
Daniel Prows
committed
refactoring launching when using Xcode 6 device type identifiers
1 parent 9397b42 commit c6f62cb

File tree

3 files changed

+65
-43
lines changed

3 files changed

+65
-43
lines changed

lib/sim_launcher/direct_client.rb

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
11
module SimLauncher
2-
class DirectClient
3-
def initialize( app_path, sdk, family )
4-
@app_path = File.expand_path( app_path )
5-
@sdk = sdk
6-
@family = family
7-
end
8-
9-
def self.for_ipad_app( app_path, sdk = nil )
10-
self.new( app_path, sdk, 'ipad' )
11-
end
12-
13-
def self.for_iphone_app( app_path, sdk = nil )
14-
self.new( app_path, sdk, 'iphone' )
15-
end
16-
17-
def launch
18-
SimLauncher::Simulator.new.launch_ios_app( @app_path, @sdk, @family )
19-
end
20-
21-
def rotate_left
22-
simulator = SimLauncher::Simulator.new
23-
simulator.rotate_left
24-
end
25-
26-
def rotate_right
27-
simulator = SimLauncher::Simulator.new
28-
simulator.rotate_right
29-
end
30-
31-
32-
33-
def relaunch
34-
simulator = SimLauncher::Simulator.new
35-
simulator.quit_simulator
36-
simulator.launch_ios_app( @app_path, @sdk, @family )
37-
end
38-
end
2+
class DirectClient
3+
def initialize( app_path, sdk, options ={} )
4+
@app_path = File.expand_path( app_path )
5+
@sdk = sdk
6+
@family = options[:family]
7+
@device_type_identifier = options[:device_type_identifier]
8+
end
9+
10+
def self.for_ipad_app( app_path, sdk = nil )
11+
self.new( app_path, sdk, 'ipad' )
12+
end
13+
14+
def self.for_iphone_app( app_path, sdk = nil )
15+
self.new( app_path, sdk, 'iphone' )
16+
end
17+
18+
def launch
19+
if @device_type_identifier.to_s != ''
20+
SimLauncher::Simulator.new.launch_ios_app_with_device_identifier(@app_path, @sdk, @device_type_identifier)
21+
else
22+
SimLauncher::Simulator.new.launch_ios_app( @app_path, @sdk, @family, @device_type_identifier)
23+
end
24+
25+
end
26+
27+
def rotate_left
28+
simulator = SimLauncher::Simulator.new
29+
simulator.rotate_left
30+
end
31+
32+
def rotate_right
33+
simulator = SimLauncher::Simulator.new
34+
simulator.rotate_right
35+
end
36+
37+
38+
39+
def relaunch
40+
simulator = SimLauncher::Simulator.new
41+
simulator.quit_simulator
42+
launch
43+
end
44+
end
3945
end

lib/sim_launcher/simulator.rb

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,29 @@ def reset(sdks=nil)
4545

4646
end
4747

48+
def launch_ios_app_with_device_identifier(app_path, sdk_version, device_identifier, app_args=nil)
49+
if problem = SimLauncher.check_app_path(app_path)
50+
bangs = '!'*80
51+
raise "\n#{bangs}\nENCOUNTERED A PROBLEM WITH THE SPECIFIED APP PATH:\n\n#{problem}\n#{bangs}"
52+
end
53+
54+
sdk_version ||= SdkDetector.new(self).latest_sdk_version
55+
56+
args = ["--args"] + app_args.flatten if app_args
57+
58+
run_synchronous_command( :launch, app_path, '--sdk', sdk_version, '--devicetypeid', device_identifier, '--exit', *args )
59+
end
60+
4861
def launch_ios_app(app_path, sdk_version, device_family, app_args = nil)
49-
if problem = SimLauncher.check_app_path( app_path )
50-
bangs = '!'*80
51-
raise "\n#{bangs}\nENCOUNTERED A PROBLEM WITH THE SPECIFIED APP PATH:\n\n#{problem}\n#{bangs}"
52-
end
53-
sdk_version ||= SdkDetector.new(self).latest_sdk_version
62+
if problem = SimLauncher.check_app_path(app_path)
63+
bangs = '!'*80
64+
raise "\n#{bangs}\nENCOUNTERED A PROBLEM WITH THE SPECIFIED APP PATH:\n\n#{problem}\n#{bangs}"
65+
end
66+
67+
sdk_version ||= SdkDetector.new(self).latest_sdk_version
68+
5469
args = ["--args"] + app_args.flatten if app_args
70+
5571
run_synchronous_command( :launch, app_path, '--sdk', sdk_version, '--family', device_family, '--exit', *args )
5672
end
5773

lib/sim_launcher/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module SimLauncher
2-
VERSION = "0.4.11"
2+
VERSION = "0.4.12"
33
end

0 commit comments

Comments
 (0)