1
0

manifest_serializer.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # frozen_string_literal: true
  2. class ManifestSerializer < ActiveModel::Serializer
  3. include InstanceHelper
  4. include RoutingHelper
  5. include ActionView::Helpers::TextHelper
  6. attributes :id, :name, :short_name,
  7. :icons, :theme_color, :background_color,
  8. :display, :start_url, :scope,
  9. :share_target, :shortcuts,
  10. :prefer_related_applications, :related_applications
  11. def id
  12. # This is set to `/home` because that was the old value of `start_url` and
  13. # thus the fallback ID computed by Chrome:
  14. # https://developer.chrome.com/blog/pwa-manifest-id/
  15. '/home'
  16. end
  17. def name
  18. object.title
  19. end
  20. def short_name
  21. object.title
  22. end
  23. def icons
  24. SiteUpload::ANDROID_ICON_SIZES.map do |size|
  25. src = app_icon_path(size.to_i)
  26. src = URI.join(root_url, src).to_s if src.present?
  27. {
  28. src: src || frontend_asset_url("icons/android-chrome-#{size}x#{size}.png"),
  29. sizes: "#{size}x#{size}",
  30. type: 'image/png',
  31. purpose: 'any maskable',
  32. }
  33. end
  34. end
  35. def theme_color
  36. '#191b22'
  37. end
  38. def background_color
  39. '#191b22'
  40. end
  41. def display
  42. 'standalone'
  43. end
  44. def start_url
  45. '/'
  46. end
  47. def scope
  48. '/'
  49. end
  50. def share_target
  51. {
  52. url_template: 'share?title={title}&text={text}&url={url}',
  53. action: 'share',
  54. method: 'GET',
  55. enctype: 'application/x-www-form-urlencoded',
  56. params: {
  57. title: 'title',
  58. text: 'text',
  59. url: 'url',
  60. },
  61. }
  62. end
  63. def shortcuts
  64. [
  65. {
  66. name: 'Compose new post',
  67. url: '/publish',
  68. },
  69. {
  70. name: 'Notifications',
  71. url: '/notifications',
  72. },
  73. {
  74. name: 'Explore',
  75. url: '/explore',
  76. },
  77. ]
  78. end
  79. def prefer_related_applications
  80. true
  81. end
  82. def related_applications
  83. [
  84. {
  85. platform: 'play',
  86. url: 'https://play.google.com/store/apps/details?id=org.joinmastodon.android',
  87. id: 'org.joinmastodon.android',
  88. },
  89. {
  90. platform: 'itunes',
  91. url: 'https://apps.apple.com/us/app/mastodon-for-iphone/id1571998974',
  92. id: 'id1571998974',
  93. },
  94. {
  95. platform: 'f-droid',
  96. url: 'https://f-droid.org/en/packages/org.joinmastodon.android/',
  97. id: 'org.joinmastodon.android',
  98. },
  99. ]
  100. end
  101. end