Class: RunLoop::CLI::Simctl

Inherits:
Thor
  • Object
show all
Defined in:
lib/run_loop/cli/simctl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#sim_controlObject (readonly)

Returns the value of attribute sim_control.



9
10
11
# File 'lib/run_loop/cli/simctl.rb', line 9

def sim_control
  @sim_control
end

Instance Method Details

#bootedObject



25
26
27
28
29
30
31
32
# File 'lib/run_loop/cli/simctl.rb', line 25

def booted
  device = booted_device
  if device.nil?
    puts 'No simulator is booted.'
  else
    puts device
  end
end

#installObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/run_loop/cli/simctl.rb', line 105

def install
  debug = options[:debug]

  if debug
    ENV['DEBUG'] = '1'
  end

  debug_logging = RunLoop::Environment.debug?

  device = expect_device(options)
  app = expect_app(options, device)

  bridge = RunLoop::Simctl::Bridge.new(device, app.path)

  force_reinstall = options[:force]

  before = Time.now

  if bridge.app_is_installed?
    if debug_logging
      puts "App with bundle id '#{app.bundle_identifier}' is already installed."
    end

    if force_reinstall
      if debug_logging
        puts 'Will force a re-install.'
      end
      bridge.uninstall
      bridge.install
    else
      new_digest = RunLoop::Directory.directory_digest(app.path)
      if debug_logging
        puts "      New app has SHA: '#{new_digest}'."
      end
      installed_app_bundle = bridge.fetch_app_dir
      old_digest = RunLoop::Directory.directory_digest(installed_app_bundle)
      if debug_logging
        puts "Installed app has SHA: '#{old_digest}'."
      end
      if new_digest != old_digest
        if debug_logging
          puts "Will re-install '#{app.bundle_identifier}' because the SHAs don't match."
        end
        bridge.uninstall
        bridge.install
      else
        if debug_logging
          puts "Will not re-install '#{app.bundle_identifier}' because the SHAs match."
        end
      end
    end
  else
    bridge.install
  end

  if debug_logging
    "Launching took #{Time.now-before} seconds"
    puts "Installed '#{app.bundle_identifier}' on #{device} in #{Time.now-before} seconds."
  end
end

#refreshObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/run_loop/cli/simctl.rb', line 43

def refresh
  debug = options[:debug]
  original_value = ENV['DEBUG']

  ENV['DEBUG'] = '1' if debug

  RunLoop::SimControl.terminate_all_sims

  begin
    process_name = 'com.apple.CoreSimulator.CoreSimulatorService'
    pids = RunLoop::ProcessWaiter.new(process_name, {:timeout => 0.2}).pids
    if debug && pids.empty?
      puts 'There are no CoreSimulatorServices processes running'
    end
    pids.each do |pid|
      RunLoop::ProcessTerminator.new(pid, 'KILL', process_name).kill_process
    end
  ensure
    ENV['DEBUG'] = original_value if debug
  end
end

#tailObject



12
13
14
# File 'lib/run_loop/cli/simctl.rb', line 12

def tail
  tail_booted
end