FEATURE: Allow admins to control PWA display mode per user agent
This commit is contained in:
parent
fb15e04e48
commit
2450f178ca
|
@ -19,7 +19,7 @@ class MetadataController < ApplicationController
|
|||
end
|
||||
file_info = get_file_info(logo)
|
||||
|
||||
display = request.user_agent =~ /iPad|iPhone/ ? 'browser' : 'standalone'
|
||||
display = Regexp.new(SiteSetting.pwa_display_browser_regex).match(request.user_agent) ? 'browser' : 'standalone'
|
||||
|
||||
manifest = {
|
||||
name: SiteSetting.title,
|
||||
|
|
|
@ -1665,6 +1665,10 @@ uncategorized:
|
|||
|
||||
native_app_install_banner: false
|
||||
|
||||
pwa_display_browser_regex:
|
||||
default: "iPad|iPhone"
|
||||
hidden: true
|
||||
|
||||
share_anonymized_statistics: true
|
||||
|
||||
auto_handle_queued_age:
|
||||
|
|
|
@ -31,6 +31,27 @@ RSpec.describe MetadataController do
|
|||
manifest = JSON.parse(response.body)
|
||||
expect(manifest["icons"].first["type"]).to eq("image/png")
|
||||
end
|
||||
|
||||
it 'defaults to display standalone for Android' do
|
||||
get "/manifest.webmanifest", params: {}, headers: { 'USER-AGENT' => 'Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/67.0.3396.87 Mobile Safari/537.36' }
|
||||
manifest = JSON.parse(response.body)
|
||||
expect(manifest["display"]).to eq("standalone")
|
||||
end
|
||||
|
||||
it 'defaults to display browser for iPhone' do
|
||||
get "/manifest.webmanifest", params: {}, headers: { 'USER-AGENT' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' }
|
||||
manifest = JSON.parse(response.body)
|
||||
expect(manifest["display"]).to eq("browser")
|
||||
end
|
||||
|
||||
it 'can be changed to display standalone for iPhones using a site setting' do
|
||||
SiteSetting.pwa_display_browser_regex = "a^" # this never matches
|
||||
|
||||
get "/manifest.webmanifest", params: {}, headers: { 'USER-AGENT' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' }
|
||||
manifest = JSON.parse(response.body)
|
||||
expect(manifest["display"]).to eq("standalone")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'opensearch.xml' do
|
||||
|
|
Loading…
Reference in New Issue