2017-10-01 19:23:32 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ManifestSerializer < ActiveModel::Serializer
|
2024-08-22 06:04:27 -04:00
|
|
|
include InstanceHelper
|
2017-10-01 19:23:32 -04:00
|
|
|
include RoutingHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
|
2023-10-12 10:47:18 -04:00
|
|
|
attributes :id, :name, :short_name,
|
2017-10-01 19:23:32 -04:00
|
|
|
:icons, :theme_color, :background_color,
|
2018-01-17 11:08:10 -05:00
|
|
|
:display, :start_url, :scope,
|
2024-10-07 16:33:14 -04:00
|
|
|
:share_target, :shortcuts,
|
|
|
|
:prefer_related_applications, :related_applications
|
2017-10-01 19:23:32 -04:00
|
|
|
|
2023-10-12 10:47:18 -04:00
|
|
|
def id
|
|
|
|
# This is set to `/home` because that was the old value of `start_url` and
|
|
|
|
# thus the fallback ID computed by Chrome:
|
|
|
|
# https://developer.chrome.com/blog/pwa-manifest-id/
|
|
|
|
'/home'
|
|
|
|
end
|
|
|
|
|
2017-10-01 19:23:32 -04:00
|
|
|
def name
|
2022-10-04 21:47:56 -04:00
|
|
|
object.title
|
2017-10-01 19:23:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def short_name
|
2022-10-04 21:47:56 -04:00
|
|
|
object.title
|
2017-10-01 19:23:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def icons
|
2024-05-06 11:06:52 -04:00
|
|
|
SiteUpload::ANDROID_ICON_SIZES.map do |size|
|
2024-05-15 05:38:16 -04:00
|
|
|
src = app_icon_path(size.to_i)
|
2024-05-06 11:06:52 -04:00
|
|
|
src = URI.join(root_url, src).to_s if src.present?
|
|
|
|
|
2017-10-01 19:23:32 -04:00
|
|
|
{
|
2024-05-06 11:06:52 -04:00
|
|
|
src: src || frontend_asset_url("icons/android-chrome-#{size}x#{size}.png"),
|
2022-06-09 16:25:23 -04:00
|
|
|
sizes: "#{size}x#{size}",
|
2017-10-01 19:23:32 -04:00
|
|
|
type: 'image/png',
|
2022-11-17 04:52:30 -05:00
|
|
|
purpose: 'any maskable',
|
2022-06-09 16:25:23 -04:00
|
|
|
}
|
|
|
|
end
|
2017-10-01 19:23:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def theme_color
|
2022-10-23 09:58:24 -04:00
|
|
|
'#191b22'
|
2017-10-01 19:23:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def background_color
|
|
|
|
'#191b22'
|
|
|
|
end
|
|
|
|
|
|
|
|
def display
|
|
|
|
'standalone'
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_url
|
2023-10-12 10:47:18 -04:00
|
|
|
'/'
|
2017-10-01 19:23:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def scope
|
2021-09-08 17:33:36 -04:00
|
|
|
'/'
|
2017-10-01 19:23:32 -04:00
|
|
|
end
|
2018-01-17 11:08:10 -05:00
|
|
|
|
|
|
|
def share_target
|
2019-02-01 19:26:49 -05:00
|
|
|
{
|
|
|
|
url_template: 'share?title={title}&text={text}&url={url}',
|
|
|
|
action: 'share',
|
2019-09-05 09:51:51 -04:00
|
|
|
method: 'GET',
|
|
|
|
enctype: 'application/x-www-form-urlencoded',
|
2019-02-01 19:26:49 -05:00
|
|
|
params: {
|
|
|
|
title: 'title',
|
|
|
|
text: 'text',
|
|
|
|
url: 'url',
|
|
|
|
},
|
|
|
|
}
|
2018-01-17 11:08:10 -05:00
|
|
|
end
|
2020-12-14 20:04:56 -05:00
|
|
|
|
|
|
|
def shortcuts
|
|
|
|
[
|
|
|
|
{
|
2022-06-09 16:25:23 -04:00
|
|
|
name: 'Compose new post',
|
2022-10-23 08:05:18 -04:00
|
|
|
url: '/publish',
|
2020-12-14 20:04:56 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Notifications',
|
2022-10-23 08:05:18 -04:00
|
|
|
url: '/notifications',
|
2020-12-14 20:04:56 -05:00
|
|
|
},
|
2023-10-02 07:18:16 -04:00
|
|
|
{
|
|
|
|
name: 'Explore',
|
|
|
|
url: '/explore',
|
|
|
|
},
|
2020-12-14 20:04:56 -05:00
|
|
|
]
|
|
|
|
end
|
2024-10-07 16:33:14 -04:00
|
|
|
|
|
|
|
def prefer_related_applications
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def related_applications
|
|
|
|
[
|
|
|
|
{
|
|
|
|
platform: 'play',
|
|
|
|
url: 'https://play.google.com/store/apps/details?id=org.joinmastodon.android',
|
|
|
|
id: 'org.joinmastodon.android',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
platform: 'itunes',
|
|
|
|
url: 'https://apps.apple.com/us/app/mastodon-for-iphone/id1571998974',
|
|
|
|
id: 'id1571998974',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
platform: 'f-droid',
|
|
|
|
url: 'https://f-droid.org/en/packages/org.joinmastodon.android/',
|
|
|
|
id: 'org.joinmastodon.android',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
end
|
2017-10-01 19:23:32 -04:00
|
|
|
end
|