mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
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',
|
||||
|
||||
initialize() {
|
||||
window.addEventListener('load', () => {
|
||||
const isSecured = (document.location.protocol === 'https:') ||
|
||||
(location.hostname === "localhost");
|
||||
const isSecured = (document.location.protocol === 'https:') ||
|
||||
(location.hostname === "localhost");
|
||||
|
||||
const isSupported= isSecured && ('serviceWorker' in navigator);
|
||||
const isSupported= isSecured && ('serviceWorker' in navigator);
|
||||
|
||||
if (isSupported) {
|
||||
if (Discourse.ServiceWorkerURL) {
|
||||
navigator.serviceWorker
|
||||
.register(`${Discourse.BaseUri}/${Discourse.ServiceWorkerURL}`)
|
||||
.catch(error => {
|
||||
Ember.Logger.info(`Failed to register Service Worker: ${error}`);
|
||||
});
|
||||
} else {
|
||||
navigator.serviceWorker.getRegistrations().then(registrations => {
|
||||
for(let registration of registrations) {
|
||||
registration.unregister();
|
||||
};
|
||||
if (isSupported) {
|
||||
if (Discourse.ServiceWorkerURL) {
|
||||
navigator.serviceWorker
|
||||
.register(`${Discourse.BaseUri}/${Discourse.ServiceWorkerURL}`)
|
||||
.catch(error => {
|
||||
Ember.Logger.info(`Failed to register Service Worker: ${error}`);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
navigator.serviceWorker.getRegistrations().then(registrations => {
|
||||
for(let registration of registrations) {
|
||||
registration.unregister();
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -45,7 +45,7 @@
|
||||
Discourse.ThemeSettings = ps.get('themeSettings');
|
||||
Discourse.LetterAvatarVersion = '<%= LetterAvatar.version %>';
|
||||
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 %>';
|
||||
Discourse.start();
|
||||
Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
|
||||
|
@ -734,6 +734,8 @@ Discourse::Application.routes.draw do
|
||||
# logs.
|
||||
get "/service-worker.js" => redirect(relative_url_root + 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
|
||||
|
||||
get "cdn_asset/:site/*path" => "static#cdn_asset", format: false
|
||||
|
Loading…
Reference in New Issue
Block a user