Remove dependencies and simplify CLI, also adding eww ping command
This commit is contained in:
parent
6df15379bb
commit
5fac2271b5
4 changed files with 57 additions and 778 deletions
789
Cargo.lock
generated
789
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -26,24 +26,17 @@ structopt = "0.3"
|
|||
serde = {version = "1.0", features = ["derive"]}
|
||||
extend = "0.3.0"
|
||||
grass = "0.10"
|
||||
hotwatch = "0.4"
|
||||
crossbeam-channel = "0.4"
|
||||
num = "0.3"
|
||||
stoppable_thread = "0.2"
|
||||
roxmltree = "0.13"
|
||||
itertools = "0.9"
|
||||
scheduled-executor = "0.4"
|
||||
debug_stub_derive = "0.3"
|
||||
log = "0.4"
|
||||
pretty_env_logger = "0.4"
|
||||
lazy_static = "1.4.0"
|
||||
libc = "0.2"
|
||||
popol = "0.3"
|
||||
nix = "0.19"
|
||||
smart-default = "0.6"
|
||||
filedescriptor = "0.7"
|
||||
simple-signal = "1.1"
|
||||
dashmap = "3.11"
|
||||
unescape = "0.1"
|
||||
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -53,11 +53,12 @@ fn main() {
|
|||
}
|
||||
opts::Action::WithServer(action) => {
|
||||
log::info!("Trying to find server process");
|
||||
if let Ok(stream) = net::UnixStream::connect(&*IPC_SOCKET_PATH) {
|
||||
if let Some(stream) = try_connect(&*IPC_SOCKET_PATH) {
|
||||
log::info!("Connected to eww server.");
|
||||
client::forward_command_to_server(stream, action).context("Error while forwarding command to server")?;
|
||||
} else if action.needs_server_running() {
|
||||
println!("No eww server running");
|
||||
std::process::exit(1);
|
||||
} else {
|
||||
log::info!("No server running, initializing server...");
|
||||
let _ = std::fs::remove_file(&*crate::IPC_SOCKET_PATH);
|
||||
|
@ -71,3 +72,14 @@ fn main() {
|
|||
eprintln!("{:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn try_connect(path: &std::path::PathBuf) -> Option<net::UnixStream> {
|
||||
if path.exists() {
|
||||
for _ in 0..5 {
|
||||
if let Ok(stream) = net::UnixStream::connect(&*IPC_SOCKET_PATH) {
|
||||
return Some(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
|
25
src/opts.rs
25
src/opts.rs
|
@ -18,20 +18,14 @@ pub struct Opt {
|
|||
#[derive(StructOpt, Debug, Serialize, Deserialize, PartialEq)]
|
||||
struct RawOpt {
|
||||
#[structopt(subcommand)]
|
||||
action: Option<Action>,
|
||||
|
||||
/// Run Eww in the background, daemonizing it.
|
||||
/// When daemonized, to kill eww you can run `eww kill`. To see logs, use `eww logs`.
|
||||
#[structopt(short = "-d", long = "--detach")]
|
||||
should_detach: bool,
|
||||
action: Action,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug, Serialize, Deserialize, PartialEq, smart_default::SmartDefault)]
|
||||
#[derive(StructOpt, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub enum Action {
|
||||
#[structopt(flatten)]
|
||||
ClientOnly(ActionClientOnly),
|
||||
|
||||
#[default]
|
||||
#[structopt(flatten)]
|
||||
WithServer(ActionWithServer),
|
||||
}
|
||||
|
@ -43,12 +37,16 @@ pub enum ActionClientOnly {
|
|||
Logs,
|
||||
}
|
||||
|
||||
#[derive(StructOpt, Debug, Serialize, Deserialize, PartialEq, smart_default::SmartDefault)]
|
||||
#[derive(StructOpt, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub enum ActionWithServer {
|
||||
/// Start the eww daemon.
|
||||
#[structopt(name = "daemon")]
|
||||
#[default]
|
||||
Daemon,
|
||||
|
||||
/// Ping the eww server, checking if it is reachable.
|
||||
#[structopt(name = "ping")]
|
||||
Ping,
|
||||
|
||||
/// Update the value of a variable, in a running eww instance
|
||||
#[structopt(name = "update")]
|
||||
Update {
|
||||
|
@ -109,10 +107,9 @@ impl Opt {
|
|||
|
||||
impl From<RawOpt> for Opt {
|
||||
fn from(other: RawOpt) -> Self {
|
||||
let RawOpt { action, should_detach } = other;
|
||||
let action = action.unwrap_or_default();
|
||||
let RawOpt { action } = other;
|
||||
Opt {
|
||||
should_detach: should_detach || action == Action::WithServer(ActionWithServer::Daemon),
|
||||
should_detach: action == Action::WithServer(ActionWithServer::Daemon),
|
||||
action,
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +125,7 @@ fn parse_var_update_arg(s: &str) -> Result<(VarName, PrimitiveValue)> {
|
|||
impl ActionWithServer {
|
||||
pub fn into_eww_command(self) -> (app::EwwCommand, Option<tokio::sync::mpsc::UnboundedReceiver<String>>) {
|
||||
let command = match self {
|
||||
ActionWithServer::Daemon => app::EwwCommand::NoOp,
|
||||
ActionWithServer::Daemon | ActionWithServer::Ping => app::EwwCommand::NoOp,
|
||||
ActionWithServer::Update { mappings } => app::EwwCommand::UpdateVars(mappings.into_iter().collect()),
|
||||
ActionWithServer::OpenWindow {
|
||||
window_name,
|
||||
|
|
Loading…
Add table
Reference in a new issue