diff --git a/.bauke/bin/tauon-controls b/.bauke/bin/tauon-controls index 576a0db..3382e50 100755 --- a/.bauke/bin/tauon-controls +++ b/.bauke/bin/tauon-controls @@ -2,5 +2,6 @@ deno run \ --allow-net="127.0.0.1:7813,127.0.0.1:7814" \ + --allow-run="notify-send" \ "$BAUKE_DIR/scripts/tauon-controls.ts" \ "$@" diff --git a/.bauke/scripts/tauon-controls.ts b/.bauke/scripts/tauon-controls.ts index 0d3b749..68c68ad 100644 --- a/.bauke/scripts/tauon-controls.ts +++ b/.bauke/scripts/tauon-controls.ts @@ -7,6 +7,7 @@ async function main(): Promise { const { options } = await new Command() .name("tauon-controls") .description("Small remote control CLI for Tauon Music Box!") + .option("--current-song", "Send a notification with the current song.") .option("--next-song", "Play the next song.") .option("--play-pause", "Toggle play or pause.") .option("--previous-song", "Play the previous song.") @@ -16,6 +17,10 @@ async function main(): Promise { ) .parse(Deno.args); + if (options.currentSong) { + await notifyCurrentSong(); + } + if (options.nextSong) { await fetch(`${remoteApi}/next`); } @@ -33,6 +38,22 @@ async function main(): Promise { } } +type Status = { + artist?: string; + title?: string; +}; + +async function notifyCurrentSong(): Promise { + const status: Status = await (await fetch(`${remoteApi}/status`)).json(); + if (status.artist === undefined || status.title === undefined) { + return; + } + + await Deno.run({ + cmd: ["notify-send", status.title, status.artist], + }).status(); +} + if (import.meta.main) { void main(); }