diff --git a/src_assets/common/assets/web/index.html b/src_assets/common/assets/web/index.html index 7a02b34fc36..0f7884b925c 100644 --- a/src_assets/common/assets/web/index.html +++ b/src_assets/common/assets/web/index.html @@ -187,11 +187,40 @@
{{ githubVersion.release.name }}
this.platform = config.platform; this.controllerEnabled = config.controller !== "disabled"; this.version = new SunshineVersion(null, config.version); - console.log("Version: ", this.version.version) - this.githubVersion = new SunshineVersion(await fetch("https://api.github.com/repos/LizardByte/Sunshine/releases/latest").then((r) => r.json()), null); - console.log("GitHub Version: ", this.githubVersion.version) - this.preReleaseVersion = new SunshineVersion((await fetch("https://api.github.com/repos/LizardByte/Sunshine/releases").then((r) => r.json())).find(release => release.prerelease), null); - console.log("Pre-Release Version: ", this.preReleaseVersion.version) + console.log("Version: ", this.version.version); + + const now = Date.now(); + let { lastCheck, latest, pre } = JSON.parse(localStorage.getItem('sunshine_version_cache') || '{}'); + const cacheAge = 60 * 60 * 1000; + + if (lastCheck && (now - lastCheck < cacheAge) && latest) { + console.log("Using cached version data"); + this.githubVersion = new SunshineVersion(latest, null); + if (pre) { + this.preReleaseVersion = new SunshineVersion(pre, null); + } + } else { + const latestJson = await fetch("https://api.github.com/repos/LizardByte/Sunshine/releases/latest").then(e => e.json()); + this.githubVersion = new SunshineVersion(latestJson, null); + console.log("GitHub Version: ", this.githubVersion.version) + + let preReleaseJson = null; + // Only send request when need pre-release + if (this.notifyPreReleases) { + const releases = await fetch("https://api.github.com/repos/LizardByte/Sunshine/releases").then(e => e.json()); + preReleaseJson = releases.find(e => e.prerelease); + if (preReleaseJson) { + this.preReleaseVersion = new SunshineVersion((await fetch("https://api.github.com/repos/LizardByte/Sunshine/releases").then((r) => r.json())).find(release => release.prerelease), null); + console.log("Pre-Release Version: ", this.preReleaseVersion.version) + } + } + + localStorage.setItem('sunshine_version_cache', JSON.stringify({ + lastCheck: now, + latest: latestJson, + pre: preReleaseJson + })); + } // Fetch ViGEmBus status only on Windows when controller is enabled if (this.platform === 'windows' && this.controllerEnabled) {