2019-05-02 02:57:12 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2020-06-30 22:58:02 -04:00
|
|
|
expires_in 1.minutes
|
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
|
2020-06-30 22:58:02 -04:00
|
|
|
expires_in 1.minutes
|
2019-05-03 02:19:14 -04:00
|
|
|
render template: "metadata/opensearch.xml"
|
2016-06-30 00:03:52 -04:00
|
|
|
end
|
|
|
|
|
2019-08-27 14:05:37 -04:00
|
|
|
def app_association_android
|
|
|
|
raise Discourse::NotFound unless SiteSetting.app_association_android.present?
|
2020-06-30 22:58:02 -04:00
|
|
|
expires_in 1.minutes
|
2019-08-27 14:05:37 -04:00
|
|
|
render plain: SiteSetting.app_association_android, content_type: 'application/json'
|
|
|
|
end
|
|
|
|
|
|
|
|
def app_association_ios
|
|
|
|
raise Discourse::NotFound unless SiteSetting.app_association_ios.present?
|
2020-06-30 22:58:02 -04:00
|
|
|
expires_in 1.minutes
|
2019-08-27 14:05:37 -04:00
|
|
|
render plain: SiteSetting.app_association_ios, content_type: 'application/json'
|
|
|
|
end
|
|
|
|
|
2016-06-30 00:03:52 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def default_manifest
|
2019-11-27 21:13:13 -05:00
|
|
|
display = "standalone"
|
|
|
|
if request.user_agent
|
|
|
|
regex = Regexp.new(SiteSetting.pwa_display_browser_regex)
|
|
|
|
if regex.match(request.user_agent)
|
|
|
|
display = "browser"
|
|
|
|
end
|
|
|
|
end
|
2018-08-15 22:36:08 -04:00
|
|
|
|
2020-06-02 00:04:02 -04:00
|
|
|
scheme_id = view_context.scheme_id
|
|
|
|
primary_color = ColorScheme.hex_for_name('primary', scheme_id)
|
2020-05-14 15:32:53 -04:00
|
|
|
icon_url_base = UrlHelper.absolute("/svg-sprite/#{Discourse.current_hostname}/icon/#{primary_color}")
|
|
|
|
|
2017-01-03 12:50:45 -05:00
|
|
|
manifest = {
|
2016-04-20 10:54:01 -04:00
|
|
|
name: SiteSetting.title,
|
2020-02-04 12:16:00 -05:00
|
|
|
short_name: SiteSetting.short_title.presence || SiteSetting.title.truncate(12, separator: ' ', omission: ''),
|
2018-08-15 22:36:08 -04:00
|
|
|
display: display,
|
2018-06-15 13:29:33 -04:00
|
|
|
start_url: Discourse.base_uri.present? ? "#{Discourse.base_uri}/" : '.',
|
2020-06-02 00:04:02 -04:00
|
|
|
background_color: "##{ColorScheme.hex_for_name('secondary', scheme_id)}",
|
|
|
|
theme_color: "##{ColorScheme.hex_for_name('header_background', scheme_id)}",
|
2016-04-20 10:54:01 -04:00
|
|
|
icons: [
|
2018-12-07 10:48:09 -05:00
|
|
|
],
|
|
|
|
share_target: {
|
|
|
|
action: "/new-topic",
|
2019-03-15 16:10:05 -04:00
|
|
|
method: "GET",
|
|
|
|
enctype: "application/x-www-form-urlencoded",
|
2018-12-07 10:48:09 -05:00
|
|
|
params: {
|
|
|
|
title: "title",
|
|
|
|
text: "body"
|
|
|
|
}
|
2020-05-12 11:24:33 -04:00
|
|
|
},
|
|
|
|
shortcuts: [
|
|
|
|
{
|
|
|
|
name: I18n.t('js.topic.create_long'),
|
|
|
|
short_name: I18n.t('js.topic.create'),
|
|
|
|
url: "/new-topic",
|
|
|
|
icons: [
|
|
|
|
{
|
2020-05-14 15:32:53 -04:00
|
|
|
src: "#{icon_url_base}/plus.svg",
|
2020-05-14 20:56:35 -04:00
|
|
|
sizes: "131x150",
|
|
|
|
type: "image/svg"
|
2020-05-12 11:24:33 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: I18n.t('js.user.messages.inbox'),
|
|
|
|
short_name: I18n.t('js.user.messages.inbox'),
|
|
|
|
url: "/my/messages",
|
|
|
|
icons: [
|
|
|
|
{
|
2020-05-14 15:32:53 -04:00
|
|
|
src: "#{icon_url_base}/envelope.svg",
|
2020-05-14 20:56:35 -04:00
|
|
|
sizes: "150x150",
|
|
|
|
type: "image/svg"
|
2020-05-12 11:24:33 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: I18n.t('js.user.bookmarks'),
|
|
|
|
short_name: I18n.t('js.user.bookmarks'),
|
|
|
|
url: "/my/bookmarks",
|
|
|
|
icons: [
|
|
|
|
{
|
2020-05-14 15:32:53 -04:00
|
|
|
src: "#{icon_url_base}/bookmark.svg",
|
2020-05-14 20:56:35 -04:00
|
|
|
sizes: "113x150",
|
|
|
|
type: "image/svg"
|
2020-05-12 11:24:33 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: I18n.t('js.filters.top.title'),
|
|
|
|
short_name: I18n.t('js.filters.top.title'),
|
|
|
|
url: "/top",
|
|
|
|
icons: [
|
|
|
|
{
|
2020-05-14 15:32:53 -04:00
|
|
|
src: "#{icon_url_base}/signal.svg",
|
2020-05-14 20:56:35 -04:00
|
|
|
sizes: "188x150",
|
|
|
|
type: "image/svg"
|
2020-05-12 11:24:33 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2015-09-20 11:00:30 -04:00
|
|
|
}
|
2017-01-03 12:50:45 -05:00
|
|
|
|
2019-05-01 09:44:45 -04:00
|
|
|
logo = SiteSetting.site_manifest_icon_url
|
2019-09-22 00:20:25 -04:00
|
|
|
if logo
|
|
|
|
icon_entry = {
|
|
|
|
src: UrlHelper.absolute(logo),
|
|
|
|
sizes: "512x512",
|
|
|
|
type: MiniMime.lookup_by_filename(logo)&.content_type || "image/png"
|
|
|
|
}
|
|
|
|
manifest[:icons] << icon_entry.dup
|
|
|
|
icon_entry[:purpose] = "maskable"
|
|
|
|
manifest[:icons] << icon_entry
|
|
|
|
end
|
2019-05-01 09:44:45 -04:00
|
|
|
|
2019-04-17 12:25:13 -04:00
|
|
|
if current_user && current_user.trust_level >= 1 && SiteSetting.native_app_install_banner_android
|
2017-01-03 12:50:45 -05:00
|
|
|
manifest = manifest.merge(
|
|
|
|
prefer_related_applications: true,
|
|
|
|
related_applications: [
|
|
|
|
{
|
|
|
|
platform: "play",
|
2019-04-17 12:25:13 -04:00
|
|
|
id: SiteSetting.android_app_id
|
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
|
|
|
|
2015-09-20 11:00:30 -04:00
|
|
|
end
|