import app from "ags/gtk3/app" import { Astal, Gtk, Gdk } from "ags/gtk3" import { execAsync } from "ags/process" import { createPoll } from "ags/time" export default function Media(gdkmonitor: Gdk.Monitor) { const { TOP, LEFT } = Astal.WindowAnchor const pollCmd = "playerctl metadata -f '{{title}}|||{{artist}}|||{{mpris:artUrl}}|||{{status}}|||{{mpris:length}}|||{{position}}' 2>/dev/null || echo 'No Media||||||Stopped|||0|||0'"; const mediaState = createPoll({ title: "No Media", artist: "", artUrl: "", status: "Stopped", length: 0, position: 0 }, 1000, pollCmd, (stdout) => { const parts = stdout.split("|||"); const title = parts[0]?.trim() || "No Media"; const artist = parts[1]?.trim() || ""; const rawUrl = parts[2]?.trim() || ""; const artUrl = rawUrl.replace(/^file:\/\//, ''); const status = parts[3]?.trim() || "Stopped"; const length = Number(parts[4]) || 0; const position = Number(parts[5]) || 0; return { title, artist, artUrl, status, length, position }; }); return ( s.artUrl ? `background-image: url('${s.artUrl}'); min-width: 80px; min-height: 80px;` : 'min-width: 80px; min-height: 80px; background-color: alpha(@color0, 0.5);')} /> ) }