From 200e7ba55f5d57d34961a5e098fac0fec2ff036f Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Fri, 13 Aug 2021 19:27:00 +0200 Subject: [PATCH] feat(scripts): Walk scripts directory when loading a list of scripts --- Makefile | 4 +-- debian/pop-launcher-system76-power.install | 2 +- debian/pop-launcher.install | 5 +--- debian/rules | 2 +- plugins/src/plugins/scripts/mod.rs | 31 +++++++++++++--------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index c345937..0f2da29 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/debian/pop-launcher-system76-power.install b/debian/pop-launcher-system76-power.install index dea91d6..72e3852 100644 --- a/debian/pop-launcher-system76-power.install +++ b/debian/pop-launcher-system76-power.install @@ -1 +1 @@ -/usr/lib/pop-launcher/scripts/graphics-* \ No newline at end of file +/usr/lib/pop-launcher/scripts/system76-power \ No newline at end of file diff --git a/debian/pop-launcher.install b/debian/pop-launcher.install index 01f6662..6852f59 100644 --- a/debian/pop-launcher.install +++ b/debian/pop-launcher.install @@ -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 \ No newline at end of file +/usr/lib/pop-launcher/scripts/session/ \ No newline at end of file diff --git a/debian/rules b/debian/rules index 4438e4a..d2bc4ac 100755 --- a/debian/rules +++ b/debian/rules @@ -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 \ No newline at end of file + chmod +x debian/pop-launcher/usr/lib/pop-launcher/scripts/**/*.sh \ No newline at end of file diff --git a/plugins/src/plugins/scripts/mod.rs b/plugins/src/plugins/scripts/mod.rs index d334f37..93bf1ee 100644 --- a/plugins/src/plugins/scripts/mod.rs +++ b/plugins/src/plugins/scripts/mod.rs @@ -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::(); - 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::(); 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) { +async fn load_from(path: &Path, path_tx: &Sender, tx: Sender) { 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(),