Fix check for update feature

This commit is contained in:
redphx 2023-08-05 10:03:56 +07:00
parent 3d3811b8f3
commit 1dc411281c

View File

@ -574,8 +574,9 @@ class UserAgent {
class Preferences { class Preferences {
static get LAST_UPDATE_CHECK() { return 'last_update_check'; } static get LAST_UPDATE_CHECK() { return 'version_last_check'; }
static get LATEST_VERSION() { return 'latest_version'; } static get LATEST_VERSION() { return 'version_latest'; }
static get CURRENT_VERSION() { return 'version_current'; }
static get SERVER_REGION() { return 'server_region'; } static get SERVER_REGION() { return 'server_region'; }
static get PREFER_IPV6_SERVER() { return 'prefer_ipv6_server'; } static get PREFER_IPV6_SERVER() { return 'prefer_ipv6_server'; }
@ -617,6 +618,10 @@ class Preferences {
'default': '', 'default': '',
'hidden': true, 'hidden': true,
}, },
[Preferences.CURRENT_VERSION]: {
'default': '',
'hidden': true,
},
[Preferences.SERVER_REGION]: { [Preferences.SERVER_REGION]: {
'label': 'Region of streaming server', 'label': 'Region of streaming server',
'default': 'default', 'default': 'default',
@ -912,11 +917,13 @@ const PREFS = new Preferences();
function checkForUpdate() { function checkForUpdate() {
const CHECK_INTERVAL_SECONDS = 4 * 3600 * 1000; // check every 4 hours const CHECK_INTERVAL_SECONDS = 4 * 3600; // check every 4 hours
const lastCheck = PREFS.get(Preferences.LAST_UPDATE_CHECK, 0);
const now = +new Date;
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; return;
} }
@ -927,6 +934,7 @@ function checkForUpdate() {
.then(json => { .then(json => {
// Store the latest version // Store the latest version
PREFS.set(Preferences.LATEST_VERSION, json.tag_name.substring(1)); PREFS.set(Preferences.LATEST_VERSION, json.tag_name.substring(1));
PREFS.set(Preferences.CURRENT_VERSION, SCRIPT_VERSION);
}); });
} }