Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions src_assets/common/assets/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,47 @@
vigembus: null,
}
},
async created() {

Check failure on line 183 in src_assets/common/assets/web/index.html

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=LizardByte_Sunshine&issues=AZ1Esgh07fGjs1Y14gyL&open=AZ1Esgh07fGjs1Y14gyL&pullRequest=4932
try {
let config = await fetch("./api/config").then((r) => r.json());
this.notifyPreReleases = config.notify_pre_releases;
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) {
Expand Down