PlayerSettings.pm 2.3 KB

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