Use appSettings for SyncPlay settings
This commit is contained in:
parent
938c01a72a
commit
74bff4f896
5 changed files with 53 additions and 75 deletions
|
@ -6,7 +6,7 @@
|
||||||
import { Events } from 'jellyfin-apiclient';
|
import { Events } from 'jellyfin-apiclient';
|
||||||
import { toBoolean, toFloat } from '../../../scripts/stringUtils';
|
import { toBoolean, toFloat } from '../../../scripts/stringUtils';
|
||||||
import * as Helper from './Helper';
|
import * as Helper from './Helper';
|
||||||
import Settings from './Settings';
|
import { getSetting } from './Settings';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that manages the playback of SyncPlay.
|
* Class that manages the playback of SyncPlay.
|
||||||
|
@ -39,7 +39,7 @@ class PlaybackCore {
|
||||||
this.manager = syncPlayManager;
|
this.manager = syncPlayManager;
|
||||||
this.timeSyncCore = syncPlayManager.getTimeSyncCore();
|
this.timeSyncCore = syncPlayManager.getTimeSyncCore();
|
||||||
|
|
||||||
Events.on(Settings, 'update', () => {
|
Events.on(this.manager, 'settings-update', () => {
|
||||||
this.loadPreferences();
|
this.loadPreferences();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -49,25 +49,25 @@ class PlaybackCore {
|
||||||
*/
|
*/
|
||||||
loadPreferences() {
|
loadPreferences() {
|
||||||
// Minimum required delay for SpeedToSync to kick in, in milliseconds.
|
// Minimum required delay for SpeedToSync to kick in, in milliseconds.
|
||||||
this.minDelaySpeedToSync = toFloat(Settings.get('minDelaySpeedToSync'), 60.0);
|
this.minDelaySpeedToSync = toFloat(getSetting('minDelaySpeedToSync'), 60.0);
|
||||||
|
|
||||||
// Maximum delay after which SkipToSync is used instead of SpeedToSync, in milliseconds.
|
// Maximum delay after which SkipToSync is used instead of SpeedToSync, in milliseconds.
|
||||||
this.maxDelaySpeedToSync = toFloat(Settings.get('maxDelaySpeedToSync'), 3000.0);
|
this.maxDelaySpeedToSync = toFloat(getSetting('maxDelaySpeedToSync'), 3000.0);
|
||||||
|
|
||||||
// Time during which the playback is sped up, in milliseconds.
|
// Time during which the playback is sped up, in milliseconds.
|
||||||
this.speedToSyncDuration = toFloat(Settings.get('speedToSyncDuration'), 1000.0);
|
this.speedToSyncDuration = toFloat(getSetting('speedToSyncDuration'), 1000.0);
|
||||||
|
|
||||||
// Minimum required delay for SkipToSync to kick in, in milliseconds.
|
// Minimum required delay for SkipToSync to kick in, in milliseconds.
|
||||||
this.minDelaySkipToSync = toFloat(Settings.get('minDelaySkipToSync'), 400.0);
|
this.minDelaySkipToSync = toFloat(getSetting('minDelaySkipToSync'), 400.0);
|
||||||
|
|
||||||
// Whether SpeedToSync should be used.
|
// Whether SpeedToSync should be used.
|
||||||
this.useSpeedToSync = toBoolean(Settings.get('useSpeedToSync'), true);
|
this.useSpeedToSync = toBoolean(getSetting('useSpeedToSync'), true);
|
||||||
|
|
||||||
// Whether SkipToSync should be used.
|
// Whether SkipToSync should be used.
|
||||||
this.useSkipToSync = toBoolean(Settings.get('useSkipToSync'), true);
|
this.useSkipToSync = toBoolean(getSetting('useSkipToSync'), true);
|
||||||
|
|
||||||
// Whether sync correction during playback is active.
|
// Whether sync correction during playback is active.
|
||||||
this.enableSyncCorrection = toBoolean(Settings.get('enableSyncCorrection'), true);
|
this.enableSyncCorrection = toBoolean(getSetting('enableSyncCorrection'), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,51 +2,27 @@
|
||||||
* Module that manages SyncPlay settings.
|
* Module that manages SyncPlay settings.
|
||||||
* @module components/syncPlay/core/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 {
|
const PREFIX = 'syncPlay';
|
||||||
constructor() {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the key used to store a setting in the App Storage.
|
* Gets the value of a setting.
|
||||||
* @param {string} name The name of the setting.
|
* @param {string} name The name of the setting.
|
||||||
* @returns {string} The key.
|
* @returns {string} The value.
|
||||||
*/
|
*/
|
||||||
getKey(name) {
|
export function getSetting(name) {
|
||||||
return 'syncPlay-' + name;
|
return appSettings.get(name, PREFIX);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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}'.`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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);
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import * as Helper from './Helper';
|
import * as Helper from './Helper';
|
||||||
import Settings from './Settings';
|
|
||||||
import ManagerClass from './Manager';
|
import ManagerClass from './Manager';
|
||||||
import PlayerFactoryClass from './players/PlayerFactory';
|
import PlayerFactoryClass from './players/PlayerFactory';
|
||||||
import GenericPlayer from './players/GenericPlayer';
|
import GenericPlayer from './players/GenericPlayer';
|
||||||
|
@ -9,7 +8,6 @@ const Manager = new ManagerClass(PlayerFactory);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Helper,
|
Helper,
|
||||||
Settings,
|
|
||||||
Manager,
|
Manager,
|
||||||
PlayerFactory,
|
PlayerFactory,
|
||||||
Players: {
|
Players: {
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Events } from 'jellyfin-apiclient';
|
import { Events } from 'jellyfin-apiclient';
|
||||||
|
import appSettings from '../../../../scripts/settings/appSettings';
|
||||||
import { toFloat } from '../../../../scripts/stringUtils';
|
import { toFloat } from '../../../../scripts/stringUtils';
|
||||||
import Settings from '../Settings';
|
import { getSetting } from '../Settings';
|
||||||
import TimeSyncServer from './TimeSyncServer';
|
import TimeSyncServer from './TimeSyncServer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,8 +27,8 @@ class TimeSyncCore {
|
||||||
this.manager = null;
|
this.manager = null;
|
||||||
this.timeSyncServer = null;
|
this.timeSyncServer = null;
|
||||||
|
|
||||||
this.timeSyncDeviceId = Settings.get('timeSyncDevice') || 'server';
|
this.timeSyncDeviceId = getSetting('timeSyncDevice') || 'server';
|
||||||
this.extraTimeOffset = toFloat(Settings.get('extraTimeOffset'), 0.0);
|
this.extraTimeOffset = toFloat(getSetting('extraTimeOffset'), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,8 +48,10 @@ class TimeSyncCore {
|
||||||
Events.trigger(this, 'time-sync-server-update', [timeOffset, ping]);
|
Events.trigger(this, 'time-sync-server-update', [timeOffset, ping]);
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.on(Settings, 'extraTimeOffset', () => {
|
Events.on(appSettings, 'change', function (e, name) {
|
||||||
this.extraTimeOffset = toFloat(Settings.get('extraTimeOffset'), 0.0);
|
if (name === 'extraTimeOffset') {
|
||||||
|
this.extraTimeOffset = toFloat(getSetting('extraTimeOffset'), 0.0);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
import { Events } from 'jellyfin-apiclient';
|
import { Events } from 'jellyfin-apiclient';
|
||||||
import SyncPlay from '../../core';
|
import SyncPlay from '../../core';
|
||||||
|
import { getSetting, setSetting } from '../../core/Settings';
|
||||||
import dialogHelper from '../../../dialogHelper/dialogHelper';
|
import dialogHelper from '../../../dialogHelper/dialogHelper';
|
||||||
import layoutManager from '../../../layoutManager';
|
import layoutManager from '../../../layoutManager';
|
||||||
import loading from '../../../loading/loading';
|
import loading from '../../../loading/loading';
|
||||||
|
@ -95,14 +96,14 @@ class SettingsEditor {
|
||||||
async initEditor() {
|
async initEditor() {
|
||||||
const { context } = this;
|
const { context } = this;
|
||||||
|
|
||||||
context.querySelector('#txtExtraTimeOffset').value = toFloat(SyncPlay.Settings.get('extraTimeOffset'), 0.0);
|
context.querySelector('#txtExtraTimeOffset').value = toFloat(getSetting('extraTimeOffset'), 0.0);
|
||||||
context.querySelector('#chkSyncCorrection').checked = toBoolean(SyncPlay.Settings.get('enableSyncCorrection'), true);
|
context.querySelector('#chkSyncCorrection').checked = toBoolean(getSetting('enableSyncCorrection'), true);
|
||||||
context.querySelector('#txtMinDelaySpeedToSync').value = toFloat(SyncPlay.Settings.get('minDelaySpeedToSync'), 60.0);
|
context.querySelector('#txtMinDelaySpeedToSync').value = toFloat(getSetting('minDelaySpeedToSync'), 60.0);
|
||||||
context.querySelector('#txtMaxDelaySpeedToSync').value = toFloat(SyncPlay.Settings.get('maxDelaySpeedToSync'), 3000.0);
|
context.querySelector('#txtMaxDelaySpeedToSync').value = toFloat(getSetting('maxDelaySpeedToSync'), 3000.0);
|
||||||
context.querySelector('#txtSpeedToSyncDuration').value = toFloat(SyncPlay.Settings.get('speedToSyncDuration'), 1000.0);
|
context.querySelector('#txtSpeedToSyncDuration').value = toFloat(getSetting('speedToSyncDuration'), 1000.0);
|
||||||
context.querySelector('#txtMinDelaySkipToSync').value = toFloat(SyncPlay.Settings.get('minDelaySkipToSync'), 400.0);
|
context.querySelector('#txtMinDelaySkipToSync').value = toFloat(getSetting('minDelaySkipToSync'), 400.0);
|
||||||
context.querySelector('#chkSpeedToSync').checked = toBoolean(SyncPlay.Settings.get('useSpeedToSync'), true);
|
context.querySelector('#chkSpeedToSync').checked = toBoolean(getSetting('useSpeedToSync'), true);
|
||||||
context.querySelector('#chkSkipToSync').checked = toBoolean(SyncPlay.Settings.get('useSkipToSync'), true);
|
context.querySelector('#chkSkipToSync').checked = toBoolean(getSetting('useSkipToSync'), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
|
@ -130,16 +131,16 @@ class SettingsEditor {
|
||||||
const useSpeedToSync = context.querySelector('#chkSpeedToSync').checked;
|
const useSpeedToSync = context.querySelector('#chkSpeedToSync').checked;
|
||||||
const useSkipToSync = context.querySelector('#chkSkipToSync').checked;
|
const useSkipToSync = context.querySelector('#chkSkipToSync').checked;
|
||||||
|
|
||||||
SyncPlay.Settings.set('extraTimeOffset', extraTimeOffset);
|
setSetting('extraTimeOffset', extraTimeOffset);
|
||||||
SyncPlay.Settings.set('enableSyncCorrection', syncCorrection);
|
setSetting('enableSyncCorrection', syncCorrection);
|
||||||
SyncPlay.Settings.set('minDelaySpeedToSync', minDelaySpeedToSync);
|
setSetting('minDelaySpeedToSync', minDelaySpeedToSync);
|
||||||
SyncPlay.Settings.set('maxDelaySpeedToSync', maxDelaySpeedToSync);
|
setSetting('maxDelaySpeedToSync', maxDelaySpeedToSync);
|
||||||
SyncPlay.Settings.set('speedToSyncDuration', speedToSyncDuration);
|
setSetting('speedToSyncDuration', speedToSyncDuration);
|
||||||
SyncPlay.Settings.set('minDelaySkipToSync', minDelaySkipToSync);
|
setSetting('minDelaySkipToSync', minDelaySkipToSync);
|
||||||
SyncPlay.Settings.set('useSpeedToSync', useSpeedToSync);
|
setSetting('useSpeedToSync', useSpeedToSync);
|
||||||
SyncPlay.Settings.set('useSkipToSync', useSkipToSync);
|
setSetting('useSkipToSync', useSkipToSync);
|
||||||
|
|
||||||
Events.trigger(SyncPlay.Settings, 'update');
|
Events.trigger(SyncPlay.Manager, 'settings-update');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue