mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 10:49:04 +08:00
App Banner Support for Android Chrome (#4103)
* App Banner Support for Android Chrome * Oops, forgot semicolon;
This commit is contained in:
parent
7996ae50d8
commit
bbe642070e
|
@ -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: './'});
|
||||
}
|
||||
}
|
||||
};
|
|
@ -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
4
public/service-worker.js
Normal 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
|
||||
*/
|
Loading…
Reference in New Issue
Block a user