Class: RunLoop::LifeCycle::CoreSimulator
- Inherits:
-
Object
- Object
- 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.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 71 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.
64 65 66 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 64 def app @app end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
65 66 67 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 65 def device @device end |
#sim_control ⇒ Object (readonly)
Returns the value of attribute sim_control.
66 67 68 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 66 def sim_control @sim_control end |
Instance Method Details
#app_documents_dir ⇒ Object
The Documents directory in the sandbox.
173 174 175 176 177 178 179 180 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 173 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?
193 194 195 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 193 def app_is_installed? !installed_app_bundle_dir.nil? end |
#app_library_dir ⇒ Object
The Library 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_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.
163 164 165 166 167 168 169 170 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 163 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.
142 143 144 145 146 147 148 149 150 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 142 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.
183 184 185 186 187 188 189 190 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 183 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
127 128 129 130 131 132 133 134 135 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 127 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
120 121 122 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 120 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.
238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 238 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.
198 199 200 201 202 203 204 205 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 198 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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 83 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.
298 299 300 301 302 303 304 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 298 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?
208 209 210 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 208 def same_sha1_as_installed? app.sha1 == installed_app_sha1 end |
#uninstall ⇒ Object
Uninstall the app on the device.
226 227 228 229 230 231 232 233 234 235 |
# File 'lib/run_loop/life_cycle/core_simulator.rb', line 226 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 |