Skip to content

Commit

Permalink
feat: optionally use POP_LAUNCHER_LIB_DIR env variable
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ryanabx committed Oct 28, 2024
1 parent 6a1b8b9 commit 2f2e927
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
5 changes: 4 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ base-dir := if rootdir == '' {
rootdir / 'usr'
}

lib-path := 'lib'

lib-dir := if rootdir == '' {
base-dir / 'share'
} else {
base-dir / 'lib'
base-dir / lib-path
}


bin-dir := base-dir / 'bin'
bin-path := bin-dir / ID

Expand Down
17 changes: 10 additions & 7 deletions plugins/src/scripts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ use std::process::Stdio;
use tokio::io::AsyncBufReadExt;
use tokio::process::Command;

const LOCAL_PATH: &str = ".local/share/pop-launcher/scripts";
const SYSTEM_ADMIN_PATH: &str = "/etc/pop-launcher/scripts";
const DISTRIBUTION_PATH: &str = "/usr/lib/pop-launcher/scripts";

pub async fn main() {
let mut requests = json_input_stream(async_stdin());

Expand Down Expand Up @@ -103,13 +99,20 @@ impl App {

let mut queue = VecDeque::new();

let local_path = ".local/share/pop-launcher/scripts";
let system_admin_path = "/etc/pop-launcher/scripts";
let distribution_path = &format!(
"{}/scripts",
option_env!("POP_LAUNCHER_LIB_DIR").unwrap_or("/usr/lib/pop-launcher")
);

queue.push_back(
dirs::home_dir()
.expect("user does not have home dir")
.join(LOCAL_PATH),
.join(local_path),
);
queue.push_back(Path::new(SYSTEM_ADMIN_PATH).to_owned());
queue.push_back(Path::new(DISTRIBUTION_PATH).to_owned());
queue.push_back(Path::new(system_admin_path).to_owned());
queue.push_back(Path::new(distribution_path).to_owned());

let script_sender = async move {
while let Some(path) = queue.pop_front() {
Expand Down
23 changes: 11 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,33 @@ pub mod config;

pub use self::codec::*;

use const_format::concatcp;
use serde::{Deserialize, Serialize};
use std::{
borrow::Cow,
path::{Path, PathBuf},
};

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

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

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

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

pub fn plugin_paths() -> impl Iterator<Item = Cow<'static, Path>> {
PLUGIN_PATHS.iter().map(|path| {
plugin_paths.into_iter().map(|path| {
#[allow(deprecated)]
if let Some(path) = path.strip_prefix("~/") {
let path = dirs::home_dir()
.expect("user does not have home dir")
.join(path);
Cow::Owned(path)
path
} else {
Cow::Borrowed(Path::new(path))
Path::new(&path).to_owned()
}
})
}
Expand Down

0 comments on commit 2f2e927

Please sign in to comment.