revert settings
This commit is contained in:
parent
3492a91056
commit
95ac1655bc
|
@ -1,44 +1,12 @@
|
|||
function deRegister() {
|
||||
if (navigator.serviceWorker.getRegistrations) {
|
||||
navigator.serviceWorker.getRegistrations().then(r => {
|
||||
r.forEach(reg => {
|
||||
if (reg.active && reg.active.scriptURL.indexOf('service-worker.js') > 0) {
|
||||
reg.unregister();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'register-service-worker',
|
||||
|
||||
initialize(container) {
|
||||
const siteSettings = container.lookup('site-settings:main');
|
||||
initialize() {
|
||||
const isSecure = (document.location.protocol === 'https:') ||
|
||||
(location.hostname === "localhost");
|
||||
|
||||
if (isSecure && ('serviceWorker' in navigator)) {
|
||||
|
||||
let agents = siteSettings.service_worker_user_agents.split('|');
|
||||
|
||||
let allowed = false;
|
||||
|
||||
if (agents[0].length > 0) {
|
||||
const userAgent = (navigator.userAgent || "unknown").toLowerCase();
|
||||
for(let i=0; i<agents.length; i++) {
|
||||
allowed = userAgent.indexOf(agents[i]) !== -1;
|
||||
if (allowed) { break; }
|
||||
}
|
||||
}
|
||||
|
||||
if (allowed) {
|
||||
// TODO no need to register if we already registered recently
|
||||
// consider using local storage to figure out when last registered
|
||||
navigator.serviceWorker.register(`${Discourse.BaseUri}/service-worker.js`);
|
||||
} else {
|
||||
deRegister();
|
||||
}
|
||||
navigator.serviceWorker.register(`${Discourse.BaseUri}/service-worker.js`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1271,12 +1271,6 @@ uncategorized:
|
|||
summary_percent_filter: 20
|
||||
summary_max_results: 100
|
||||
|
||||
service_worker_user_agents:
|
||||
hidden: true
|
||||
default: 'android'
|
||||
type: list
|
||||
client: true
|
||||
|
||||
# View heat thresholds
|
||||
topic_views_heat_low:
|
||||
client: true
|
||||
|
|
Loading…
Reference in New Issue