Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: allow large icon to be uploaded in wizard

Arpit Jalanaedc61a3b499
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index dbd3d8323ca..9214cc324dd 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -3843,7 +3843,7 @@ en:
description: "Icon image used to represent your site in web browsers that looks good at small sizes such as 32px by 32px."
apple_touch_icon_url:
label: "Large Icon"
- description: "Icon image used to represent your site on modern devices that looks good at larger sizes. Recommended size is at least 144px by 144px."
+ description: "Icon image used to represent your site on modern devices that looks good at larger sizes. Recommended size is at least 512px by 512px."
homepage:
description: "We recommend showing the latest topics on your homepage, but you can also show categories (groups of topics) on the homepage if you prefer."
diff --git a/lib/wizard/builder.rb b/lib/wizard/builder.rb
index 11a1e05d502..1c7a5bc1540 100644
--- a/lib/wizard/builder.rb
+++ b/lib/wizard/builder.rb
@@ -169,7 +169,25 @@ class Wizard
step.add_field(id: 'apple_touch_icon_url', type: 'image', value: SiteSetting.apple_touch_icon_url)
step.on_update do |updater|
- updater.apply_settings(:favicon_url, :apple_touch_icon_url)
+ updater.apply_settings(:favicon_url)
+
+ if updater.fields[:apple_touch_icon_url] != SiteSetting.apple_touch_icon_url
+ upload = Upload.find_by_url(updater.fields[:apple_touch_icon_url])
+ dimensions = 180 # for apple touch icon
+ if upload && upload.width > dimensions && upload.height > dimensions
+ updater.update_setting(:large_icon_url, updater.fields[:apple_touch_icon_url])
+
+ apple_touch_icon_optimized = OptimizedImage.create_for(upload, dimensions, dimensions, filename: upload.original_filename)
+ original_file = File.new(Discourse.store.path_for(apple_touch_icon_optimized)) rescue nil
+ if original_file
+ apple_touch_icon_upload = UploadCreator.new(original_file, upload.original_filename).create_for(@wizard.user.id)
+ updater.update_setting(:apple_touch_icon_url, apple_touch_icon_upload.url)
+ end
+ apple_touch_icon_optimized.destroy! if apple_touch_icon_optimized.present?
+ else
+ updater.apply_settings(:apple_touch_icon_url)
+ end
+ end
end
end
diff --git a/spec/components/wizard/step_updater_spec.rb b/spec/components/wizard/step_updater_spec.rb
index 36641ff96d8..b57d3000db3 100644
--- a/spec/components/wizard/step_updater_spec.rb
+++ b/spec/components/wizard/step_updater_spec.rb
@@ -237,6 +237,15 @@ describe Wizard::StepUpdater do
expect(SiteSetting.favicon_url).to eq('/uploads/favicon.png')
expect(SiteSetting.apple_touch_icon_url).to eq('/uploads/apple.png')
end
+
+ it "updates large_icon_url if the uploaded icon size is greater than 180x180" do
+ upload = Fabricate(:upload, width: 512, height: 512)
+ updater = wizard.create_updater('icons', apple_touch_icon_url: upload.url)
+ updater.update
+
+ expect(updater).to be_success
+ expect(SiteSetting.large_icon_url).to eq(upload.url)
+ end
end
context "emoji step" do