Class: SimulatorRecorder

Inherits:
Recorder show all
Defined in:
lib/capa/simulator_recorder.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename: '') ⇒ SimulatorRecorder

Returns a new instance of SimulatorRecorder.



5
6
7
8
# File 'lib/capa/simulator_recorder.rb', line 5

def initialize(filename: '')
  abort('Please provide a name for the video') if filename.blank?
  @filename = filename
end

Instance Method Details

#can_record?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'lib/capa/simulator_recorder.rb', line 31

def can_record?
  return false if command?('xcrun') == false
  # Will output 'No devices are booted.' if Simulator.app is closed
  `xcrun simctl io booted enumerate > /dev/null 2>&1`
  $?.exitstatus == 0
end

#cancelObject



25
26
27
28
29
# File 'lib/capa/simulator_recorder.rb', line 25

def cancel
  if system('pgrep simctl > /dev/null')
    `killall simctl`
  end
end

#recordObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/capa/simulator_recorder.rb', line 10

def record
  abort("You need to open the iOS Simulator") unless can_record?

  Signal.trap("SIGINT") { raise Capa::UserAbort }
  Signal.trap("SIGTSTP") { raise Capa::UserAbort }

  Thread.new do
    `xcrun simctl io booted recordVideo #{@filename}`
  end

  puts 'Capturing video from the iOS Simulator... Press ENTER to save'
  p = gets.chomp
  `killall -SIGINT simctl`
end