2019-05-02 14:57:12 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-14 02:29:53 +08:00
|
|
|
class MetadataController < ApplicationController
|
2015-09-20 23:00:30 +08:00
|
|
|
layout false
|
2017-08-31 12:06:56 +08:00
|
|
|
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required
|
2015-09-20 23:00:30 +08:00
|
|
|
|
2016-02-14 02:29:53 +08:00
|
|
|
def manifest
|
2018-06-14 11:13:28 +08:00
|
|
|
render json: default_manifest.to_json, content_type: 'application/manifest+json'
|
2016-06-30 12:03:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def opensearch
|
2019-05-03 14:19:14 +08:00
|
|
|
render template: "metadata/opensearch.xml"
|
2016-06-30 12:03:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def default_manifest
|
2018-10-27 00:47:22 +08:00
|
|
|
display = Regexp.new(SiteSetting.pwa_display_browser_regex).match(request.user_agent) ? 'browser' : 'standalone'
|
2018-08-16 10:36:08 +08:00
|
|
|
|
2017-01-04 01:50:45 +08:00
|
|
|
manifest = {
|
2016-04-20 22:54:01 +08:00
|
|
|
name: SiteSetting.title,
|
2018-08-16 10:36:08 +08:00
|
|
|
display: display,
|
2018-06-16 01:29:33 +08:00
|
|
|
start_url: Discourse.base_uri.present? ? "#{Discourse.base_uri}/" : '.',
|
2018-09-12 09:04:58 +08:00
|
|
|
background_color: "##{ColorScheme.hex_for_name('secondary', view_context.scheme_id)}",
|
|
|
|
theme_color: "##{ColorScheme.hex_for_name('header_background', view_context.scheme_id)}",
|
2016-04-20 22:54:01 +08:00
|
|
|
icons: [
|
2018-12-07 23:48:09 +08:00
|
|
|
],
|
|
|
|
share_target: {
|
|
|
|
action: "/new-topic",
|
2019-03-16 04:10:05 +08:00
|
|
|
method: "GET",
|
|
|
|
enctype: "application/x-www-form-urlencoded",
|
2018-12-07 23:48:09 +08:00
|
|
|
params: {
|
|
|
|
title: "title",
|
|
|
|
text: "body"
|
|
|
|
}
|
|
|
|
}
|
2015-09-20 23:00:30 +08:00
|
|
|
}
|
2017-01-04 01:50:45 +08:00
|
|
|
|
2019-05-01 21:44:45 +08:00
|
|
|
logo = SiteSetting.site_manifest_icon_url
|
|
|
|
manifest[:icons] << {
|
|
|
|
src: UrlHelper.absolute(logo),
|
|
|
|
sizes: "512x512",
|
|
|
|
type: MiniMime.lookup_by_filename(logo)&.content_type || "image/png"
|
|
|
|
} if logo
|
|
|
|
|
2018-11-28 21:55:52 +08:00
|
|
|
manifest[:short_name] = SiteSetting.short_title if SiteSetting.short_title.present?
|
|
|
|
|
2019-04-18 00:25:13 +08:00
|
|
|
if current_user && current_user.trust_level >= 1 && SiteSetting.native_app_install_banner_android
|
2017-07-28 09:20:09 +08:00
|
|
|
manifest = manifest.merge(
|
2017-01-04 01:50:45 +08:00
|
|
|
prefer_related_applications: true,
|
|
|
|
related_applications: [
|
|
|
|
{
|
|
|
|
platform: "play",
|
2019-04-18 00:25:13 +08:00
|
|
|
id: SiteSetting.android_app_id
|
2017-01-04 01:50:45 +08:00
|
|
|
}
|
|
|
|
]
|
2017-07-28 09:20:09 +08:00
|
|
|
)
|
2017-01-04 01:50:45 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
manifest
|
2016-02-14 02:29:53 +08:00
|
|
|
end
|
2018-05-18 03:10:35 +08:00
|
|
|
|
2015-09-20 23:00:30 +08:00
|
|
|
end
|