Class: RunLoop::LifeCycle::CoreSimulator
- Inherits:
-
Simulator
- Object
- Simulator
- RunLoop::LifeCycle::CoreSimulator
- Defined in:
- lib/run_loop/life_cycle/core_simulator.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#sim_control ⇒ Object
readonly
Returns the value of attribute sim_control.
Instance Method Summary collapse
-
#app_documents_dir ⇒ Object
The Documents directory in the sandbox.
-
#app_is_installed? ⇒ Boolean
Is this app installed?.
-
#app_library_dir ⇒ Object
The Library directory in the sandbox.
-
#app_library_preferences_dir ⇒ Object
The Library/Preferences directory in the sandbox.
-
#app_sandbox_dir ⇒ Object
The sandbox directory for the app.
-
#app_tmp_dir ⇒ Object
The tmp directory in the sandbox.
-
#device_applications_dir ⇒ Object
The applications directory for the device.
-
#device_data_dir ⇒ Object
The data directory for the the device.
-
#initialize(app, device, sim_control = RunLoop::SimControl.new) ⇒ CoreSimulator
constructor
A new instance of CoreSimulator.
-
#install ⇒ Object
Install the app on the device.
-
#installed_app_sha1 ⇒ Object
The sha1 of the installed app.
-
#launch_simulator ⇒ Object
Launch simulator without specifying an app.
-
#reset_app_sandbox ⇒ Object
Reset app sandbox.
-
#same_sha1_as_installed? ⇒ Boolean
Is the app that is install the same as the one we have in hand?.
-
#uninstall ⇒ Object
Uninstall the app on the device.
Constructor Details
#initialize(app, device, sim_control = RunLoop::SimControl.new) ⇒ CoreSimulator
Returns a new instance of CoreSimulator.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 41 def initialize(app, device, sim_control=RunLoop::SimControl.new) @app = app @device = device @sim_control = sim_control # In order to manage the app on the device, we need to manage the # CoreSimulator processes. RunLoop::SimControl.terminate_all_sims terminate_core_simulator_processes end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
34 35 36 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 34 def app @app end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
35 36 37 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 35 def device @device end |
#sim_control ⇒ Object (readonly)
Returns the value of attribute sim_control.
36 37 38 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 36 def sim_control @sim_control end |
Instance Method Details
#app_documents_dir ⇒ Object
The Documents directory in the sandbox.
143 144 145 146 147 148 149 150 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 143 def app_documents_dir base_dir = app_sandbox_dir if base_dir.nil? nil else File.join(base_dir, 'Documents') end end |
#app_is_installed? ⇒ Boolean
Is this app installed?
163 164 165 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 163 def app_is_installed? !installed_app_bundle_dir.nil? end |
#app_library_dir ⇒ Object
The Library directory in the sandbox.
123 124 125 126 127 128 129 130 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 123 def app_library_dir base_dir = app_sandbox_dir if base_dir.nil? nil else File.join(base_dir, 'Library') end end |
#app_library_preferences_dir ⇒ Object
The Library/Preferences directory in the sandbox.
133 134 135 136 137 138 139 140 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 133 def app_library_preferences_dir base_dir = app_library_dir if base_dir.nil? nil else File.join(base_dir, 'Preferences') end end |
#app_sandbox_dir ⇒ Object
The sandbox directory for the app.
~/Library/Developer/CoreSimulator/Devices/<UDID>/Containers/Data/Application
Contains Library, Documents, and tmp directories.
112 113 114 115 116 117 118 119 120 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 112 def app_sandbox_dir app_install_dir = installed_app_bundle_dir return nil if app_install_dir.nil? if sdk_gte_8? app_sandbox_dir_sdk_gte_8 else app_install_dir end end |
#app_tmp_dir ⇒ Object
The tmp directory in the sandbox.
153 154 155 156 157 158 159 160 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 153 def app_tmp_dir base_dir = app_sandbox_dir if base_dir.nil? nil else File.join(base_dir, 'tmp') end end |
#device_applications_dir ⇒ Object
The applications directory for the device.
~/Library/Developer/CoreSimulator/Devices/<UDID>/Containers/Bundle/Application
97 98 99 100 101 102 103 104 105 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 97 def device_applications_dir @device_app_dir ||= lambda do if sdk_gte_8? File.join(device_data_dir, 'Containers', 'Bundle', 'Application') else File.join(device_data_dir, 'Applications') end end.call end |
#device_data_dir ⇒ Object
The data directory for the the device.
~/Library/Developer/CoreSimulator/Devices/<UDID>/data
90 91 92 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 90 def device_data_dir @device_data_dir ||= File.join(CORE_SIMULATOR_DEVICE_DIR, device.udid, 'data') end |
#install ⇒ Object
Install the app on the device.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 208 def install installed_app_bundle = installed_app_bundle_dir # App is not installed. return install_new_app if installed_app_bundle.nil? # App is installed but sha1 is different. if !same_sha1_as_installed? return reinstall_existing_app_and_clear_sandbox(installed_app_bundle) end RunLoop.log_debug('The installed app is the same as the app we are trying to install; skipping installation') installed_app_bundle end |
#installed_app_sha1 ⇒ Object
The sha1 of the installed app.
168 169 170 171 172 173 174 175 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 168 def installed_app_sha1 installed_bundle = installed_app_bundle_dir if installed_bundle RunLoop::Directory.directory_digest(installed_bundle) else nil end end |
#launch_simulator ⇒ Object
Launch simulator without specifying an app.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 53 def launch_simulator sim_path = sim_control.send(:sim_app_path) args = ['open', '-g', '-a', sim_path, '--args', '-CurrentDeviceUDID', device.udid] RunLoop.log_debug("Launching #{device} with:") RunLoop.log_unix_cmd("xcrun #{args.join(' ')}") start_time = Time.now pid = spawn('xcrun', *args) Process.detach(pid) sim_name = sim_control.send(:sim_name) RunLoop::ProcessWaiter.new(sim_name, WAIT_FOR_SIMULATOR_PROCESSES_OPTS).wait_for_any device.simulator_wait_for_stable_state elapsed = Time.now - start_time RunLoop.log_debug("Took #{elapsed} seconds to launch the simulator") true end |
#reset_app_sandbox ⇒ Object
Reset app sandbox.
270 271 272 273 274 275 276 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 270 def reset_app_sandbox return true if !app_is_installed? wait_for_device_state('Shutdown') reset_app_sandbox_internal end |
#same_sha1_as_installed? ⇒ Boolean
Is the app that is install the same as the one we have in hand?
178 179 180 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 178 def same_sha1_as_installed? app.sha1 == installed_app_sha1 end |
#uninstall ⇒ Object
Uninstall the app on the device.
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 196 def uninstall installed_app_bundle = installed_app_bundle_dir if installed_app_bundle uninstall_app_and_sandbox(installed_app_bundle) :uninstalled else RunLoop.log_debug('App was not installed. Nothing to do') :not_installed end end |