feat(scripts): Walk scripts directory when loading a list of scripts

This commit is contained in:
Michael Aaron Murphy 2021-08-13 19:27:00 +02:00
parent 8b3b95aae8
commit 200e7ba55f
5 changed files with 23 additions and 21 deletions

View file

@ -95,6 +95,6 @@ install:
# Scripts
mkdir -p $(SCRIPTS_DIR)
for script in $(PWD)/scripts/session/*.sh scripts/system76-power/*.sh; do \
install -Dm0644 $${script} $(SCRIPTS_DIR); \
for script in $(PWD)/scripts/*; do \
cp -r $${script} $(SCRIPTS_DIR); \
done

View file

@ -1 +1 @@
/usr/lib/pop-launcher/scripts/graphics-*
/usr/lib/pop-launcher/scripts/system76-power

View file

@ -1,6 +1,3 @@
/usr/bin/
/usr/lib/pop-launcher/plugins/
/usr/lib/pop-launcher/scripts/session-logout.sh
/usr/lib/pop-launcher/scripts/session-reboot.sh
/usr/lib/pop-launcher/scripts/session-shutdown.sh
/usr/lib/pop-launcher/scripts/session-suspend.sh
/usr/lib/pop-launcher/scripts/session/

2
debian/rules vendored
View file

@ -21,4 +21,4 @@ override_dh_auto_build:
override_dh_fixperms:
dh_fixperms
chmod +x debian/pop-launcher/usr/lib/pop-launcher/plugins/**/*.js
chmod +x debian/pop-launcher/usr/lib/pop-launcher/scripts/*.sh
chmod +x debian/pop-launcher/usr/lib/pop-launcher/scripts/**/*.sh

View file

@ -72,21 +72,21 @@ impl App {
}
async fn reload(&mut self) {
#[allow(deprecated)]
let home = std::env::home_dir()
.expect("user does not have home dir")
.join(LOCAL_PATH);
let (path_tx, path_rx) = flume::unbounded::<PathBuf>();
let paths = &[
&home,
Path::new(SYSTEM_ADMIN_PATH),
Path::new(DISTRIBUTION_PATH),
];
let (tx, rx) = flume::unbounded();
#[allow(deprecated)]
let _ = path_tx.send(std::env::home_dir()
.expect("user does not have home dir")
.join(LOCAL_PATH));
let _ = path_tx.send(Path::new(SYSTEM_ADMIN_PATH).to_owned());
let _ = path_tx.send(Path::new(DISTRIBUTION_PATH).to_owned());
let (tx, rx) = flume::unbounded::<ScriptInfo>();
let script_sender = async move {
for path in paths {
load_from(path, tx.clone()).await;
for path in path_rx.recv_async().await {
load_from(&path, &path_tx, tx.clone()).await;
}
};
@ -144,12 +144,17 @@ struct ScriptInfo {
description: String,
}
async fn load_from(path: &Path, tx: Sender<ScriptInfo>) {
async fn load_from(path: &Path, path_tx: &Sender<PathBuf>, tx: Sender<ScriptInfo>) {
if let Ok(directory) = path.read_dir() {
for entry in directory.filter_map(Result::ok) {
let tx = tx.clone();
let path = entry.path();
if path.is_dir() {
path_tx.send_async(path);
continue;
}
smol::spawn(async move {
let mut file = match smol::fs::File::open(&path).await {
Ok(file) => smol::io::BufReader::new(file).lines(),