Compare commits
3 Commits
93c786f9e3
...
fffbb5d5e0
Author | SHA1 | Date |
---|---|---|
John Mertz | fffbb5d5e0 | |
John Mertz | b0e1ead2b3 | |
John Mertz | 7e43f9f600 |
|
@ -56,7 +56,8 @@ sub new($class, %args)
|
|||
$args{im} = Image::Magick->new();
|
||||
$args{error} = ();
|
||||
|
||||
$args{pidfile} = "/tmp/$ENV{USER}-wallpaper.pid";
|
||||
$args{pidfile} = "$ENV{HOME}/.local/state/wallpaper.pid";
|
||||
$args{outputfile} = "$ENV{HOME}/.local/state/wallpaper_outputs";
|
||||
|
||||
return bless { %args };
|
||||
}
|
||||
|
@ -144,7 +145,6 @@ sub get_active($self)
|
|||
$self->do_log('LOG_WARNING',"No outputs detected.") unless (scalar(keys(%active)));
|
||||
return \%active;
|
||||
} else {
|
||||
print "You haven't initialized get_outputs";
|
||||
$self->do_log('LOG_WARNING',"Output list not defined yet. Try 'get_outputs()' first");
|
||||
return \{};
|
||||
}
|
||||
|
@ -251,23 +251,10 @@ sub do_log($self, $level, $msg, $die=0)
|
|||
{
|
||||
my $min = $self->{verbose} || 5;
|
||||
|
||||
# Journald is borked. Just don't bother logging
|
||||
return 0;
|
||||
if ($self->{daemon}) {
|
||||
#use Log::Journald qw(send);
|
||||
#send(
|
||||
#PRIORITY => ERROR->{$level},
|
||||
#MESSAGE => $msg,
|
||||
#PERL_PACKAGE => 'Sway Wallpapers'
|
||||
#) || warn "Could not send log ($level $msg): $!";
|
||||
if ($die) {
|
||||
$msg = '(FATAL) ' . $msg;
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
if (ERROR->{$level} >= $min) {
|
||||
printf("%11s %s\n", $level, $msg);
|
||||
}
|
||||
# Journald module is borked. Just print to STDOUT and SystemD will catch it
|
||||
$msg = '(FATAL) ' . $msg if ($die);
|
||||
if (ERROR->{$level} >= $min) {
|
||||
printf("%11s %s\n", $level, $msg);
|
||||
}
|
||||
if ($die) {
|
||||
$self->clean();
|
||||
|
@ -410,7 +397,7 @@ die "Invalid wallpaper path '$path'. Not a directory." if (defined($path) && !-d
|
|||
die "Invalid verbosity level: '$verbose'\n" if (defined($verbose) && $verbose !~ m/^[1-8]$/);
|
||||
|
||||
$wp->do_log("LOG_DEBUG", "Configuring object");
|
||||
$wp->{targets} = \@targets || undef;
|
||||
$wp->{targets} = \@targets || \();
|
||||
$wp->{daemon} = $daemon || 0;
|
||||
$wp->{path} = $path || "$ENV{HOME}/wallpapers";
|
||||
$wp->{crop} = $crop || 1;
|
||||
|
@ -419,6 +406,27 @@ $wp->{verbose} = $verbose || 0;
|
|||
$wp->{recursive}= $recursive;
|
||||
$wp->{error} = [];
|
||||
|
||||
unless(defined($wp->{targets})) {
|
||||
if (open(my $fh, '<', $wp->{outputfile})) {
|
||||
$wp->do_log("LOG_DEBUG", "No outputs requested, using cache file $wp->{outputfile}\n");
|
||||
while (my $o = <$fh>) {
|
||||
chomp($o);
|
||||
push (@{$wp->{targets}}, $o) if ($o);
|
||||
}
|
||||
$wp->do_log("LOG_DEBUG", "Found cached outputs: ".join(', ', @{$wp->{targets}})."\n") if (scalar(@{$wp->{targets}})."\n");
|
||||
} else {
|
||||
$wp->do_log("LOG_WARNING", "Failed to load $wp->{outputfile}\n");
|
||||
}
|
||||
unless (scalar(@{$wp->{targets}})) {
|
||||
$wp->{'targets'} = \$wp->get_outputs();
|
||||
if (scalar(@{$wp->{targets}})) {
|
||||
$wp->do_log("LOG_WARNING", "Using all available outputs ".join(', ', @{$wp->{targets}})."\n");
|
||||
} else {
|
||||
$wp->do_log("LOG_INFO", "Failed to discover any available outputs.\n", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Fork if daemonized
|
||||
################################################################################
|
||||
|
|
Loading…
Reference in New Issue