capa 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d579a95dcc1d51a4600ddf28c836abf623f962f2cc4ed98cd1f7b5398cedae5a
4
- data.tar.gz: 45ed656b945f4ef785cbf09f8b02301d4145e4d83f7662f38f1244bf440c018a
3
+ metadata.gz: dcbb3e889cb78cbd969f3ee5408f766f9f07b438fbc78d8b2558107b48ef8be2
4
+ data.tar.gz: 36a96e12f227e53f62154a6af9bbbc2a55dd5c7fd706e9c9ae2202ea129092e8
5
5
  SHA512:
6
- metadata.gz: 9db48acb31ecad6888422b6b50095da330d99bcc6df98b13522f18f3a1c75a541c90aec72fda48ac8cded7896d2f66d3cdcfee2d0dee92bece0c3f3515c019ec
7
- data.tar.gz: ed5de9f0717b8d75262fc9bd231342f4851d4ef9a03f7d0d5bfd01b181143c3281b7aca2d80eb1b946f303719a5c08cba4a3e0e72d77adbe9a75a3bc2044cd99
6
+ metadata.gz: 767b605ea8a0f401cf713ff78a4740f26a9aa87b1b1df48b22e8f1457c7d1ac0d925a72109b191cadf54bffee2198571112cf486c1546c0df6c23d4d98e557c0
7
+ data.tar.gz: 302cb2dac22680d9abfee0c7dacb32b2d35a3252613ba91ba08527739a2654ae1e92edf2804436be998b51da15280e439b07a751d0358f266a7966f466362377
@@ -2,17 +2,18 @@
2
2
 
3
3
  require_relative '../lib/capa'
4
4
 
5
- abort('Please install adb') unless command?('adb')
5
+ abort('Please install adb https://developer.android.com/studio/') unless command?('adb')
6
6
  abort('Please install gifify: https://github.com/vvo/gifify') unless command?('gifify')
7
7
 
8
8
  recorder = EmulatorRecorder.new(filename: @video_filename)
9
9
  generator = GIFGenerator.new(input_video: @video_filename, output_gif: "#{@video_filename}.gif")
10
10
 
11
- Signal.trap("SIGINT") do
12
- recorder.stop
13
- recorder.pull_video_from_emulator
14
- generator.generate
15
- exit 0
11
+ begin
12
+ recorder.record
13
+ rescue Capa::UserAbort
14
+ puts 'Exiting...'
15
+ `adb shell killall screenrecord`
16
+ exit
16
17
  end
17
18
 
18
- video = recorder.record
19
+ generator.generate
@@ -2,18 +2,19 @@
2
2
 
3
3
  require_relative '../lib/capa'
4
4
 
5
- def command?(command)
6
- system("which #{command} > /dev/null 2>&1")
7
- end
8
-
9
5
  abort('Please install gifify: https://github.com/vvo/gifify') unless command?('gifify')
10
6
 
11
7
  recorder = SimulatorRecorder.new(filename: @video_filename)
8
+ generator = GIFGenerator.new(input_video: @video_filename, output_gif: "#{@video_filename}.gif")
12
9
 
13
- Signal.trap("SIGINT") do
14
- generator = GIFGenerator.new(input_video: @video_filename, output_gif: "#{@video_filename}.gif")
15
- generator.generate
10
+ begin
11
+ recorder.record
12
+ rescue Capa::UserAbort
13
+ puts 'Exiting...'
14
+ if system('pgrep simctl > /dev/null')
15
+ `killall simctl`
16
+ end
17
+ exit
16
18
  end
17
19
 
18
-
19
- recorder.record
20
+ generator.generate
@@ -18,7 +18,7 @@ optparse = OptionParser.new do |opts|
18
18
  usage = "Usage: #{$0} [options]".bold
19
19
  opts.banner = "#{explanation} #{usage}"
20
20
 
21
- opts.on( '-o', '--output NAME', "Output filename. GIF file will get '.gif' added as suffix. Defaults to recording.mp4 and recording.mp4.gif" ) do |o|
21
+ opts.on( '-o', '--output NAME', "Output filename. Defaults to 'recording'" ) do |o|
22
22
  options[:output] = o
23
23
  end
24
24
 
@@ -36,4 +36,4 @@ end
36
36
  # The parse! method also removes any options it finds from ARGV.
37
37
  optparse.parse!
38
38
 
39
- @video_filename = options[:output] || 'recording.mp4'
39
+ @video_filename = "#{options[:output] || 'recording'}.mp4"
@@ -1,4 +1,5 @@
1
1
  require_relative 'string'
2
+ require_relative 'helper'
2
3
 
3
4
  class EmulatorRecorder
4
5
  def initialize(filename: '')
@@ -8,18 +9,25 @@ class EmulatorRecorder
8
9
 
9
10
  def record
10
11
  abort("You need exactly one emulator or device connected") unless can_record?
11
- puts 'Capturing video... Use CTRL+C to save'
12
- # Might want to add '--size 720x1280' flag. That's the maximum permitted size for video recordings
13
- # We can specify the device, in case there is more than one connected: -s emulator-5554
14
- message = `adb shell screenrecord --verbose #{emulator_video_path}`
15
12
 
16
- abort("Maximum permitted resolution is 720x1280. Minimum Android version is Marshmallow.\n"\
17
- "Please choose a different device.\n"\
18
- "Tip: Galaxy Nexus works great!") if /err=-38/ =~ message
19
- end
13
+ Signal.trap("SIGINT") { raise Capa::UserAbort }
14
+ Signal.trap("SIGTSTP") { raise Capa::UserAbort }
15
+
16
+ Thread.new do
17
+ # Might want to add '--size 720x1280' flag. That's the maximum permitted size for video recordings
18
+ # We can specify the device, in case there is more than one connected: -s emulator-5554
19
+ message = `adb shell screenrecord --verbose #{emulator_video_path}`
20
+
21
+ abort("Maximum permitted resolution is 720x1280. Minimum Android version is Marshmallow.\n"\
22
+ "Please choose a different device.\n"\
23
+ "Tip: Galaxy Nexus works great!") if /err=-38/ =~ message
24
+ end
20
25
 
21
- def stop
22
- `killall -SIGINT adb`
26
+ puts 'Capturing video... Press ENTER to save'
27
+ p = gets.chomp
28
+ `adb shell killall -SIGINT screenrecord`
29
+ sleep 0.5
30
+ pull_video_from_emulator
23
31
  end
24
32
 
25
33
  def pull_video_from_emulator
@@ -1,3 +1,7 @@
1
+ module Capa
2
+ class UserAbort < StandardError; end
3
+ end
4
+
1
5
 
2
6
  def command?(command)
3
7
  system("which #{command} > /dev/null 2>&1")
@@ -8,14 +8,17 @@ class SimulatorRecorder
8
8
 
9
9
  def record
10
10
  abort unless can_record?
11
- puts 'Capturing video... Use CTRL+C to save'
12
11
 
13
- job = fork do
14
- exec("xcrun simctl io booted recordVideo #{@filename}")
12
+ Signal.trap("SIGINT") { raise Capa::UserAbort }
13
+ Signal.trap("SIGTSTP") { raise Capa::UserAbort }
14
+
15
+ Thread.new do
16
+ `xcrun simctl io booted recordVideo #{@filename}`
15
17
  end
16
18
 
17
- Process.detach(job)
18
- Process.waitall
19
+ puts 'Capturing video... Press ENTER to save'
20
+ p = gets.chomp
21
+ `killall -SIGINT simctl`
19
22
  end
20
23
 
21
24
  private
@@ -1,3 +1,3 @@
1
1
  module Capa
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Salom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-16 00:00:00.000000000 Z
11
+ date: 2018-10-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: capa can record animated GIFs (and videos) from the iOS Simulator and
14
14
  the Android Emulator because a GIF is worth a thousand lines of code.