-
Notifications
You must be signed in to change notification settings - Fork 3
/
Settings.pm
112 lines (76 loc) · 2.81 KB
/
Settings.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package Plugins::LocalPlayer::Settings;
use strict;
use base qw(Slim::Web::Settings);
use Slim::Utils::Prefs;
my $prefs = preferences('plugin.localplayer');
sub name { 'PLUGIN_LOCALPLAYER' }
sub page { 'plugins/LocalPlayer/settings/basic.html' }
sub handler {
my ($class, $client, $params, $callback, @args) = @_;
my $update;
if ($params->{'saveSettings'}) {
# only set autorun if turning it on as other params are hidden and don't get returned
my @bool = $params->{'autorun'} && !$prefs->get('autorun') ? qw(autorun) : qw(autorun logging loc);
my @other = $params->{'autorun'} && !$prefs->get('autorun') ? () : qw(output bin debugs opts);
for my $param (@bool) {
my $val = $params->{ $param } ? 1 : 0;
if ($val != $prefs->get($param)) {
$prefs->set($param, $val);
$update = 1 unless $param eq 'loc';
if ($param eq 'autorun') {
require Plugins::LocalPlayer::Squeezelite;
}
if ($param eq 'loc' && $params->{ $param }) {
require Plugins::LocalPlayer::LocalFile;
Slim::Player::ProtocolHandlers->registerHandler('file', 'Plugins::LocalPlayer::LocalFile');
}
}
}
for my $param (@other) {
if ($params->{ $param } ne $prefs->get($param)) {
$prefs->set($param, $params->{ $param });
$update = 1;
}
}
}
if ($update) {
$prefs->get('autorun') ? Plugins::LocalPlayer::Squeezelite->restart : Plugins::LocalPlayer::Squeezelite->stop;
Slim::Utils::Timers::setTimer($class, Time::HiRes::time() + 1, sub {
$class->handler2( $client, $params, $callback, @args);
});
} else {
$class->handler2( $client, $params, $callback, @args);
}
return undef;
}
sub handler2 {
my ($class, $client, $params, $callback, @args) = @_;
if ($prefs->get('autorun')) {
my $bin = Plugins::LocalPlayer::Squeezelite->bin;
$params->{'binary'} = $bin;
$params->{'binaries'} = [ Plugins::LocalPlayer::Squeezelite->binaries('update') ];
$params->{'running'} = Plugins::LocalPlayer::Squeezelite->alive;
if (my $path = Slim::Utils::Misc::findbin($bin)) {
if (my $options = `$path -?`) {
# extract descriptions for server address, name, and MAC address
while ($options =~ /(^\s+-[smn]\s+.+\n)/mg) {
$params->{'optionsTable'} .= $1;
}
}
}
my $devices = Plugins::LocalPlayer::Squeezelite->devices;
unshift @$devices, { name => '', desc => "Default" };
$params->{'devices'} = $devices;
} else {
$params->{'running'} = 0;
}
for my $param (qw(autorun output bin opts debugs logging loc)) {
$params->{ $param } = $prefs->get($param);
}
my $osDetails = Slim::Utils::OSDetect::details();
$params->{'isDocker'} = $osDetails->{osName} =~ /Docker/ ? 1 : 0;
$params->{'isPCP'} = Plugins::LocalPlayer::Plugin::isPCP();
$params->{'arch'} = Slim::Utils::OSDetect::OS();
$callback->($client, $params, $class->SUPER::handler($client, $params), @args);
}
1;