PlayerSettings.pm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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' && $client->displayWidth;
  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 = qw(width small_VU spectrum artwork eq);
  26. return ($prefs->client($client), @prefs);
  27. }
  28. sub handler {
  29. my ($class, $client, $paramRef) = @_;
  30. my ($cprefs, @prefs) = $class->prefs($client);
  31. if ($paramRef->{'saveSettings'}) {
  32. $cprefs->set('small_VU', $paramRef->{'pref_small_VU'});
  33. my $spectrum = { scale => $paramRef->{'pref_spectrum_scale'},
  34. small => { size => $paramRef->{'pref_spectrum_small_size'},
  35. band => $paramRef->{'pref_spectrum_small_band'} },
  36. full => { band => $paramRef->{'pref_spectrum_full_band'} },
  37. };
  38. $cprefs->set('spectrum', $spectrum);
  39. my $artwork = { enable => $paramRef->{'pref_artwork_enable'},
  40. x => $paramRef->{'pref_artwork_x'},
  41. y => $paramRef->{'pref_artwork_y'},
  42. };
  43. $cprefs->set('artwork', $artwork);
  44. $client->display->modes($client->display->build_modes);
  45. $client->display->update;
  46. my $eq = $cprefs->get('eq');
  47. for my $i (0 .. $#{$eq}) {
  48. $eq->[$i] = $paramRef->{"pref_eq.$i"};
  49. }
  50. $cprefs->set('eq', $eq);
  51. Plugins::SqueezeESP32::Plugin::send_equalizer($client);
  52. # force update or disable artwork
  53. if ($artwork->{'enable'}) {
  54. Plugins::SqueezeESP32::Plugin::update_artwork($client, 1);
  55. } else {
  56. Plugins::SqueezeESP32::Plugin::config_artwork($client);
  57. }
  58. }
  59. # as there is nothing captured, we need to re-set these variables
  60. $paramRef->{'pref_width'} = $cprefs->get('width');
  61. # here I don't know why you need to set again spectrum which is a reference
  62. # to a hash. Using $paramRef->{prefs} does not work either. It seems that
  63. # some are copies of value, some are references, can't figure out. This whole
  64. # logic of "Settings" is beyond me and I really hate it
  65. $paramRef->{'pref_spectrum'} = $cprefs->get('spectrum');
  66. $paramRef->{'pref_artwork'} = $cprefs->get('artwork');
  67. $paramRef->{'pref_eq'} = $cprefs->get('eq');
  68. return $class->SUPER::handler($client, $paramRef);
  69. }
  70. 1;