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) {
|
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
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
return this.get('enableAutoLogin') !== 'false';
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +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
|
|
|
}
|
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
return this.get('enableSystemExternalPlayers') === 'true';
|
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 {
|
2020-10-18 18:58:09 +01:00
|
|
|
return this.get(key) !== 'false';
|
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
|
|
|
|
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-04-09 00:36:44 +09:00
|
|
|
/* eslint-enable indent */
|
|
|
|
|
2020-10-18 18:58:09 +01:00
|
|
|
export default new AppSettings();
|