App Banner Support for Android Chrome (#4103)

* App Banner Support for Android Chrome

* Oops, forgot semicolon;
This commit is contained in:
Rafael dos Santos Silva 2016-04-20 11:54:01 -03:00 committed by Robin Ward
parent 7996ae50d8
commit bbe642070e
3 changed files with 29 additions and 1 deletions

View File

@ -0,0 +1,16 @@
// Android Chrome App Banner requires at least **one** service worker to be instantiate and https.
// After Discourse starts to use service workers for other stuff (like mobile notification, offline mode, or ember)
// we can ditch this.
export default {
name: 'android-app-banner-service-worker',
initialize(container) {
const caps = container.lookup('capabilities:main');
const isSecure = document.location.protocol === 'https:';
if (isSecure && caps.isAndroid && 'serviceWorker' in navigator) {
navigator.serviceWorker.register(Discourse.BaseUri + '/service-worker.js', {scope: './'});
}
}
};

View File

@ -4,12 +4,20 @@ class MetadataController < ApplicationController
def manifest
manifest = {
name: SiteSetting.title,
short_name: SiteSetting.title,
display: 'standalone',
orientation: 'portrait',
start_url: "#{Discourse.base_uri}/",
background_color: "##{ColorScheme.hex_for_name('secondary')}",
theme_color: "##{ColorScheme.hex_for_name('header_background')}"
theme_color: "##{ColorScheme.hex_for_name('header_background')}",
icons: [
{
src: SiteSetting.apple_touch_icon_url,
sizes: "144x144",
type: "image/png"
}
]
}
render json: manifest.to_json

4
public/service-worker.js Normal file
View File

@ -0,0 +1,4 @@
/*
This service worker doesn't actually do anything!
I'm here just to support Google Chrome App Banner on Android
*/