You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/app/update_checker.js

65 lines
1.5 KiB

// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
app.UpdateChecker = class UpdateChecker {
constructor() {
this.checkDocs = this.checkDocs.bind(this);
this.onFocus = this.onFocus.bind(this);
this.lastCheck = Date.now();
1 year ago
$.on(window, "focus", this.onFocus);
if (app.serviceWorker != null) {
1 year ago
app.serviceWorker.on("updateready", this.onUpdateReady);
}
setTimeout(this.checkDocs, 0);
}
check() {
if (app.serviceWorker) {
app.serviceWorker.update();
} else {
ajax({
1 year ago
url: $('script[src*="application"]').getAttribute("src"),
dataType: "application/javascript",
error: (_, xhr) => {
if (xhr.status === 404) {
return this.onUpdateReady();
}
},
});
}
}
onUpdateReady() {
1 year ago
new app.views.Notif("UpdateReady", { autoHide: null });
}
checkDocs() {
1 year ago
if (!app.settings.get("manualUpdate")) {
app.docs.updateInBackground();
} else {
1 year ago
app.docs.checkForUpdates((i) => {
if (i > 0) {
return this.onDocsUpdateReady();
}
});
}
}
onDocsUpdateReady() {
1 year ago
new app.views.Notif("UpdateDocs", { autoHide: null });
}
onFocus() {
1 year ago
if (Date.now() - this.lastCheck > 21600e3) {
this.lastCheck = Date.now();
this.check();
}
}
};