fix(scripts): Close signal was not being sent

This commit is contained in:
Michael Aaron Murphy 2021-08-24 22:04:21 +02:00
parent dbcf28b3d8
commit 3be27dde0d

View file

@ -4,12 +4,12 @@ use pop_launcher::*;
use futures_lite::{AsyncBufReadExt, StreamExt}; use futures_lite::{AsyncBufReadExt, StreamExt};
use postage::mpsc::Sender; use postage::mpsc::Sender;
use postage::prelude::*; use postage::prelude::*;
use smol::process::{Command, Stdio};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::os::unix::process::CommandExt; use std::os::unix::process::CommandExt;
use std::{ use std::{
io, io,
path::{Path, PathBuf}, path::{Path, PathBuf},
process::{Command, Stdio},
}; };
const LOCAL_PATH: &str = ".local/share/pop-launcher/scripts"; const LOCAL_PATH: &str = ".local/share/pop-launcher/scripts";
@ -53,26 +53,19 @@ impl App {
} }
async fn activate(&mut self, id: u32) { async fn activate(&mut self, id: u32) {
use fork::{daemon, Fork};
if let Ok(Fork::Child) = daemon(true, true) {
if let Some(script) = self.scripts.get(id as usize) { if let Some(script) = self.scripts.get(id as usize) {
let interpreter = script.interpreter.as_deref().unwrap_or("sh"); let interpreter = script.interpreter.as_deref().unwrap_or("sh");
send(&mut self.out, PluginResponse::Close).await;
let why = dbg!(Command::new(interpreter).arg(script.path.as_os_str())) let _ = Command::new(interpreter)
.arg(script.path.as_os_str())
.stdin(Stdio::null()) .stdin(Stdio::null())
.stdout(Stdio::null()) .stdout(Stdio::null())
.stderr(Stdio::null()) .stderr(Stdio::null())
.exec(); .spawn();
tracing::error!("failed to exec: {}", why);
std::process::exit(1);
} }
} }
send(&mut self.out, PluginResponse::Close).await;
}
async fn reload(&mut self) { async fn reload(&mut self) {
let (tx, mut rx) = postage::mpsc::channel::<ScriptInfo>(8); let (tx, mut rx) = postage::mpsc::channel::<ScriptInfo>(8);