2016-02-13 12:29:53 -06:00
|
|
|
class MetadataController < ApplicationController
|
2015-09-20 10:00:30 -05:00
|
|
|
layout false
|
2017-08-30 23:06:56 -05:00
|
|
|
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required
|
2015-09-20 10:00:30 -05:00
|
|
|
|
2016-02-13 12:29:53 -06:00
|
|
|
def manifest
|
2018-06-13 22:13:28 -05:00
|
|
|
render json: default_manifest.to_json, content_type: 'application/manifest+json'
|
2016-06-29 23:03:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def opensearch
|
|
|
|
render file: "#{Rails.root}/app/views/metadata/opensearch.xml"
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def default_manifest
|
2017-11-03 00:19:31 -05:00
|
|
|
logo = SiteSetting.large_icon_url.presence || SiteSetting.logo_small_url.presence || SiteSetting.apple_touch_icon_url.presence
|
2018-05-21 21:10:59 -05:00
|
|
|
if !logo
|
|
|
|
logo = path('/images/d-logo-sketch-small.png')
|
|
|
|
end
|
2018-05-17 16:43:22 -05:00
|
|
|
file_info = get_file_info(logo)
|
2017-10-31 22:51:51 -05:00
|
|
|
|
2018-08-15 21:36:08 -05:00
|
|
|
display = request.user_agent =~ /iPad|iPhone/ ? 'browser' : 'standalone'
|
|
|
|
|
2017-01-03 11:50:45 -06:00
|
|
|
manifest = {
|
2016-04-20 09:54:01 -05:00
|
|
|
name: SiteSetting.title,
|
2015-09-20 10:00:30 -05:00
|
|
|
short_name: SiteSetting.title,
|
2018-08-15 21:36:08 -05:00
|
|
|
display: display,
|
2018-06-13 22:13:28 -05:00
|
|
|
orientation: 'any',
|
2018-06-15 12:29:33 -05:00
|
|
|
start_url: Discourse.base_uri.present? ? "#{Discourse.base_uri}/" : '.',
|
2016-03-20 21:18:40 -05:00
|
|
|
background_color: "##{ColorScheme.hex_for_name('secondary')}",
|
2016-04-20 09:54:01 -05:00
|
|
|
theme_color: "##{ColorScheme.hex_for_name('header_background')}",
|
|
|
|
icons: [
|
|
|
|
{
|
2017-10-31 22:51:51 -05:00
|
|
|
src: logo,
|
2018-05-17 16:43:22 -05:00
|
|
|
sizes: file_info[:size],
|
|
|
|
type: file_info[:type]
|
2016-04-20 09:54:01 -05:00
|
|
|
}
|
|
|
|
]
|
2015-09-20 10:00:30 -05:00
|
|
|
}
|
2017-01-03 11:50:45 -06:00
|
|
|
|
|
|
|
if SiteSetting.native_app_install_banner
|
2017-07-27 20:20:09 -05:00
|
|
|
manifest = manifest.merge(
|
2017-01-03 11:50:45 -06:00
|
|
|
prefer_related_applications: true,
|
|
|
|
related_applications: [
|
|
|
|
{
|
|
|
|
platform: "play",
|
|
|
|
id: "com.discourse"
|
|
|
|
}
|
|
|
|
]
|
2017-07-27 20:20:09 -05:00
|
|
|
)
|
2017-01-03 11:50:45 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
manifest
|
2016-02-13 12:29:53 -06:00
|
|
|
end
|
2018-05-17 14:10:35 -05:00
|
|
|
|
2018-05-17 16:43:22 -05:00
|
|
|
def get_file_info(filename)
|
|
|
|
type = MiniMime.lookup_by_filename(filename)&.content_type || "image/png"
|
|
|
|
upload = Upload.find_by_url(filename)
|
|
|
|
{ size: "#{upload&.width || 512}x#{upload&.height || 512}", type: type }
|
2018-05-17 14:10:35 -05:00
|
|
|
end
|
|
|
|
|
2015-09-20 10:00:30 -05:00
|
|
|
end
|