PlayerSettings.pm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 = qw(width small_VU spectrum);
  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. $client->display->modes($client->display->build_modes);
  40. $client->display->update;
  41. }
  42. # as there is nothing captured, we need to re-set these variables
  43. $paramRef->{'pref_width'} = $cprefs->get('width');
  44. # here I don't know why you need to set again spectrum which is a reference
  45. # to a hash. Using $paramRef->{prefs} does not work either. It seems that
  46. # soem are copies of value, some are references, can't figure out.This whole
  47. # logic of "Settings" is beyond me and I really hate it
  48. $paramRef->{'pref_spectrum'} = $cprefs->get('spectrum');
  49. return $class->SUPER::handler($client, $paramRef);
  50. }
  51. 1;