1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/scripts/settings/appSettings.js

99 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-04-03 03:20:06 +09:00
/* eslint-disable indent */
2020-09-08 02:05:02 -04:00
import { AppStorage, Events } from 'jellyfin-apiclient';
2018-10-23 01:05:09 +03:00
2020-10-18 18:58:09 +01:00
class AppSettings {
#getKey(name, userId) {
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());
}
2020-10-18 18:58:09 +01:00
return this.get('enableAutoLogin') !== 'false';
2020-04-03 03:16:06 +09: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-10-18 18:58:09 +01:00
return this.get('enableSystemExternalPlayers') === 'true';
2020-04-03 03:16:06 +09:00
}
2020-10-18 18:58:09 +01:00
enableAutomaticBitrateDetection(isInNetwork, mediaType, val) {
const key = 'enableautobitratebitrate-' + mediaType + '-' + isInNetwork;
2020-04-26 16:49:21 +02:00
if (val !== undefined) {
if (isInNetwork && mediaType === 'Audio') {
val = true;
}
2020-10-18 18:58:09 +01:00
this.set(key, val.toString());
}
if (isInNetwork && mediaType === 'Audio') {
return true;
} else {
2020-10-18 18:58:09 +01:00
return this.get(key) !== 'false';
}
2020-04-03 03:16:06 +09:00
}
2020-10-18 18:58:09 +01:00
maxStreamingBitrate(isInNetwork, mediaType, val) {
const key = 'maxbitrate-' + mediaType + '-' + isInNetwork;
2020-04-26 16:49:21 +02:00
if (val !== undefined) {
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);
}
}
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;
}
2020-04-03 03:16:06 +09: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);
}
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
}
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);
}
2020-10-18 18:58:09 +01:00
val = this.get('chromecastBitrate1');
return val ? parseInt(val) : null;
2020-04-03 03:16:06 +09:00
}
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);
if (currentValue !== value) {
2020-09-08 02:05:02 -04:00
Events.trigger(this, 'change', [name]);
}
2020-04-03 03:16:06 +09: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
}
2020-04-09 00:36:44 +09:00
/* eslint-enable indent */
2020-10-18 18:58:09 +01:00
export default new AppSettings();