Use appSettings for SyncPlay settings
This commit is contained in:
parent
938c01a72a
commit
74bff4f896
5 changed files with 53 additions and 75 deletions
|
@ -2,51 +2,27 @@
|
|||
* Module that manages SyncPlay settings.
|
||||
* @module components/syncPlay/core/Settings
|
||||
*/
|
||||
import { Events, AppStorage } from 'jellyfin-apiclient';
|
||||
import appSettings from '../../../scripts/settings/appSettings';
|
||||
|
||||
/**
|
||||
* Class that manages SyncPlay settings.
|
||||
* Prefix used when saving SyncPlay settings.
|
||||
*/
|
||||
class SyncPlaySettings {
|
||||
constructor() {
|
||||
// Do nothing
|
||||
}
|
||||
const PREFIX = 'syncPlay';
|
||||
|
||||
/**
|
||||
* Gets the key used to store a setting in the App Storage.
|
||||
* @param {string} name The name of the setting.
|
||||
* @returns {string} The key.
|
||||
*/
|
||||
getKey(name) {
|
||||
return 'syncPlay-' + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of a setting.
|
||||
* @param {string} name The name of the setting.
|
||||
* @returns {string} The value.
|
||||
*/
|
||||
get(name) {
|
||||
return AppStorage.getItem(this.getKey(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a setting. Triggers an update if the new value differs from the old one.
|
||||
* @param {string} name The name of the setting.
|
||||
* @param {Object} value The value of the setting.
|
||||
*/
|
||||
set(name, value) {
|
||||
const oldValue = this.get(name);
|
||||
AppStorage.setItem(this.getKey(name), value);
|
||||
const newValue = this.get(name);
|
||||
|
||||
if (oldValue !== newValue) {
|
||||
Events.trigger(this, name, [newValue, oldValue]);
|
||||
}
|
||||
|
||||
console.debug(`SyncPlay Settings set: '${name}' from '${oldValue}' to '${newValue}'.`);
|
||||
}
|
||||
/**
|
||||
* Gets the value of a setting.
|
||||
* @param {string} name The name of the setting.
|
||||
* @returns {string} The value.
|
||||
*/
|
||||
export function getSetting(name) {
|
||||
return appSettings.get(name, PREFIX);
|
||||
}
|
||||
|
||||
/** SyncPlaySettings singleton. */
|
||||
export default new SyncPlaySettings();
|
||||
/**
|
||||
* Sets the value of a setting. Triggers an update if the new value differs from the old one.
|
||||
* @param {string} name The name of the setting.
|
||||
* @param {Object} value The value of the setting.
|
||||
*/
|
||||
export function setSetting(name, value) {
|
||||
return appSettings.set(name, value, PREFIX);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue