Load cached outputs if none given
Fallback to all available outputs
This commit is contained in:
parent
b0e1ead2b3
commit
fffbb5d5e0
|
@ -57,6 +57,7 @@ sub new($class, %args)
|
|||
$args{error} = ();
|
||||
|
||||
$args{pidfile} = "$ENV{HOME}/.local/state/wallpaper.pid";
|
||||
$args{outputfile} = "$ENV{HOME}/.local/state/wallpaper_outputs";
|
||||
|
||||
return bless { %args };
|
||||
}
|
||||
|
@ -396,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;
|
||||
|
@ -405,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