Skip to content

Commit

Permalink
FEATURE: Update the webmanifest
Browse files Browse the repository at this point in the history
- Remove share target because the spec is changing
- Allow any orientation again because natural is too restrictive
- Use correct file and mime types for the manifest
  • Loading branch information
xfalcox committed Jun 14, 2018
1 parent 66982c7 commit 8fc08aa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
7 changes: 2 additions & 5 deletions app/controllers/metadata_controller.rb
Expand Up @@ -3,7 +3,7 @@ class MetadataController < ApplicationController
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required

def manifest
render json: default_manifest.to_json
render json: default_manifest.to_json, content_type: 'application/manifest+json'
end

def opensearch
Expand All @@ -23,11 +23,8 @@ def default_manifest
name: SiteSetting.title,
short_name: SiteSetting.title,
display: 'standalone',
orientation: 'natural',
orientation: 'any',
start_url: "#{Discourse.base_uri}/",
share_target: {
url_template: 'new-topic?title={title}&body={text}%0A%0A{url}'
},
background_color: "##{ColorScheme.hex_for_name('secondary')}",
theme_color: "##{ColorScheme.hex_for_name('header_background')}",
icons: [
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -46,7 +46,7 @@
<%= render_google_tag_manager_head_code %>
<%= render_google_universal_analytics_code %>
<link rel="manifest" href="<%= Discourse.base_uri %>/manifest.json">
<link rel="manifest" href="<%= Discourse.base_uri %>/manifest.webmanifest">

<%- if SiteSetting.native_app_install_banner? %>
<meta name="apple-itunes-app" content="app-id=1173672076">
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Expand Up @@ -747,7 +747,8 @@
get "robots.txt" => "robots_txt#index"
get "robots-builder.json" => "robots_txt#builder"
get "offline.html" => "offline#index"
get "manifest.json" => "metadata#manifest", as: :manifest
get "manifest.webmanifest" => "metadata#manifest", as: :manifest
get "manifest.json" => "metadata#manifest"
get "opensearch" => "metadata#opensearch", format: :xml

scope "/tags" do
Expand Down
10 changes: 5 additions & 5 deletions spec/requests/metadata_controller_spec.rb
@@ -1,15 +1,15 @@
require 'rails_helper'

RSpec.describe MetadataController do
describe 'manifest.json' do
describe 'manifest.webmanifest' do
it 'returns the right output' do
title = 'MyApp'
SiteSetting.title = title
SiteSetting.large_icon_url = "http://big.square/png"

get "/manifest.json"
get "/manifest.webmanifest"
expect(response.status).to eq(200)
expect(response.content_type).to eq('application/json')
expect(response.content_type).to eq('application/manifest+json')
manifest = JSON.parse(response.body)

expect(manifest["name"]).to eq(title)
Expand All @@ -18,15 +18,15 @@

it 'can guess mime types' do
SiteSetting.large_icon_url = "http://big.square/ico.jpg"
get "/manifest.json"
get "/manifest.webmanifest"
expect(response.status).to eq(200)
manifest = JSON.parse(response.body)
expect(manifest["icons"].first["type"]).to eq("image/jpeg")
end

it 'defaults to png' do
SiteSetting.large_icon_url = "http://big.square/noidea.bogus"
get "/manifest.json"
get "/manifest.webmanifest"
expect(response.status).to eq(200)
manifest = JSON.parse(response.body)
expect(manifest["icons"].first["type"]).to eq("image/png")
Expand Down

1 comment on commit 8fc08aa

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/progressive-web-application-pwa/79217/5

Please sign in to comment.