Files
new-phone-who-dis/phone/src/os/sound/utils/getSoundSettings.ts
T
Taso 6419245d93 Revert "feat(phone/settings): Add localStorage settings schema validation (#139)"
This reverts commit cb5a00e57e.
Reverted due a non-descript bug in CEF. Will be reapplied after fix.
2021-03-05 12:38:22 -05:00

32 lines
957 B
TypeScript

import { IPhoneSettings } from '../../../apps/settings/hooks/useSettings';
import { getNotificationPath, getRingtonePath } from '../../../apps/settings/utils/getRingtonePath';
const getPath = {
ringtone: getRingtonePath,
notiSound: getNotificationPath,
};
/**
* Gets the configuration for SoundProvider based on settings and apps
*/
export const getSoundSettings = (
type: 'ringtone' | 'notiSound',
settings: IPhoneSettings,
app?: string,
) => {
try {
return app
? {
sound: getPath[type](settings[`${app}_${type}`].value || settings[type].value),
volume: (settings[`${app}_${type}Vol`] || settings[`${type}Vol`]) / 100,
}
: {
sound: getPath[type](settings[type as string].value),
volume: settings[`${type}Vol`] / 100,
};
} catch (e) {
console.error('getSoundSettings.ts error', e, 'Using default sounds');
return { sound: getPath[type](), volume: 1 };
}
};