diff options
author | qkzk <qu3nt1n@gmail.com> | 2023-09-27 15:26:38 +0200 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2023-09-27 15:26:38 +0200 |
commit | 49c02b3262cb51934e54c4727f77e72d82dc1ce2 (patch) | |
tree | a9fcbe191537a63e02c027681827633a45d3b3b8 | |
parent | 8ebe8ff18bd1174f0939ef4a0c2de93498ef69d0 (diff) |
nitrogen must be installed to set a wallpaper
-rw-r--r-- | development.md | 1 | ||||
-rw-r--r-- | src/constant_strings_paths.rs | 2 | ||||
-rw-r--r-- | src/event_exec.rs | 14 | ||||
-rw-r--r-- | src/preview.rs | 4 |
4 files changed, 19 insertions, 2 deletions
diff --git a/development.md b/development.md index c86061e..a076a69 100644 --- a/development.md +++ b/development.md @@ -520,6 +520,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally. - [x] FIX: MOCP print error message on screen - [x] cryptdevice requires lsblk & cryptdevice. Display a message if not installed - [x] mocp must be installed to run relatives commands +- [x] nitrogen must be installed to set a wallpaper ## TODO diff --git a/src/constant_strings_paths.rs b/src/constant_strings_paths.rs index 4d8031b..eb609c2 100644 --- a/src/constant_strings_paths.rs +++ b/src/constant_strings_paths.rs @@ -154,3 +154,5 @@ pub const RENAME_LINES: [&str; 3] = [ ]; /// Executable commands whose output is a text to be displayed in terminal pub const CLI_INFO_COMMANDS: [&str; 4] = ["duf", "inxi -v 2 --color", "neofetch", "lsusb"]; +/// Wallpaper executable +pub const NITROGEN: &str = "nitrogen"; diff --git a/src/event_exec.rs b/src/event_exec.rs index 74fe95e..218c6d3 100644 --- a/src/event_exec.rs +++ b/src/event_exec.rs @@ -11,6 +11,7 @@ use which::which; use crate::action_map::ActionMap; use crate::completion::InputCompleted; use crate::config::Colors; +use crate::constant_strings_paths::NITROGEN; use crate::constant_strings_paths::SSHFS_EXECUTABLE; use crate::constant_strings_paths::{CONFIG_PATH, DEFAULT_DRAGNDROP}; use crate::cryptsetup::{lsblk_and_cryptsetup_installed, BlockDeviceAction}; @@ -26,6 +27,7 @@ use crate::opener::{ execute_in_child_without_output_with_path, InternalVariant, }; use crate::password::{PasswordKind, PasswordUsage}; +use crate::preview::is_ext_image; use crate::preview::Preview; use crate::selectable_content::SelectableContent; use crate::shell_parser::ShellCommandParser; @@ -989,10 +991,20 @@ impl EventAction { /// Set the current selected file as wallpaper with `nitrogen`. /// Requires `nitrogen` to be installed. pub fn set_wallpaper(tab: &Tab) -> Result<()> { + if !is_program_in_path(NITROGEN) { + write_log_line("nitrogen must be installed".to_owned()); + return Ok(()); + } + let Some(fileinfo) = tab.path_content.selected() else { + return Ok(()); + }; + if !is_ext_image(&fileinfo.extension) { + return Ok(()); + } let Some(path_str) = tab.path_content.selected_path_string() else { return Ok(()); }; - let _ = execute_in_child("nitrogen", &["--set-zoom-fill", "--save", &path_str]); + let _ = execute_in_child(NITROGEN, &["--set-zoom-fill", "--save", &path_str]); Ok(()) } diff --git a/src/preview.rs b/src/preview.rs index 9792930..ba88f6d 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -987,7 +987,9 @@ fn is_ext_compressed(ext: &str) -> bool { "zip" | "gzip" | "bzip2" | "xz" | "lzip" | "lzma" | "tar" | "mtree" | "raw" | "7z" ) } -fn is_ext_image(ext: &str) -> bool { + +/// True iff the extension is a known (by me) image extension. +pub fn is_ext_image(ext: &str) -> bool { matches!( ext, "png" | "jpg" | "jpeg" | "tiff" | "heif" | "gif" | "raw" | "cr2" | "nef" | "orf" | "sr2" |