PlayerSettings.pm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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);
  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. }
  47. # as there is nothing captured, we need to re-set these variables
  48. $paramRef->{'pref_width'} = $cprefs->get('width');
  49. # here I don't know why you need to set again spectrum which is a reference
  50. # to a hash. Using $paramRef->{prefs} does not work either. It seems that
  51. # some are copies of value, some are references, can't figure out. This whole
  52. # logic of "Settings" is beyond me and I really hate it
  53. $paramRef->{'pref_spectrum'} = $cprefs->get('spectrum');
  54. $paramRef->{'pref_artwork'} = $cprefs->get('artwork');
  55. return $class->SUPER::handler($client, $paramRef);
  56. }
  57. 1;