Skip to content

Commit e4dc30b

Browse files
committed
feat: optionally use POP_LAUNCHER_LIB_DIR env variable
This environment variable describes where the pop-launcher distribution path exists. The default for this is `/usr/lib/pop-launcher`; however, some distributions would like to use `/usr/libexec/pop-launcher` instead. Signed-off-by: Ryan Brue <[email protected]>
1 parent 6a1b8b9 commit e4dc30b

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

plugins/src/scripts/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ use std::process::Stdio;
1313
use tokio::io::AsyncBufReadExt;
1414
use tokio::process::Command;
1515

16-
const LOCAL_PATH: &str = ".local/share/pop-launcher/scripts";
17-
const SYSTEM_ADMIN_PATH: &str = "/etc/pop-launcher/scripts";
18-
const DISTRIBUTION_PATH: &str = "/usr/lib/pop-launcher/scripts";
19-
2016
pub async fn main() {
2117
let mut requests = json_input_stream(async_stdin());
2218

@@ -103,13 +99,20 @@ impl App {
10399

104100
let mut queue = VecDeque::new();
105101

102+
let local_path = ".local/share/pop-launcher/scripts";
103+
let system_admin_path = "/etc/pop-launcher/scripts";
104+
let distribution_path = &format!(
105+
"{}/scripts",
106+
option_env!("POP_LAUNCHER_LIB_DIR").unwrap_or("/usr/lib/pop-launcher")
107+
);
108+
106109
queue.push_back(
107110
dirs::home_dir()
108111
.expect("user does not have home dir")
109-
.join(LOCAL_PATH),
112+
.join(local_path),
110113
);
111-
queue.push_back(Path::new(SYSTEM_ADMIN_PATH).to_owned());
112-
queue.push_back(Path::new(DISTRIBUTION_PATH).to_owned());
114+
queue.push_back(Path::new(system_admin_path).to_owned());
115+
queue.push_back(Path::new(distribution_path).to_owned());
113116

114117
let script_sender = async move {
115118
while let Some(path) = queue.pop_front() {

src/lib.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,33 @@ pub mod config;
66

77
pub use self::codec::*;
88

9-
use const_format::concatcp;
109
use serde::{Deserialize, Serialize};
1110
use std::{
1211
borrow::Cow,
1312
path::{Path, PathBuf},
1413
};
1514

16-
pub const LOCAL: &str = "~/.local/share/pop-launcher";
17-
pub const LOCAL_PLUGINS: &str = concatcp!(LOCAL, "/plugins");
15+
pub fn plugin_paths<'a>() -> impl Iterator<Item = PathBuf> {
16+
let local = "~/.local/share/pop-launcher";
17+
let local_plugins = format!("{}/plugins", local);
1818

19-
pub const SYSTEM: &str = "/etc/pop-launcher";
20-
pub const SYSTEM_PLUGINS: &str = concatcp!(SYSTEM, "/plugins");
19+
let system = "/etc/pop-launcher";
20+
let system_plugins = format!("{}/plugins", system);
2121

22-
pub const DISTRIBUTION: &str = "/usr/lib/pop-launcher";
23-
pub const DISTRIBUTION_PLUGINS: &str = concatcp!(DISTRIBUTION, "/plugins");
22+
let distribution = option_env!("POP_LAUNCHER_LIB_DIR").unwrap_or("/usr/lib/pop-launcher");
23+
let distribution_plugins = format!("{}/plugins", distribution);
2424

25-
pub const PLUGIN_PATHS: &[&str] = &[LOCAL_PLUGINS, SYSTEM_PLUGINS, DISTRIBUTION_PLUGINS];
25+
let plugin_paths = vec![local_plugins, system_plugins, distribution_plugins];
2626

27-
pub fn plugin_paths() -> impl Iterator<Item = Cow<'static, Path>> {
28-
PLUGIN_PATHS.iter().map(|path| {
27+
plugin_paths.into_iter().map(|path| {
2928
#[allow(deprecated)]
3029
if let Some(path) = path.strip_prefix("~/") {
3130
let path = dirs::home_dir()
3231
.expect("user does not have home dir")
3332
.join(path);
34-
Cow::Owned(path)
33+
path
3534
} else {
36-
Cow::Borrowed(Path::new(path))
35+
Path::new(&path).to_owned()
3736
}
3837
})
3938
}

0 commit comments

Comments
 (0)