70 lines
2 KiB
Nix
70 lines
2 KiB
Nix
{ pkgs
|
|
, mpv
|
|
, pamixer
|
|
, lib
|
|
}:
|
|
|
|
let
|
|
mpvExe = lib.getExe mpv;
|
|
pamixerExe = lib.getExe pamixer;
|
|
in
|
|
pkgs.writers.writeRustBin "pipewire-controller" { } ''
|
|
use std::{process::Command, str};
|
|
|
|
const MUTE_AUDIO: &str = "${./audio/discord-mute.mp3}";
|
|
const UNMUTE_AUDIO: &str = "${./audio/discord-unmute.mp3}";
|
|
|
|
fn main() {
|
|
let mute_status = Command::new("${pamixerExe}")
|
|
.args(["--default-source", "--get-mute"])
|
|
.output()
|
|
.expect("Unable to get mute status from pamixer")
|
|
.stdout;
|
|
|
|
let mute_status = str::from_utf8(&mute_status[..]).expect("pamixer output wasn't a string").trim();
|
|
|
|
if mute_status == "false" {
|
|
Command::new("${pamixerExe}")
|
|
.args(["--default-source", "--mute"])
|
|
.output()
|
|
.expect("Unable to mute via pamixer");
|
|
|
|
Command::new("${mpvExe}")
|
|
.args(["--no-video", "--volume=80", MUTE_AUDIO])
|
|
.output()
|
|
.expect("Unable to play audio via mpv");
|
|
} else {
|
|
Command::new("${pamixerExe}")
|
|
.args(["--default-source", "--unmute"])
|
|
.output()
|
|
.expect("Unable to unmute via pamixer");
|
|
|
|
Command::new("${mpvExe}")
|
|
.args(["--no-video", "--volume=80", UNMUTE_AUDIO])
|
|
.output()
|
|
.expect("Unable to play audio via mpv");
|
|
}
|
|
|
|
let xrootdatetime_pid_raw =
|
|
Command::new("systemctl")
|
|
.args([
|
|
"--user",
|
|
"show",
|
|
"--property", "MainPID",
|
|
"--value", "xrootdatetime"
|
|
])
|
|
.output();
|
|
|
|
if let Ok(xrootdatetime_pid_raw) = xrootdatetime_pid_raw {
|
|
if let Ok(xrootdatetime_pid) = str::from_utf8(&xrootdatetime_pid_raw.stdout[..]) {
|
|
let _ = Command::new("kill")
|
|
.args([
|
|
"-s",
|
|
"SIGUSR1",
|
|
xrootdatetime_pid
|
|
])
|
|
.spawn();
|
|
}
|
|
}
|
|
}
|
|
''
|