mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-07 16:17:20 +02:00
Fix check for update feature
This commit is contained in:
parent
3d3811b8f3
commit
1dc411281c
@ -574,8 +574,9 @@ class UserAgent {
|
||||
|
||||
|
||||
class Preferences {
|
||||
static get LAST_UPDATE_CHECK() { return 'last_update_check'; }
|
||||
static get LATEST_VERSION() { return 'latest_version'; }
|
||||
static get LAST_UPDATE_CHECK() { return 'version_last_check'; }
|
||||
static get LATEST_VERSION() { return 'version_latest'; }
|
||||
static get CURRENT_VERSION() { return 'version_current'; }
|
||||
|
||||
static get SERVER_REGION() { return 'server_region'; }
|
||||
static get PREFER_IPV6_SERVER() { return 'prefer_ipv6_server'; }
|
||||
@ -617,6 +618,10 @@ class Preferences {
|
||||
'default': '',
|
||||
'hidden': true,
|
||||
},
|
||||
[Preferences.CURRENT_VERSION]: {
|
||||
'default': '',
|
||||
'hidden': true,
|
||||
},
|
||||
[Preferences.SERVER_REGION]: {
|
||||
'label': 'Region of streaming server',
|
||||
'default': 'default',
|
||||
@ -912,11 +917,13 @@ const PREFS = new Preferences();
|
||||
|
||||
|
||||
function checkForUpdate() {
|
||||
const CHECK_INTERVAL_SECONDS = 4 * 3600 * 1000; // check every 4 hours
|
||||
const lastCheck = PREFS.get(Preferences.LAST_UPDATE_CHECK, 0);
|
||||
const now = +new Date;
|
||||
const CHECK_INTERVAL_SECONDS = 4 * 3600; // check every 4 hours
|
||||
|
||||
if (now - lastCheck < CHECK_INTERVAL_SECONDS) {
|
||||
const currentVersion = PREFS.get(Preferences.CURRENT_VERSION, '');
|
||||
const lastCheck = PREFS.get(Preferences.LAST_UPDATE_CHECK, 0);
|
||||
const now = Math.round((+new Date) / 1000);
|
||||
|
||||
if (currentVersion === SCRIPT_VERSION && now - lastCheck < CHECK_INTERVAL_SECONDS) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -927,6 +934,7 @@ function checkForUpdate() {
|
||||
.then(json => {
|
||||
// Store the latest version
|
||||
PREFS.set(Preferences.LATEST_VERSION, json.tag_name.substring(1));
|
||||
PREFS.set(Preferences.CURRENT_VERSION, SCRIPT_VERSION);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user