2020-04-03 03:20:06 +09:00
|
|
|
/* eslint-disable indent */
|
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
import appSettings from 'appSettings';
|
|
|
|
import events from 'events';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function onSaveTimeout() {
|
2019-11-30 10:51:24 +09:00
|
|
|
var self = this;
|
|
|
|
self.saveTimeout = null;
|
|
|
|
self.currentApiClient.updateDisplayPreferences('usersettings', self.displayPrefs, self.currentUserId, 'emby');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveServerPreferences(instance) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (instance.saveTimeout) {
|
|
|
|
clearTimeout(instance.saveTimeout);
|
|
|
|
}
|
2019-11-26 03:15:23 +09:00
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
instance.saveTimeout = setTimeout(onSaveTimeout.bind(instance), 50);
|
|
|
|
}
|
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function setUserInfo(userId, apiClient) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (this.saveTimeout) {
|
|
|
|
clearTimeout(this.saveTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.currentUserId = userId;
|
|
|
|
this.currentApiClient = apiClient;
|
|
|
|
|
|
|
|
if (!userId) {
|
|
|
|
this.displayPrefs = null;
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var self = this;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return apiClient.getDisplayPreferences('usersettings', userId, 'emby').then(function (result) {
|
|
|
|
result.CustomPrefs = result.CustomPrefs || {};
|
|
|
|
self.displayPrefs = result;
|
|
|
|
});
|
2020-04-04 00:09:47 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function getData() {
|
2019-01-10 15:39:37 +03:00
|
|
|
return this.displayPrefs;
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function importFrom(instance) {
|
2019-01-10 15:39:37 +03:00
|
|
|
this.displayPrefs = instance.getData();
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function set(name, value, enableOnServer) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var userId = this.currentUserId;
|
2019-01-10 15:39:37 +03:00
|
|
|
var currentValue = this.get(name, enableOnServer);
|
2019-11-26 03:15:23 +09:00
|
|
|
var result = appSettings.set(name, value, userId);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (enableOnServer !== false && this.displayPrefs) {
|
|
|
|
this.displayPrefs.CustomPrefs[name] = value == null ? value : value.toString();
|
|
|
|
saveServerPreferences(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentValue !== value) {
|
|
|
|
events.trigger(this, 'change', [name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function get(name, enableOnServer) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var userId = this.currentUserId;
|
2019-12-03 23:06:33 +09:00
|
|
|
if (enableOnServer !== false && this.displayPrefs) {
|
|
|
|
return this.displayPrefs.CustomPrefs[name];
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2019-11-26 03:15:23 +09:00
|
|
|
return appSettings.get(name, userId);
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function serverConfig(config) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var apiClient = this.currentApiClient;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (config) {
|
|
|
|
return apiClient.updateUserConfiguration(this.currentUserId, config);
|
|
|
|
}
|
2019-11-26 03:15:23 +09:00
|
|
|
|
|
|
|
return apiClient.getUser(this.currentUserId).then(function (user) {
|
|
|
|
return user.Configuration;
|
|
|
|
});
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function enableCinemaMode(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('enableCinemaMode', val.toString(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
val = this.get('enableCinemaMode', false);
|
2019-11-26 03:15:23 +09:00
|
|
|
return val !== 'false';
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function enableNextVideoInfoOverlay(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('enableNextVideoInfoOverlay', val.toString());
|
|
|
|
}
|
|
|
|
|
2019-11-26 03:15:23 +09:00
|
|
|
val = this.get('enableNextVideoInfoOverlay', false);
|
2019-01-10 15:39:37 +03:00
|
|
|
return val !== 'false';
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function enableThemeSongs(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('enableThemeSongs', val.toString(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
val = this.get('enableThemeSongs', false);
|
|
|
|
return val !== 'false';
|
2020-04-04 00:09:47 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function enableThemeVideos(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('enableThemeVideos', val.toString(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
val = this.get('enableThemeVideos', false);
|
2019-11-26 03:15:23 +09:00
|
|
|
return val !== 'false';
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function enableFastFadein(val) {
|
2020-01-26 15:32:13 +01:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('fastFadein', val.toString(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
val = this.get('fastFadein', false);
|
|
|
|
return val !== 'false';
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2020-01-26 15:32:13 +01:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function enableBackdrops(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('enableBackdrops', val.toString(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
val = this.get('enableBackdrops', false);
|
2019-11-26 03:15:23 +09:00
|
|
|
return val !== 'false';
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function language(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('language', val.toString(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.get('language', false);
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function dateTimeLocale(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('datetimelocale', val.toString(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.get('datetimelocale', false);
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function skipBackLength(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('skipBackLength', val.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseInt(this.get('skipBackLength') || '10000');
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function skipForwardLength(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('skipForwardLength', val.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseInt(this.get('skipForwardLength') || '30000');
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function dashboardTheme(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('dashboardTheme', val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.get('dashboardTheme');
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function skin(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('skin', val, false);
|
|
|
|
}
|
|
|
|
|
2019-11-26 03:15:23 +09:00
|
|
|
return this.get('skin', false);
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function theme(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('appTheme', val, false);
|
|
|
|
}
|
|
|
|
|
2019-11-26 03:15:23 +09:00
|
|
|
return this.get('appTheme', false);
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function screensaver(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('screensaver', val, false);
|
|
|
|
}
|
|
|
|
|
2019-11-26 03:15:23 +09:00
|
|
|
return this.get('screensaver', false);
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function soundEffects(val) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (val != null) {
|
|
|
|
return this.set('soundeffects', val, false);
|
|
|
|
}
|
|
|
|
|
2019-11-26 03:15:23 +09:00
|
|
|
return this.get('soundeffects', false);
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function loadQuerySettings(key, query) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var values = this.get(key);
|
2019-01-10 15:39:37 +03:00
|
|
|
if (values) {
|
|
|
|
values = JSON.parse(values);
|
|
|
|
return Object.assign(query, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
return query;
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function saveQuerySettings(key, query) {
|
2018-10-23 01:05:09 +03:00
|
|
|
var values = {};
|
2019-01-10 15:39:37 +03:00
|
|
|
if (query.SortBy) {
|
|
|
|
values.SortBy = query.SortBy;
|
|
|
|
}
|
2019-11-26 03:15:23 +09:00
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
if (query.SortOrder) {
|
|
|
|
values.SortOrder = query.SortOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.set(key, JSON.stringify(values));
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function getSubtitleAppearanceSettings(key) {
|
2019-01-10 15:39:37 +03:00
|
|
|
key = key || 'localplayersubtitleappearance3';
|
|
|
|
return JSON.parse(this.get(key, false) || '{}');
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function setSubtitleAppearanceSettings(value, key) {
|
2019-01-10 15:39:37 +03:00
|
|
|
key = key || 'localplayersubtitleappearance3';
|
|
|
|
return this.set(key, JSON.stringify(value), false);
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function setFilter(key, value) {
|
2019-01-10 15:39:37 +03:00
|
|
|
return this.set(key, value, true);
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function getFilter(key) {
|
2019-01-10 15:39:37 +03:00
|
|
|
return this.get(key, true);
|
2020-04-03 23:19:20 +09:00
|
|
|
}
|