PlayerSettings.pm 2.7 KB

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