2020-09-08 02:05:02 -04:00
|
|
|
import { AppStorage, Events } from 'jellyfin-apiclient';
|
2022-04-12 12:18:12 -04:00
|
|
|
import { toBoolean } from '../../utils/string.ts';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
class AppSettings {
|
|
|
|
#getKey(name, userId) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (userId) {
|
|
|
|
name = userId + '-' + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
enableAutoLogin(val) {
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2020-10-18 18:58:09 +01:00
|
|
|
this.set('enableAutoLogin', val.toString());
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-01-24 02:57:29 +09:00
|
|
|
|
2022-04-12 12:18:12 -04:00
|
|
|
return toBoolean(this.get('enableAutoLogin'), true);
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2021-03-28 17:11:00 +03:00
|
|
|
/**
|
|
|
|
* Get or set 'Enable Gamepad' state.
|
|
|
|
* @param {boolean|undefined} val - Flag to enable 'Enable Gamepad' or undefined.
|
|
|
|
* @return {boolean} 'Enable Gamepad' state.
|
|
|
|
*/
|
|
|
|
enableGamepad(val) {
|
|
|
|
if (val !== undefined) {
|
|
|
|
return this.set('enableGamepad', val.toString());
|
|
|
|
}
|
|
|
|
|
2022-04-12 12:18:12 -04:00
|
|
|
return toBoolean(this.get('enableGamepad'), false);
|
2021-03-28 17:11:00 +03:00
|
|
|
}
|
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
enableSystemExternalPlayers(val) {
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2020-10-18 18:58:09 +01:00
|
|
|
this.set('enableSystemExternalPlayers', val.toString());
|
2020-02-16 22:11:36 +09:00
|
|
|
}
|
|
|
|
|
2022-04-12 12:18:12 -04:00
|
|
|
return toBoolean(this.get('enableSystemExternalPlayers'), false);
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2020-02-16 22:11:36 +09:00
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
enableAutomaticBitrateDetection(isInNetwork, mediaType, val) {
|
2020-07-17 11:30:56 +01:00
|
|
|
const key = 'enableautobitratebitrate-' + mediaType + '-' + isInNetwork;
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (isInNetwork && mediaType === 'Audio') {
|
|
|
|
val = true;
|
|
|
|
}
|
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
this.set(key, val.toString());
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isInNetwork && mediaType === 'Audio') {
|
|
|
|
return true;
|
|
|
|
} else {
|
2022-04-12 12:18:12 -04:00
|
|
|
return toBoolean(this.get(key), true);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
maxStreamingBitrate(isInNetwork, mediaType, val) {
|
2020-07-17 11:30:56 +01:00
|
|
|
const key = 'maxbitrate-' + mediaType + '-' + isInNetwork;
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (isInNetwork && mediaType === 'Audio') {
|
|
|
|
// nothing to do, this is always a max value
|
|
|
|
} else {
|
2020-10-18 18:58:09 +01:00
|
|
|
this.set(key, val);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInNetwork && mediaType === 'Audio') {
|
|
|
|
// return a huge number so that it always direct plays
|
|
|
|
return 150000000;
|
|
|
|
} else {
|
2020-10-18 18:58:09 +01:00
|
|
|
return parseInt(this.get(key) || '0') || 1500000;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
maxStaticMusicBitrate(val) {
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2020-10-18 18:58:09 +01:00
|
|
|
this.set('maxStaticMusicBitrate', val);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-07-17 11:30:56 +01:00
|
|
|
const defaultValue = 320000;
|
2020-10-18 18:58:09 +01:00
|
|
|
return parseInt(this.get('maxStaticMusicBitrate') || defaultValue.toString()) || defaultValue;
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
maxChromecastBitrate(val) {
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2020-10-18 18:58:09 +01:00
|
|
|
this.set('chromecastBitrate1', val);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
val = this.get('chromecastBitrate1');
|
2019-01-10 15:39:37 +03:00
|
|
|
return val ? parseInt(val) : null;
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2022-06-20 10:01:01 -04:00
|
|
|
/**
|
|
|
|
* Get or set 'Maximum video width'
|
|
|
|
* @param {number|undefined} val - Maximum video width or undefined.
|
|
|
|
* @return {number} Maximum video width.
|
|
|
|
*/
|
|
|
|
maxVideoWidth(val) {
|
|
|
|
if (val !== undefined) {
|
|
|
|
return this.set('maxVideoWidth', val.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseInt(this.get('maxVideoWidth') || '0', 10) || 0;
|
|
|
|
}
|
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
set(name, value, userId) {
|
|
|
|
const currentValue = this.get(name, userId);
|
|
|
|
AppStorage.setItem(this.#getKey(name, userId), value);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (currentValue !== value) {
|
2020-09-08 02:05:02 -04:00
|
|
|
Events.trigger(this, 'change', [name]);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
get(name, userId) {
|
|
|
|
return AppStorage.getItem(this.#getKey(name, userId));
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2020-10-18 18:58:09 +01:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
export default new AppSettings();
|