mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 23:57:19 +02:00
Validate settings when getting its values
This commit is contained in:
parent
651402a6b4
commit
cd7a7c92c7
@ -1327,17 +1327,17 @@ class Preferences {
|
||||
},
|
||||
[Preferences.VIDEO_SATURATION]: {
|
||||
'default': 100,
|
||||
'min': 0,
|
||||
'min': 50,
|
||||
'max': 150,
|
||||
},
|
||||
[Preferences.VIDEO_CONTRAST]: {
|
||||
'default': 100,
|
||||
'min': 0,
|
||||
'min': 50,
|
||||
'max': 150,
|
||||
},
|
||||
[Preferences.VIDEO_BRIGHTNESS]: {
|
||||
'default': 100,
|
||||
'min': 0,
|
||||
'min': 50,
|
||||
'max': 150,
|
||||
},
|
||||
[Preferences.AUDIO_MIC_ON_PLAYING]: {
|
||||
@ -1417,34 +1417,16 @@ class Preferences {
|
||||
}
|
||||
}
|
||||
|
||||
get(key, defaultValue=null) {
|
||||
if (typeof key === 'undefined') {
|
||||
debugger;
|
||||
return;
|
||||
}
|
||||
|
||||
// Return "default" for STREAM_TOUCH_CONTROLLER pref when the browser doesn't support touch
|
||||
if (!HAS_TOUCH_SUPPORT && key === Preferences.STREAM_TOUCH_CONTROLLER) {
|
||||
return 'default';
|
||||
}
|
||||
|
||||
const value = this._prefs[key];
|
||||
|
||||
if (typeof value !== 'undefined' && value !== null && value !== '') {
|
||||
#validateValue(key, value) {
|
||||
const config = Preferences.SETTINGS[key];
|
||||
if (!config) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (defaultValue !== null) {
|
||||
return defaultValue;
|
||||
if (typeof value === 'undefined' || value === null) {
|
||||
value = config.default;
|
||||
}
|
||||
|
||||
// Return default value
|
||||
return Preferences.SETTINGS[key].default;
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
const config = Preferences.SETTINGS[key];
|
||||
if (config) {
|
||||
if ('min' in config) {
|
||||
value = Math.max(config.min, value);
|
||||
}
|
||||
@ -1467,8 +1449,30 @@ class Preferences {
|
||||
value = config.default;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
get(key) {
|
||||
if (typeof key === 'undefined') {
|
||||
debugger;
|
||||
return;
|
||||
}
|
||||
|
||||
// Return "default" for STREAM_TOUCH_CONTROLLER pref when the browser doesn't support touch
|
||||
if (!HAS_TOUCH_SUPPORT && key === Preferences.STREAM_TOUCH_CONTROLLER) {
|
||||
return 'default';
|
||||
}
|
||||
|
||||
let value = this._prefs[key];
|
||||
value = this.#validateValue(key, value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
value = this.#validateValue(key, value);
|
||||
|
||||
this._prefs[key] = value;
|
||||
this._update_storage();
|
||||
}
|
||||
@ -1649,8 +1653,8 @@ const PREFS = new Preferences();
|
||||
function checkForUpdate() {
|
||||
const CHECK_INTERVAL_SECONDS = 4 * 3600; // check every 4 hours
|
||||
|
||||
const currentVersion = PREFS.get(Preferences.CURRENT_VERSION, '');
|
||||
const lastCheck = PREFS.get(Preferences.LAST_UPDATE_CHECK, 0);
|
||||
const currentVersion = PREFS.get(Preferences.CURRENT_VERSION);
|
||||
const lastCheck = PREFS.get(Preferences.LAST_UPDATE_CHECK);
|
||||
const now = Math.round((+new Date) / 1000);
|
||||
|
||||
if (currentVersion === SCRIPT_VERSION && now - lastCheck < CHECK_INTERVAL_SECONDS) {
|
||||
@ -2669,7 +2673,7 @@ function injectSettingsButton($parent) {
|
||||
|
||||
const CE = createElement;
|
||||
const PREF_PREFERRED_REGION = getPreferredServerRegion();
|
||||
const PREF_LATEST_VERSION = PREFS.get(Preferences.LATEST_VERSION, null);
|
||||
const PREF_LATEST_VERSION = PREFS.get(Preferences.LATEST_VERSION);
|
||||
|
||||
// Setup Settings button
|
||||
const $button = CE('button', {'class': 'better-xcloud-settings-button'}, PREF_PREFERRED_REGION);
|
||||
|
Loading…
x
Reference in New Issue
Block a user