Merge pull request #5749 from featheredtoast/service-worker-registration-fixes
Fix - service worker registrations
This commit is contained in:
commit
4c6d2ed59a
|
@ -2,27 +2,25 @@ export default {
|
||||||
name: 'register-service-worker',
|
name: 'register-service-worker',
|
||||||
|
|
||||||
initialize() {
|
initialize() {
|
||||||
window.addEventListener('load', () => {
|
const isSecured = (document.location.protocol === 'https:') ||
|
||||||
const isSecured = (document.location.protocol === 'https:') ||
|
(location.hostname === "localhost");
|
||||||
(location.hostname === "localhost");
|
|
||||||
|
|
||||||
const isSupported= isSecured && ('serviceWorker' in navigator);
|
const isSupported= isSecured && ('serviceWorker' in navigator);
|
||||||
|
|
||||||
if (isSupported) {
|
if (isSupported) {
|
||||||
if (Discourse.ServiceWorkerURL) {
|
if (Discourse.ServiceWorkerURL) {
|
||||||
navigator.serviceWorker
|
navigator.serviceWorker
|
||||||
.register(`${Discourse.BaseUri}/${Discourse.ServiceWorkerURL}`)
|
.register(`${Discourse.BaseUri}/${Discourse.ServiceWorkerURL}`)
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
Ember.Logger.info(`Failed to register Service Worker: ${error}`);
|
Ember.Logger.info(`Failed to register Service Worker: ${error}`);
|
||||||
});
|
|
||||||
} else {
|
|
||||||
navigator.serviceWorker.getRegistrations().then(registrations => {
|
|
||||||
for(let registration of registrations) {
|
|
||||||
registration.unregister();
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
|
navigator.serviceWorker.getRegistrations().then(registrations => {
|
||||||
|
for(let registration of registrations) {
|
||||||
|
registration.unregister();
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
Discourse.ThemeSettings = ps.get('themeSettings');
|
Discourse.ThemeSettings = ps.get('themeSettings');
|
||||||
Discourse.LetterAvatarVersion = '<%= LetterAvatar.version %>';
|
Discourse.LetterAvatarVersion = '<%= LetterAvatar.version %>';
|
||||||
Discourse.MarkdownItURL = '<%= asset_url('markdown-it-bundle.js') %>';
|
Discourse.MarkdownItURL = '<%= asset_url('markdown-it-bundle.js') %>';
|
||||||
Discourse.ServiceWorkerURL = '<%= Rails.application.assets_manifest.assets['service-worker.js'] %>'
|
Discourse.ServiceWorkerURL = Discourse.Environment != "development" ? '<%= Rails.application.assets_manifest.assets['service-worker.js'] %>' : 'service-worker.js';
|
||||||
I18n.defaultLocale = '<%= SiteSetting.default_locale %>';
|
I18n.defaultLocale = '<%= SiteSetting.default_locale %>';
|
||||||
Discourse.start();
|
Discourse.start();
|
||||||
Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
|
Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
|
||||||
|
|
|
@ -734,6 +734,8 @@ Discourse::Application.routes.draw do
|
||||||
# logs.
|
# logs.
|
||||||
get "/service-worker.js" => redirect(relative_url_root + service_worker_asset), format: :js
|
get "/service-worker.js" => redirect(relative_url_root + service_worker_asset), format: :js
|
||||||
get service_worker_asset => "static#service_worker_asset", format: :js
|
get service_worker_asset => "static#service_worker_asset", format: :js
|
||||||
|
elsif Rails.env.development?
|
||||||
|
get "/service-worker.js" => "static#service_worker_asset", format: :js
|
||||||
end
|
end
|
||||||
|
|
||||||
get "cdn_asset/:site/*path" => "static#cdn_asset", format: false
|
get "cdn_asset/:site/*path" => "static#cdn_asset", format: false
|
||||||
|
|
Loading…
Reference in New Issue