Skip to content

Commit

Permalink
fix: should notify new version only once a day even when an error occ…
Browse files Browse the repository at this point in the history
…urs (#353)

Add more messages in console

fixes #353
  • Loading branch information
Joxit committed Feb 8, 2024
1 parent 6318ccf commit 6c3c27e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/docker-registry-ui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docker-registry-ui",
"version": "2.5.6",
"version": "2.5.7",
"type": "module",
"scripts": {
"format": "npm run format-html && npm run format-js && npm run format-riot",
Expand Down
14 changes: 10 additions & 4 deletions src/components/version-notification.riot
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
if (latest && latest.tag_name) {
this.update({ tag_name: latest.tag_name, latest });
}
if (!latest || isNaN(expires) || new Date().getTime() > expires) {
if (isNaN(expires) || new Date().getTime() > expires) {
this.checkForUpdates(props, state);
}
},
Expand All @@ -64,16 +64,22 @@
const self = this;
oReq.addEventListener('load', function () {
localStorage.setItem(EXPIRES, new Date().getTime() + ONE_DAY);
if (this.status === 200) {
const latest = parseJSON(this.responseText);
if (latest && self.tag_name !== latest.tag_name && !isNewestVersion(props.version, latest.tag_name)) {
props.onNotify('A new version of Docker Registry UI is available!');
}
localStorage.setItem(LATEST, this.responseText);
localStorage.setItem(EXPIRES, new Date().getTime() + ONE_DAY);
self.update({ tag_name: latest.tag_name, latest });
} else {
props.onNotify('Cannot check for new updates. See the browser console.');
} else if (this.status !== 404) {
// Should not notify if the project is not found.
props.onNotify('Cannot check for new updates. Will try again in 24 hours. See the browser console.');
console.error(
`Cannot check for new Docker Registry UI updates. This is most likely a GitHub issue. You don't need to worry about it.`
);
console.error(`Got status code ${this.status} from Github API with response ${this.responseText}`);
}
});
Expand Down

0 comments on commit 6c3c27e

Please sign in to comment.