Skip to content

Commit

Permalink
Merge branch 'public/9.0' into public/9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelherger committed Dec 18, 2024
2 parents 48a1e77 + 08c392f commit 4f14736
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
6 changes: 6 additions & 0 deletions osx/MenuBarItem/LMSMenu.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"FR": "Démarrer le service",
"NL": "Service starten"
},
"SERVICE_STARTING": {
"DE": "Dienst wird gestartet...",
"EN": "Service is starting up...",
"FR": "Le service démarre...",
"NL": "De service begint..."
},
"AUTOSTART_ON": {
"DE": "✓ Dienst automatisch ausführen",
"EN": "✓ Run Service automatically",
Expand Down
40 changes: 38 additions & 2 deletions osx/MenuBarItem/LMSMenu.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ sub getPort {
return;
}

sub isProcessRunning {
return `ps -axww | grep "slimserver.pl" | grep -v grep`;
}

sub getUpdate {
my $updatesFile = getVersionFile();
my $update;
Expand Down Expand Up @@ -90,6 +94,36 @@ sub getString {
return $STRINGS->{$token}->{$lang} || $STRINGS->{$token}->{EN};
}

sub serverRequest {
my $port = shift;

my $postdata;
eval { $postdata = '{"id":1,"method":"slim.request","params":["",' . encode_json(\@_) . ']}' };

return if $@ || !$postdata;

require HTTP::Tiny;

HTTP::Tiny->new(
timeout => 2,
)->request('POST', "http://127.0.0.1:$port/jsonrpc.js", {
headers => {
'Content-Type' => 'application/json',
},
content => $postdata,
});

# Should we ever be interested in the result, uncomment the following lines:
# my $content = $res->{content} if $res->{success};
# if ($content) {
# eval {
# $content = decode_json($content);
# }
# }

# return $content;
}

sub printMenuItem {
my ($token, $icon) = @_;
$icon = "MENUITEMICON|$icon|" if $icon;
Expand All @@ -110,15 +144,17 @@ sub getPrefPane {
? 'AUTOSTART_ON'
: 'AUTOSTART_OFF';

if (getPort()) {
if (my $port = getPort()) {
printMenuItem('OPEN_GUI');
printMenuItem('OPEN_SETTINGS');
print("----\n");
printMenuItem('STOP_SERVICE');
printMenuItem($autoStartItem);

serverRequest($port, 'pref', 'macMenuItemActive', time());
}
else {
printMenuItem('START_SERVICE');
printMenuItem(isProcessRunning() ? 'SERVICE_STARTING' : 'START_SERVICE');
printMenuItem($autoStartItem);
}

Expand Down
3 changes: 3 additions & 0 deletions osx/MenuBarItem/LMSMenuAction.pm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ sub handleAction {
elsif ($item eq 'UNINSTALL_PREFPANE') {
system("open https://lyrion.org/reference/uninstall-legacy-mac/");
}
elsif ($item eq 'SERVICE_STARTING') {
# nothing to do here...
}
else {
my $x = unidecode(join(' ', @ARGV));
print "ALERT:Selected Item...|$item $x\n";
Expand Down

0 comments on commit 4f14736

Please sign in to comment.