diff --git a/client/layouts/default.vue b/client/layouts/default.vue index 388cec16..96f16840 100644 --- a/client/layouts/default.vue +++ b/client/layouts/default.vue @@ -485,6 +485,25 @@ export default { }, resize() { this.$store.commit('globals/updateWindowSize', { width: window.innerWidth, height: window.innerHeight }) + }, + checkVersionUpdate() { + // Version check is only run if time since last check was 5 minutes + const VERSION_CHECK_BUFF = 1000 * 60 * 5 // 5 minutes + var lastVerCheck = localStorage.getItem('lastVerCheck') || 0 + if (Date.now() - Number(lastVerCheck) > VERSION_CHECK_BUFF) { + this.$store + .dispatch('checkForUpdate') + .then((res) => { + localStorage.setItem('lastVerCheck', Date.now()) + if (res && res.hasUpdate) this.showUpdateToast(res) + }) + .catch((err) => console.error(err)) + + if (this.$route.query.error) { + this.$toast.error(this.$route.query.error) + this.$router.replace(this.$route.path) + } + } } }, beforeMount() { @@ -503,17 +522,7 @@ export default { this.$store.commit('setExperimentalFeatures', true) } - this.$store - .dispatch('checkForUpdate') - .then((res) => { - if (res && res.hasUpdate) this.showUpdateToast(res) - }) - .catch((err) => console.error(err)) - - if (this.$route.query.error) { - this.$toast.error(this.$route.query.error) - this.$router.replace(this.$route.path) - } + this.checkVersionUpdate() }, beforeDestroy() { window.removeEventListener('resize', this.resize) diff --git a/client/plugins/version.js b/client/plugins/version.js index d09b7afc..225c5bff 100644 --- a/client/plugins/version.js +++ b/client/plugins/version.js @@ -33,11 +33,12 @@ export async function checkForUpdate() { return } var largestVer = null - await axios.get(`https://api.github.com/repos/advplyr/audiobookshelf/tags`).then((res) => { - var tags = res.data - if (tags && tags.length) { - tags.forEach((tag) => { - var verObj = parseSemver(tag.name) + await axios.get(`https://api.github.com/repos/advplyr/audiobookshelf/releases`).then((res) => { + var releases = res.data + if (releases && releases.length) { + releases.forEach((release) => { + var tagName = release.tag_name + var verObj = parseSemver(tagName) if (verObj) { if (!largestVer || largestVer.total < verObj.total) { largestVer = verObj @@ -50,6 +51,7 @@ export async function checkForUpdate() { console.error('No valid version tags to compare with') return } + return { hasUpdate: largestVer.total > currVerObj.total, latestVersion: largestVer.version,