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