PlayerSettings.pm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package Plugins::SqueezeESP32::PlayerSettings;
  2. use strict;
  3. use base qw(Slim::Web::Settings);
  4. use List::Util qw(first);
  5. use Slim::Utils::Log;
  6. use Slim::Utils::Prefs;
  7. my $sprefs = preferences('server');
  8. my $prefs = preferences('plugin.squeezeesp32');
  9. my $log = logger('plugin.squeezeesp32');
  10. sub name {
  11. return Slim::Web::HTTP::CSRF->protectName('PLUGIN_SQUEEZEESP32_PLAYERSETTINGS');
  12. }
  13. sub needsClient {
  14. return 1;
  15. }
  16. sub validFor {
  17. my ($class, $client) = @_;
  18. return $client->model eq 'squeezeesp32';
  19. }
  20. sub page {
  21. return Slim::Web::HTTP::CSRF->protectURI('plugins/SqueezeESP32/settings/player.html');
  22. }
  23. sub prefs {
  24. my ($class, $client) = @_;
  25. my @prefs;
  26. push @prefs, qw(width small_VU) if $client->displayWidth;
  27. return ($prefs->client($client), @prefs);
  28. }
  29. sub handler {
  30. my ($class, $client, $paramRef) = @_;
  31. my ($cprefs, @prefs) = $class->prefs($client);
  32. if ($paramRef->{'saveSettings'}) {
  33. if ($client->displayWidth) {
  34. $cprefs->set('small_VU', $paramRef->{'pref_small_VU'} || 15);
  35. my $spectrum = {
  36. scale => $paramRef->{'pref_spectrum_scale'} || 25,
  37. small => { size => $paramRef->{'pref_spectrum_small_size'} || 25,
  38. band => $paramRef->{'pref_spectrum_small_band'} || 5.33 },
  39. full => { band => $paramRef->{'pref_spectrum_full_band'} } || 8,
  40. };
  41. $cprefs->set('spectrum', $spectrum);
  42. my $artwork = {
  43. enable => $paramRef->{'pref_artwork_enable'},
  44. x => $paramRef->{'pref_artwork_x'} || 0,
  45. y => $paramRef->{'pref_artwork_y'} || 0,
  46. };
  47. $cprefs->set('artwork', $artwork);
  48. $client->display->modes($client->display->build_modes);
  49. $client->display->update;
  50. # force update or disable artwork
  51. if ($artwork->{'enable'}) {
  52. $client->update_artwork(1);
  53. } else {
  54. $client->config_artwork();
  55. }
  56. }
  57. my $equalizer = $cprefs->get('equalizer');
  58. for my $i (0 .. $#{$equalizer}) {
  59. $equalizer->[$i] = $paramRef->{"pref_equalizer.$i"} || 0;
  60. }
  61. $cprefs->set('equalizer', $equalizer);
  62. $client->update_tones($equalizer);
  63. }
  64. if ($client->displayWidth) {
  65. # the Settings super class can't handle anything but scalar values
  66. # we need to populate the $paramRef for the other prefs manually
  67. $paramRef->{'pref_spectrum'} = $cprefs->get('spectrum');
  68. $paramRef->{'pref_artwork'} = $cprefs->get('artwork');
  69. }
  70. $paramRef->{'pref_equalizer'} = $cprefs->get('equalizer');
  71. return $class->SUPER::handler($client, $paramRef);
  72. }
  73. 1;