mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
FIX: Only unregister service workers that belongs to Discourse.
This commit is contained in:
@ -82,7 +82,8 @@ export default Ember.Controller.extend({
|
|||||||
actions: {
|
actions: {
|
||||||
save() {
|
save() {
|
||||||
this.set("saved", false);
|
this.set("saved", false);
|
||||||
const url = extractDomainFromUrl(this.get("model.payload_url"));
|
const url = this.get("model.payload_url");
|
||||||
|
const domain = extractDomainFromUrl(url);
|
||||||
const model = this.get("model");
|
const model = this.get("model");
|
||||||
const isNew = model.get("isNew");
|
const isNew = model.get("isNew");
|
||||||
|
|
||||||
@ -103,10 +104,10 @@ export default Ember.Controller.extend({
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (
|
if (
|
||||||
url === "localhost" ||
|
domain === "localhost" ||
|
||||||
url.match(/192\.168\.\d+\.\d+/) ||
|
domain.match(/192\.168\.\d+\.\d+/) ||
|
||||||
url.match(/127\.\d+\.\d+\.\d+/) ||
|
domain.match(/127\.\d+\.\d+\.\d+/) ||
|
||||||
url === Discourse.BaseUrl
|
url.startsWith(Discourse.BaseUrl)
|
||||||
) {
|
) {
|
||||||
return bootbox.confirm(
|
return bootbox.confirm(
|
||||||
I18n.t("admin.web_hooks.warn_local_payload_url"),
|
I18n.t("admin.web_hooks.warn_local_payload_url"),
|
||||||
|
@ -20,7 +20,7 @@ export default {
|
|||||||
Discourse.ServiceWorkerURL
|
Discourse.ServiceWorkerURL
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
registration.unregister();
|
this.unregister(registration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -34,10 +34,16 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
navigator.serviceWorker.getRegistrations().then(registrations => {
|
navigator.serviceWorker.getRegistrations().then(registrations => {
|
||||||
for (let registration of registrations) {
|
for (let registration of registrations) {
|
||||||
registration.unregister();
|
this.unregister(registration);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
unregister(registration) {
|
||||||
|
if (registration.scope.startsWith(Discourse.BaseUrl)) {
|
||||||
|
registration.unregister();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -443,11 +443,10 @@ module ApplicationHelper
|
|||||||
|
|
||||||
def client_side_setup_data
|
def client_side_setup_data
|
||||||
service_worker_url = Rails.env.development? ? 'service-worker.js' : Rails.application.assets_manifest.assets['service-worker.js']
|
service_worker_url = Rails.env.development? ? 'service-worker.js' : Rails.application.assets_manifest.assets['service-worker.js']
|
||||||
current_hostname_without_port = RailsMultisite::ConnectionManagement.current_hostname.sub(/:[\d]*$/, '')
|
|
||||||
|
|
||||||
setup_data = {
|
setup_data = {
|
||||||
cdn: Rails.configuration.action_controller.asset_host,
|
cdn: Rails.configuration.action_controller.asset_host,
|
||||||
base_url: current_hostname_without_port,
|
base_url: Discourse.base_url,
|
||||||
base_uri: Discourse::base_uri,
|
base_uri: Discourse::base_uri,
|
||||||
environment: Rails.env,
|
environment: Rails.env,
|
||||||
letter_avatar_version: LetterAvatar.version,
|
letter_avatar_version: LetterAvatar.version,
|
||||||
|
@ -115,7 +115,7 @@ QUnit.testStart(function(ctx) {
|
|||||||
// Allow our tests to change site settings and have them reset before the next test
|
// Allow our tests to change site settings and have them reset before the next test
|
||||||
Discourse.SiteSettings = dup(Discourse.SiteSettingsOriginal);
|
Discourse.SiteSettings = dup(Discourse.SiteSettingsOriginal);
|
||||||
Discourse.BaseUri = "";
|
Discourse.BaseUri = "";
|
||||||
Discourse.BaseUrl = "localhost";
|
Discourse.BaseUrl = "http://localhost:3000";
|
||||||
Discourse.Session.resetCurrent();
|
Discourse.Session.resetCurrent();
|
||||||
Discourse.User.resetCurrent();
|
Discourse.User.resetCurrent();
|
||||||
resetSite(Discourse.SiteSettings);
|
resetSite(Discourse.SiteSettings);
|
||||||
|
Reference in New Issue
Block a user