[iOS/WatchKit] Add support for UILaunchImages from an asset catalog.

Fixes http://hipbyte.myjetbrains.com/youtrack/issue/RM-297
This commit is contained in:
Eloy Durán
2014-12-11 16:39:52 +01:00
parent 998793230b
commit d7b6f29e4f
4 changed files with 96 additions and 20 deletions

View File

@@ -547,13 +547,16 @@ EOS
if assets_bundles.empty?
[]
else
if config.respond_to?(:app_icons_asset_bundle)
app_icons_asset_bundle = config.app_icons_asset_bundle
app_icon_and_launch_image_options = ''
if config.respond_to?(:app_icons_asset_bundle) && bundle_name = config.app_icon_name_from_asset_bundle
app_icon_and_launch_image_options << " --app-icon '#{bundle_name}'"
end
if app_icons_asset_bundle
app_icons_info_plist_path = config.app_icons_info_plist_path(platform)
app_icons_options = "--output-partial-info-plist \"#{app_icons_info_plist_path}\" " \
"--app-icon \"#{config.app_icon_name_from_asset_bundle}\""
if config.respond_to?(:launch_images_asset_bundle) && bundle_name = config.launch_image_name_from_asset_bundle
app_icon_and_launch_image_options << " --launch-image '#{bundle_name}'"
end
unless app_icon_and_launch_image_options.empty?
partial_info_plist = config.asset_bundle_partial_info_plist_path(platform)
app_icon_and_launch_image_options << " --output-partial-info-plist '#{partial_info_plist}'"
end
App.info 'Compile', assets_bundles.join(", ")
@@ -563,7 +566,8 @@ EOS
"--notices --warnings --platform #{config.deploy_platform.downcase} " \
"--minimum-deployment-target #{config.deployment_target} " \
"#{Array(config.device_family).map { |d| "--target-device #{d}" }.join(' ')} " \
"#{app_icons_options} --compress-pngs --compile \"#{app_resources_dir}\" " \
"#{app_icon_and_launch_image_options} --compress-pngs " \
"--compile \"#{app_resources_dir}\" " \
"\"#{assets_bundles.map { |f| File.expand_path(f) }.join('" "')}\""
$stderr.puts(cmd) if App::VERBOSE
actool_output = `#{cmd} 2>&1`
@@ -577,10 +581,10 @@ EOS
actool_document_warnings.strip.split("\n").each { |w| App.warn(w) }
end
config.configure_app_icons_from_asset_bundle(platform) if app_icons_asset_bundle
# Remove the partial Info.plist line and return the produced resources.
actool_compiled_files.delete(app_icons_info_plist_path) if app_icons_asset_bundle
unless app_icon_and_launch_image_options.empty?
config.add_images_from_asset_bundles(platform)
actool_compiled_files.delete(partial_info_plist)
end
produced_resources = actool_compiled_files.map { |f| File.basename(f) }
end
end

View File

@@ -59,15 +59,55 @@ module Motion; module Project;
end
end
def app_icons_info_plist_path(platform)
File.expand_path(File.join(versionized_build_dir(platform), 'AppIcon.plist'))
# @return [String, nil] The path to the asset bundle that contains launch
# images, if any.
#
def launch_images_asset_bundle
launch_images_asset_bundles = assets_bundles.map { |b| Dir.glob(File.join(b, '*.launchimage')) }.flatten
if launch_images_asset_bundles.size > 1
App.warn "Found #{launch_images_asset_bundles.size} launch image sets across all " \
"xcasset bundles. Only the first one (alphabetically) will be used."
end
launch_images_asset_bundles.sort.first
end
def configure_app_icons_from_asset_bundle(platform)
path = app_icons_info_plist_path(platform)
if File.exist?(path)
content = `/usr/libexec/PlistBuddy -c 'Print :CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles' "#{path}"`.strip
self.icons = content.split("\n")[1..-2].map(&:strip)
# @return [String, nil] The name of the launch image set, without any
# extension.
#
def launch_image_name_from_asset_bundle
if bundle = launch_images_asset_bundle
File.basename(bundle, '.launchimage')
end
end
# Assigns the launch image information, found in the `Info.plist` generated
# by compiling the asset bundles, to the `info_plist`s `UILaunchImages`.
#
# @return [void]
#
def add_images_from_asset_bundles(platform)
super
if launch_images_asset_bundle
path = asset_bundle_partial_info_plist_path(platform)
if File.exist?(path)
content = `/usr/libexec/PlistBuddy -c 'Print :UILaunchImages' "#{path}"`.strip
images = []
current_image = nil
content.split("\n")[1..-2].each do |line|
case line.strip
when 'Dict {'
current_image = {}
when '}'
images << current_image
current_image = nil
when /(\w+) = (.+)/
current_image[$1] = $2
end
end
unless images.empty?
info_plist['UILaunchImages'] = images
end
end
end
end
@@ -400,7 +440,7 @@ module Motion; module Project;
def launch_images
if Util::Version.new(deployment_target) >= Util::Version.new('7')
images = resources_dirs.map do |dir|
Dir.glob(File.join(dir, 'Default*.png')).map do |file|
Dir.glob(File.join(dir, '{Default,LaunchImage}*.png')).map do |file|
launch_image_metadata(file)
end
end.flatten.compact

View File

@@ -495,6 +495,17 @@ EOS
xcassets_bundles
end
# @return [String] The path to the `Info.plist` file that gets generated by
# compiling the asset bundles and contains the data that should be
# merged into the final `Info.plist` file.
#
def asset_bundle_partial_info_plist_path(platform)
File.expand_path(File.join(versionized_build_dir(platform), 'AssetCatalog-Info.plist'))
end
# @return [String, nil] The path to the asset bundle that contains
# application icons, if any.
#
def app_icons_asset_bundle
app_icons_asset_bundles = assets_bundles.map { |b| Dir.glob(File.join(b, '*.appiconset')) }.flatten
if app_icons_asset_bundles.size > 1
@@ -505,8 +516,28 @@ EOS
app_icons_asset_bundles.sort.first
end
# @return [String, nil] The name of the application icon set, without any
# extension.
#
def app_icon_name_from_asset_bundle
File.basename(app_icons_asset_bundle, '.appiconset')
if bundle = app_icons_asset_bundle
File.basename(bundle, '.appiconset')
end
end
# Assigns the application icon information, found in the `Info.plist`
# generated by compiling the asset bundles, to the configurations `icons`.
#
# @return [void]
#
def add_images_from_asset_bundles(platform)
if app_icons_asset_bundle
path = asset_bundle_partial_info_plist_path(platform)
if File.exist?(path)
content = `/usr/libexec/PlistBuddy -c 'Print :CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles' "#{path}"`.strip
self.icons = content.split("\n")[1..-2].map(&:strip)
end
end
end
attr_reader :vendor_projects