Always check for new version

This commit is contained in:
redphx 2025-03-11 17:49:15 +07:00
parent 8bdad8b319
commit 8998daf14c
3 changed files with 14 additions and 11 deletions

View File

@ -2693,11 +2693,12 @@ function setPref(prefKey, value, origin) {
}
function checkForUpdate() {
if (SCRIPT_VERSION.includes("beta")) return;
fetch("https://api.github.com/repos/redphx/better-xcloud/releases/latest").then((response) => response.json()).then((json) => {
setGlobalPref("version.latest", json.tag_name.substring(1), "direct"), setGlobalPref("version.current", SCRIPT_VERSION, "direct");
});
let CHECK_INTERVAL_SECONDS = 7200, currentVersion = getGlobalPref("version.current"), lastCheck = getGlobalPref("version.lastCheck"), now = Math.round(+new Date / 1000);
if (currentVersion === SCRIPT_VERSION && now - lastCheck < CHECK_INTERVAL_SECONDS) return;
setGlobalPref("version.lastCheck", now, "direct"), fetch("https://api.github.com/repos/redphx/better-xcloud/releases/latest").then((response) => response.json()).then((json) => {
setGlobalPref("version.latest", json.tag_name.substring(1), "direct"), setGlobalPref("version.current", SCRIPT_VERSION, "direct");
}), Translations.updateTranslations(currentVersion === SCRIPT_VERSION);
setGlobalPref("version.lastCheck", now, "direct"), Translations.updateTranslations(currentVersion === SCRIPT_VERSION);
}
function disablePwa() {
if (!(window.navigator.orgUserAgent || window.navigator.userAgent || "").toLowerCase()) return;

View File

@ -95,7 +95,7 @@ function isGlobalPref(prefKey) {return ALL_PREFS.global.includes(prefKey);}
function isStreamPref(prefKey) {return ALL_PREFS.stream.includes(prefKey);}
function getPrefInfo(prefKey) {if (isGlobalPref(prefKey)) return {storage: STORAGE.Global,definition: getGlobalPrefDefinition(prefKey)};else if (isStreamPref(prefKey)) return {storage: STORAGE.Stream,definition: getStreamPrefDefinition(prefKey)};return alert("Missing pref definition: " + prefKey), {};}
function setPref(prefKey, value, origin) {if (isGlobalPref(prefKey)) setGlobalPref(prefKey, value, origin);else if (isStreamPref(prefKey)) setStreamPref(prefKey, value, origin);}
function checkForUpdate() {if (SCRIPT_VERSION.includes("beta")) return;let CHECK_INTERVAL_SECONDS = 7200, currentVersion = getGlobalPref("version.current"), lastCheck = getGlobalPref("version.lastCheck"), now = Math.round(+new Date / 1000);if (currentVersion === SCRIPT_VERSION && now - lastCheck < CHECK_INTERVAL_SECONDS) return;setGlobalPref("version.lastCheck", now, "direct"), fetch("https://api.github.com/repos/redphx/better-xcloud/releases/latest").then((response) => response.json()).then((json) => {setGlobalPref("version.latest", json.tag_name.substring(1), "direct"), setGlobalPref("version.current", SCRIPT_VERSION, "direct");}), Translations.updateTranslations(currentVersion === SCRIPT_VERSION);}
function checkForUpdate() {if (SCRIPT_VERSION.includes("beta")) return;fetch("https://api.github.com/repos/redphx/better-xcloud/releases/latest").then((response) => response.json()).then((json) => {setGlobalPref("version.latest", json.tag_name.substring(1), "direct"), setGlobalPref("version.current", SCRIPT_VERSION, "direct");});let CHECK_INTERVAL_SECONDS = 7200, currentVersion = getGlobalPref("version.current"), lastCheck = getGlobalPref("version.lastCheck"), now = Math.round(+new Date / 1000);if (currentVersion === SCRIPT_VERSION && now - lastCheck < CHECK_INTERVAL_SECONDS) return;setGlobalPref("version.lastCheck", now, "direct"), Translations.updateTranslations(currentVersion === SCRIPT_VERSION);}
function disablePwa() {if (!(window.navigator.orgUserAgent || window.navigator.userAgent || "").toLowerCase()) return;if (!!AppInterface || UserAgent.isSafariMobile()) Object.defineProperty(window.navigator, "standalone", {value: !0});}
function hashCode(str) {let hash = 0;for (let i = 0, len = str.length;i < len; i++) {let chr = str.charCodeAt(i);hash = (hash << 5) - hash + chr, hash |= 0;}return hash;}
function renderString(str, obj) {return str.replace(/\$\{([A-Za-z0-9_$]+)\}|\$([A-Za-z0-9_$]+)\$/g, (match, p1, p2) => {let name = p1 || p2;return name in obj ? obj[name] : match;});}

View File

@ -16,6 +16,15 @@ export function checkForUpdate() {
return;
}
// Always check for new version
fetch('https://api.github.com/repos/redphx/better-xcloud/releases/latest')
.then(response => response.json())
.then(json => {
// Store the latest version
setGlobalPref(GlobalPref.VERSION_LATEST, json.tag_name.substring(1), 'direct');
setGlobalPref(GlobalPref.VERSION_CURRENT, SCRIPT_VERSION, 'direct');
});
const CHECK_INTERVAL_SECONDS = 2 * 3600; // check every 2 hours
const currentVersion = getGlobalPref(GlobalPref.VERSION_CURRENT);
@ -28,13 +37,6 @@ export function checkForUpdate() {
// Start checking
setGlobalPref(GlobalPref.VERSION_LAST_CHECK, now, 'direct');
fetch('https://api.github.com/repos/redphx/better-xcloud/releases/latest')
.then(response => response.json())
.then(json => {
// Store the latest version
setGlobalPref(GlobalPref.VERSION_LATEST, json.tag_name.substring(1), 'direct');
setGlobalPref(GlobalPref.VERSION_CURRENT, SCRIPT_VERSION, 'direct');
});
// Update translations
Translations.updateTranslations(currentVersion === SCRIPT_VERSION);