chore: more robust xdg path handling

This commit is contained in:
atagen 2025-06-22 23:51:54 +10:00
parent 1318c51a44
commit 66d1dfacda
2 changed files with 20 additions and 4 deletions

View file

@ -1,8 +1,9 @@
use anyhow::{Context, Result, anyhow};
use clap::{Parser, Subcommand};
use microxdg::Xdg;
use niri_tag::TagCmd;
use nix::unistd::geteuid;
use std::{io::Write, os::unix::net::UnixStream};
use std::{io::Write, os::unix::net::UnixStream, path::PathBuf, str::FromStr};
#[derive(Parser)]
#[command(name = "tagctl")]
@ -51,8 +52,12 @@ fn main() -> Result<()> {
let cmd = TagCmd::from(cli.cmd);
let mut ipc = UnixStream::connect(format!("/run/user/{}/niri-tag.sock", geteuid()))
.context("Connecting to niri-tag ipc socket")?;
let xdg = Xdg::new()?;
let mut path = xdg
.runtime()?
.unwrap_or(PathBuf::from_str(&format!("/run/user/{}", geteuid()))?);
path.push("niri-tag.sock");
let mut ipc = UnixStream::connect(path).context("Connecting to niri-tag ipc socket")?;
ipc.write_all(serde_json::to_string(&cmd)?.as_bytes())?;
Ok(())
}