motion-launchimages 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a011eb95f543bac37beccf3bf70cf10c5668df0
4
- data.tar.gz: efabfc1d2b75fd98d9535021240052d2cd89ca24
3
+ metadata.gz: 18fd80f96feb03a295a41dccf527d33c515c44d8
4
+ data.tar.gz: 8113afad181ea88a96c9c56357867ca919599425
5
5
  SHA512:
6
- metadata.gz: f571a451be42262a1bb6319095b20d958fab480965caa97fa41e909be84780d1f1573e3acb234cfe9fe0d5f4f14d6adf9c5b02db02bc0ab4743cb0ea7c3e3f4a
7
- data.tar.gz: dbc5e4804244f82e52afad693b8a738d67d363c4bd878fcd79a65590feca913b155de8befc2ea12eacd6bd84d4550274192e46c9760c53eab7bdd7d14dddaabf
6
+ metadata.gz: 56f30c0af3314fbd3e5fb96f1fd8637a91e4cbbf0d0bf118a97f22c4f01a0bcc4e57ca12bedf54eae43d264cccb562fd4cdca6a2eb750661467b924533868e77
7
+ data.tar.gz: 52833c69cb4fdf6cbd378e6ad1a5396ab769b87a8ed8ac7fa72efd0be5593124460891b05bdcf0f05a843fe53258753af2cf1be6c76041711aa16dc4197473d9
data/README.md CHANGED
@@ -43,10 +43,10 @@ end
43
43
 
44
44
  ## Running
45
45
 
46
- Just run `rake launchimages`! The task will launch your app in the simulator several times with different screen sizes and save the screenshots in your resources directory with the correct names. It detects whether it's being run on an iPhone or iPad (or both) app and only takes the screenshots it needs to.
46
+ Just run `rake launchimages`. The task will launch your app in the simulator several times with different screen sizes and save the screenshots in your resources directory with the correct names. It detects whether it's being run on an iPhone or iPad (or both) app and only takes the screenshots it needs to.
47
47
 
48
- If you want to just take the screenshot at one resolution, you can run `rake take_launchimages=true device_name="iPhone 6 Plus"` (for example). Any of the iPhone or iPad devices should work. You can get a full list of what's available by opening the simulator, going to the `Hardware` menu and looking under `Device`.
48
+ If you want to just take the screenshot for one device, you can run `rake take_launchimages=true device_name="iPhone 8 Plus"` (for example). See [devices.rb](lib/motion/devices.rb) for a list of acceptable values for `device_name`.
49
49
 
50
- ## Contact
50
+ ### Hybrid Apps
51
51
 
52
- [Brendan J. Caffrey](http://brendan.jcaffrey.com/)
52
+ If you have a hybrid app (iPhone and iPad), you may want to split up the launch image generation into two steps by running `rake launchimages type="ipad"`, closing all open simulators when it's done, then `rake launchimages type="iphone"` after. There seems to be some sort of limit on the number of simulators that can be open at once, and the `rake` command hangs when the limit is hit.
@@ -1,36 +1,72 @@
1
1
  require 'open3'
2
+ require_relative 'motion/devices.rb'
2
3
 
3
4
  unless defined?(Motion::Project::Config)
4
5
  raise 'This file must be required within a RubyMotion project Rakefile.'
5
6
  end
6
7
 
8
+ def get_screenshot_path
9
+ Dir.pwd + '/resources/'
10
+ end
11
+
7
12
  Motion::Project::App.setup do |app|
8
13
  Dir.glob(File.join(File.dirname(__FILE__), 'motion/*.rb')).each do |file|
9
14
  app.files.unshift(file)
10
15
 
11
16
  if ENV.has_key?('take_launchimages')
12
- app.info_plist['screenshot_path'] = Dir.pwd + '/resources/'
17
+ app.info_plist['screenshot_path'] = get_screenshot_path
18
+
19
+ if !ENV.has_key?('device_name')
20
+ puts "The device_name environment key must be specified to motion-launchimages to run"
21
+ exit
22
+ end
23
+ app.info_plist['device_name'] = ENV['device_name']
24
+
25
+ # this is done both in the `rake launchimages` process and the `rake` process because this can be ran directly
26
+ # and errors don't propogate up to the parent process (which is something that should probably be fixed)
27
+ Motion::LaunchImages.get_device(ENV['device_name']).check_screenshots_exists
28
+ end
29
+ end
30
+ end
31
+
32
+ class Device
33
+ def filepath(orientation)
34
+ "#{get_screenshot_path}#{filename(orientation)}"
35
+ end
36
+
37
+ def check_screenshots_exists
38
+ check_screenshot_exists(:portrait)
39
+ check_screenshot_exists(:landscape) if landscape
40
+ end
41
+
42
+ private
43
+
44
+ def check_screenshot_exists(orientation)
45
+ if !File.exists?(filepath(orientation))
46
+ puts "Error: Please make sure #{filepath(orientation)} exists before running. The app will not launch with the correct screensize otherwise."
47
+ puts "You should be able to download an example one at https://github.com/brendanjcaffrey/motion-launchimages/tree/master/sample/resources/#{filename(orientation)}"
48
+ exit
13
49
  end
14
50
  end
15
51
  end
16
52
 
17
53
  desc 'Take launch images of your app at all display resolutions'
18
54
  task :launchimages do
19
- devices = []
20
55
  family = Motion::Project::App.config.device_family
21
56
  family = [family] if family.is_a?(Symbol)
22
57
 
23
- if family.index(:iphone) != nil
24
- devices << 'iPhone 4s' << 'iPhone 5s' << 'iPhone 6' << 'iPhone 6 Plus'
25
- end
58
+ family -= [:iphone] if ENV['type'].to_s.downcase == 'ipad'
59
+ family -= [:ipad] if ENV['type'].to_s.downcase == 'iphone'
26
60
 
27
- if family.index(:ipad) != nil
28
- devices << 'iPad 2' << 'iPad Air'
29
- end
61
+ devices = {}
62
+ devices.merge!(Motion::LaunchImages.iphones) if family.index(:iphone) != nil
63
+ devices.merge!(Motion::LaunchImages.ipads) if family.index(:ipad) != nil
64
+
65
+ devices.each do |device_name, device_specs|
66
+ device_specs.check_screenshots_exists
30
67
 
31
- devices.each do |device|
32
- puts "Taking screenshot on #{device}"
33
- Open3.popen3({'take_launchimages' => 'true', 'device_name' => device}, 'rake') do |i, o, e, s|
68
+ puts "Taking screenshot on #{device_name}"
69
+ Open3.popen3({'take_launchimages' => 'true', 'device_name' => device_name}, 'rake') do |i, o, e, s|
34
70
  o.read
35
71
  end
36
72
  end
@@ -0,0 +1,66 @@
1
+ module Motion
2
+ Device = Struct.new(:width, :height, :scale, :landscape, :no_height_label) do
3
+ def filename(orientation)
4
+ if orientation == :portrait
5
+ size_measurement = height/scale
6
+ orientation_label = landscape ? '-Portrait' : ''
7
+ elsif orientation == :landscape
8
+ size_measurement = width/scale
9
+ orientation_label = '-Landscape'
10
+ end
11
+ size_label = no_height_label ? '' : "-#{size_measurement}h"
12
+
13
+ "Default#{orientation_label}#{size_label}@#{scale}x.png"
14
+ end
15
+
16
+ def filepath(orientation)
17
+ "#{get_screenshot_path}#{filename(orientation)}"
18
+ end
19
+
20
+ def check_screenshots_exists
21
+ check_screenshot_exists(:portrait)
22
+ check_screenshot_exists(:landscape) if landscape
23
+ end
24
+
25
+ private
26
+
27
+ def check_screenshot_exists(orientation)
28
+ if !File.exists?(filepath(orientation))
29
+ puts "Error: Please make sure #{filepath(orientation)} exists before running. The app will not launch with the correct screensize otherwise."
30
+ puts "You should be able to download an example one at https://github.com/brendanjcaffrey/motion-launchimages/tree/master/sample/resources/#{filename(orientation)}"
31
+ exit
32
+ end
33
+ end
34
+ end
35
+
36
+ class LaunchImages
37
+ def self.iphones
38
+ {
39
+ 'iPhone SE' => Device.new(640, 1136, 2, false, false), # also iPhone 5s
40
+ 'iPhone 8' => Device.new(750, 1334, 2, false, false), # also iPhone 6/7
41
+ 'iPhone 8 Plus' => Device.new(1242, 2208, 3, false, false), # also iPhone 6/7 Plus
42
+ 'iPhone X' => Device.new(1125, 2436, 3, false, false),
43
+ }
44
+ end
45
+
46
+ def self.ipads
47
+ {
48
+ 'iPad Pro (9.7-inch)' => Device.new(1536, 2048, 2, true, true),
49
+ 'iPad Pro (10.5-inch)' => Device.new(1668, 2224, 2, true, false),
50
+ 'iPad Pro (12.9-inch)' => Device.new(2048, 2732, 2, true, false),
51
+ }
52
+ end
53
+
54
+ def self.get_device(name)
55
+ if iphones.has_key?(name)
56
+ iphones[name]
57
+ elsif ipads.has_key?(name)
58
+ ipads[name]
59
+ else
60
+ puts "Unable to find device #{name}"
61
+ exit
62
+ end
63
+ end
64
+ end
65
+ end
66
+
@@ -4,6 +4,10 @@ module Motion
4
4
  NSBundle.mainBundle.objectForInfoDictionaryKey('screenshot_path')
5
5
  end
6
6
 
7
+ def self.device_name
8
+ NSBundle.mainBundle.objectForInfoDictionaryKey('device_name')
9
+ end
10
+
7
11
  def self.taking?
8
12
  screenshot_path != nil
9
13
  end
@@ -17,35 +21,30 @@ module Motion
17
21
  sleep 1.0
18
22
  end
19
23
 
20
- Dispatch::Queue.main.async { capture! }
24
+ Dispatch::Queue.main.async { capture!(orientation) }
21
25
  end
22
26
  end
23
27
 
24
- def self.capture!
28
+ def self.capture!(orientation)
29
+ # sanity check the device values
25
30
  screen = UIScreen.mainScreen
26
- height = screen.bounds.size.height
27
- scale = begin
28
- if !screen.respondsToSelector('displayLinkWithTarget:selector:')
29
- ''
30
- elsif screen.scale == 1.0
31
- ''
32
- elsif screen.scale == 2.0
33
- '@2x'
34
- elsif screen.scale == 3.0
35
- '@3x'
36
- else
37
- puts 'Error: Unable to determine screen scale'
38
- exit
39
- end
31
+ height = screen.bounds.size.height.to_i
32
+ scale = screen.respondsToSelector('displayLinkWithTarget:selector:') ? screen.scale.to_i : 1
33
+ device = get_device(device_name)
34
+ expected_height = (orientation == :portrait ? device.height : device.width) / device.scale
35
+
36
+ if expected_height != height || device.scale != scale
37
+ puts "In #{orientation.to_s}, height was expected to be #{expected_height} but was #{height} and/or scale was expected to be #{device.scale} but was #{scale}"
38
+ exit
40
39
  end
41
- filename = generate_filename(height, scale)
42
40
 
43
- if scale != ''
41
+ if scale > 1
44
42
  UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, screen.scale)
45
- else
43
+ else # TODO not sure if this is necessary anymore?
46
44
  UIGraphicsBeginImageContext(window.bounds.size)
47
45
  end
48
46
 
47
+ filename = screenshot_path + device.filename(orientation)
49
48
  window.layer.renderInContext(UIGraphicsGetCurrentContext())
50
49
  image = UIGraphicsGetImageFromCurrentImageContext()
51
50
  UIGraphicsEndImageContext()
@@ -53,36 +52,13 @@ module Motion
53
52
  data.writeToFile(filename, atomically:true)
54
53
  puts "Wrote to #{filename}"
55
54
 
56
- if should_rotate_and_take_again?(height)
55
+ if orientation == :portrait && device.landscape
57
56
  take!(:landscape)
58
57
  else
59
58
  exit
60
59
  end
61
60
  end
62
61
 
63
- def self.generate_filename(height, scale)
64
- filename = screenshot_path + 'Default'
65
-
66
- case height
67
- when 480 # iPhone 4s
68
- when 568 # iPhone 5s
69
- filename << '-568h'
70
- when 667 # iPhone 6
71
- filename << '-667h'
72
- when 736 # iPhone 6 Plus
73
- filename << '-736h'
74
- when 768 # iPad (Landscape)
75
- filename << '-Landscape'
76
- when 1024 # iPad (Portrait)
77
- filename << '-Portrait'
78
- else
79
- puts "Error: Invalid screen height #{height}"
80
- exit
81
- end
82
-
83
- filename << scale << '.png'
84
- end
85
-
86
62
  # ported from BubbleWrap to reduce dependencies
87
63
  def self.window
88
64
  normal_windows = UIApplication.sharedApplication.windows.select { |w|
@@ -96,10 +72,6 @@ module Motion
96
72
  key_window || normal_windows.first
97
73
  end
98
74
 
99
- def self.should_rotate_and_take_again?(height)
100
- height == 1024 # iPad (Portrait)
101
- end
102
-
103
75
  def self.rotate(to)
104
76
  if to == :portrait
105
77
  value = NSNumber.numberWithInt(UIInterfaceOrientationPortrait)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'motion-launchimages'
3
- s.version = '1.0.0'
3
+ s.version = '1.1.0'
4
4
  s.summary = 'Automate RubyMotion launch images'
5
5
  s.description = 'Automate RubyMotion launch images'
6
6
  s.homepage = 'https://github.com/brendanjcaffrey/motion-launchimages'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-launchimages
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan J. Caffrey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-15 00:00:00.000000000 Z
11
+ date: 2017-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -33,6 +33,7 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - README.md
35
35
  - lib/motion-launchimages.rb
36
+ - lib/motion/devices.rb
36
37
  - lib/motion/launch_images.rb
37
38
  - motion-launchimages.gemspec
38
39
  homepage: https://github.com/brendanjcaffrey/motion-launchimages
@@ -55,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
56
  version: '0'
56
57
  requirements: []
57
58
  rubyforge_project:
58
- rubygems_version: 2.4.5
59
+ rubygems_version: 2.6.8
59
60
  signing_key:
60
61
  specification_version: 4
61
62
  summary: Automate RubyMotion launch images