Skip to content

Commit 7681ff3

Browse files
committed
added shield_io_timeout variable, changed internal structure to not touch images if they will not be changed
1 parent e340016 commit 7681ff3

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

bin/badge

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ class BadgeApplication
3232
c.option '--custom STRING', String, 'Overlay a custom image on your icon'
3333
c.option '--no_badge', 'Removes the beta badge'
3434
c.option '--shield STRING', String, 'Overlay a shield from shield.io on your icon, eg: Version-1.2-green'
35-
c.option '--glob STRING', String, 'Glob pattern for finding image files'
35+
c.option '--shield_io_timeout INTEGER', Integer, 'The timeout in seconds we should wait the get a response from shield.io'
36+
c.option '--glob STRING', String, 'Glob pattern for finding image files Default: CURRENT_PATH/**/*.appiconset/*.{png,PNG}'
3637

3738
c.action do |args, options|
3839
params = {}
3940
params[:dark] = options.dark
4041
params[:custom] = options.custom
4142
params[:no_badge] = options.no_badge
4243
params[:shield] = options.shield
44+
params[:shield_io_timeout] = options.shield_io_timeout
4345
params[:alpha] = options.alpha
4446
params[:glob] = options.glob
4547
Badge::Runner.new.run('.', params)

lib/badge/runner.rb

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,48 @@ def run(path, options)
1818

1919
shield = nil
2020
begin
21-
Timeout.timeout(Badge.shield_io_timeout) do
21+
timeout = Badge.shield_io_timeout
22+
timeout = options[:shield_io_timeout] unless not options[:shield_io_timeout]
23+
Timeout.timeout(timeout.to_i) do
2224
shield = load_shield(options[:shield]) unless not options[:shield]
2325
end
2426
rescue Timeout::Error
2527
Helper.log.error "Error loading image from shield.io timeout reached. Skipping Shield. Use --verbose for more info".red
2628
end
2729

30+
icon_changed = false
2831
app_icons.each do |full_path|
29-
Helper.log.info "'#{full_path}'"
3032
icon_path = Pathname.new(full_path)
3133
icon = MiniMagick::Image.new(full_path)
3234

3335
result = MiniMagick::Image.new(full_path)
34-
result = add_badge(options[:custom], options[:dark], icon, options[:alpha]) unless options[:no_badge]
35-
36-
result = add_shield(icon, result, shield) unless not shield
37-
38-
result.format "png"
39-
result.write full_path
36+
37+
if !options[:no_badge]
38+
result = add_badge(options[:custom], options[:dark], icon, options[:alpha])
39+
icon_changed = true
40+
end
41+
if shield
42+
result = add_shield(icon, result, shield)
43+
icon_changed = true
44+
end
45+
46+
if icon_changed
47+
result.format "png"
48+
result.write full_path
49+
end
50+
end
51+
if icon_changed
52+
Helper.log.info "Badged \\o/!".green
53+
else
54+
Helper.log.info "Did nothing... Enable --verbose for more info.".red
4055
end
41-
42-
Helper.log.info "Badged \\o/!".green
4356
else
4457
Helper.log.error "Could not find any app icons...".red
4558
end
4659
end
4760

4861
def add_shield(icon, result, shield)
62+
Helper.log.info "'#{icon.path}'"
4963
Helper.log.info "Adding shield.io image ontop of icon".blue unless not $verbose
5064

5165
current_shield = MiniMagick::Image.open(shield.path)
@@ -71,6 +85,7 @@ def load_shield(shield_string)
7185
end
7286

7387
def add_badge(custom_badge, dark_badge, icon, alpha_badge)
88+
Helper.log.info "'#{icon.path}'"
7489
Helper.log.info "Adding badge image ontop of icon".blue unless not $verbose
7590
if custom_badge && File.exist?(custom_badge) # check if custom image is provided
7691
badge = MiniMagick::Image.open(custom_badge)

0 commit comments

Comments
 (0)