From e7b76b319adaed7b7b336248c4047f24373e98d2 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Wed, 28 Nov 2018 14:55:52 +0100 Subject: [PATCH] FEATURE: Setting for short title used by Android on homescreen --- app/controllers/metadata_controller.rb | 3 ++- config/locales/server.en.yml | 2 ++ config/site_settings.yml | 2 ++ spec/requests/metadata_controller_spec.rb | 13 +++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/metadata_controller.rb b/app/controllers/metadata_controller.rb index 07a3ac76327..dacba4dbd7b 100644 --- a/app/controllers/metadata_controller.rb +++ b/app/controllers/metadata_controller.rb @@ -27,7 +27,6 @@ class MetadataController < ApplicationController manifest = { name: SiteSetting.title, - short_name: SiteSetting.title, display: display, start_url: Discourse.base_uri.present? ? "#{Discourse.base_uri}/" : '.', background_color: "##{ColorScheme.hex_for_name('secondary', view_context.scheme_id)}", @@ -41,6 +40,8 @@ class MetadataController < ApplicationController ] } + manifest[:short_name] = SiteSetting.short_title if SiteSetting.short_title.present? + if SiteSetting.native_app_install_banner manifest = manifest.merge( prefer_related_applications: true, diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 8c8da6bc70e..4c643d449fb 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1856,6 +1856,8 @@ en: push_notifications_prompt: "Display user consent prompt." push_notifications_icon: "The badge icon that appears in the notification corner. Recommended size is 96px by 96px." + short_title: "The short title will be used on the user's home screen, launcher, or other places where space may be limited. A maximum of 12 characters is recommended." + errors: invalid_email: "Invalid email address." invalid_username: "There's no user with that username." diff --git a/config/site_settings.yml b/config/site_settings.yml index 3639fde011f..b64d9198b85 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -281,6 +281,8 @@ basic: push_notifications_icon_url: hidden: true default: '' + short_title: + default: '' vapid_public_key_bytes: default: '' client: true diff --git a/spec/requests/metadata_controller_spec.rb b/spec/requests/metadata_controller_spec.rb index 2047b13277f..e5b2f033b87 100644 --- a/spec/requests/metadata_controller_spec.rb +++ b/spec/requests/metadata_controller_spec.rb @@ -63,6 +63,19 @@ RSpec.describe MetadataController do expect(manifest["display"]).to eq("standalone") end + it 'uses the short_title if it is set' do + get "/manifest.webmanifest" + expect(response.status).to eq(200) + manifest = JSON.parse(response.body) + expect(manifest).to_not have_key("short_name") + + SiteSetting.short_title = "foo" + + get "/manifest.webmanifest" + expect(response.status).to eq(200) + manifest = JSON.parse(response.body) + expect(manifest["short_name"]).to eq("foo") + end end describe 'opensearch.xml' do