Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optionally use POP_LAUNCHER_LIB_DIR env variable #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ 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'
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