diff --git a/ags/widget/center-window/BigMedia.tsx b/ags/widget/center-window/BigMedia.tsx index 7b85e18..bd0ad67 100644 --- a/ags/widget/center-window/BigMedia.tsx +++ b/ags/widget/center-window/BigMedia.tsx @@ -4,67 +4,53 @@ import { Astal, Gtk } from "ags/gtk4"; import { Clipboard } from "../../scripts/clipboard"; import { player } from "../bar/Media"; import { createBinding, With } from "ags"; +import { pathToURI } from "../../scripts/utils"; import AstalMpris from "gi://AstalMpris"; import AstalIO from "gi://AstalIO"; -import Gio from "gi://Gio?version=2.0"; import Pango from "gi://Pango?version=1.0"; export const BigMedia = () => { let dragTimer: (AstalIO.Time|undefined); - return pl.available)}> {(player: AstalMpris.Player) => player.available && - { - const artSub = createBinding(player, "artUrl").subscribe(() => { - const firstChild = self.get_first_child(); - const albumArt = getAlbumArt(player); + - if(!albumArt) { - if(firstChild instanceof Gtk.Picture) - self.remove(firstChild); - - return; - } - - if(firstChild instanceof Gtk.Picture) { - firstChild.set_filename(albumArt); - return; - } - - self.prepend( - as Gtk.Picture - ); - }); - - const destroyId = self.connect("destroy", () => { - self.disconnect(destroyId); - artSub(); - }); - }}> + + + `background-image: url("${pathToURI(art)}");`)} + hexpand={false} vexpand={false} widthRequest={132} heightRequest={128} + valign={Gtk.Align.START} halign={Gtk.Align.CENTER} + /> + + + valign={Gtk.Align.CENTER} vexpand hexpand> title ?? "No Title") + } label={ + createBinding(player, "title").as(title => title ?? "No Title") } ellipsize={Pango.EllipsizeMode.END} maxWidthChars={25} /> artist ?? "No Artist") + } label={ + createBinding(player, "artist").as(artist => artist ?? "No Artist") } ellipsize={Pango.EllipsizeMode.END} maxWidthChars={28} /> - - + { if(type === undefined || type === null) @@ -84,9 +70,9 @@ export const BigMedia = () => { /> - - { + + { const sec = Math.floor(pos % 60); return pos > 0 && player.length > 0 ? `${Math.floor(pos / 60)}:${sec < 10 ? "0" : ""}${sec}` @@ -114,7 +100,7 @@ export const BigMedia = () => { : "media-playlist-consecutive-symbolic")} tooltipText={ createBinding(player, "shuffleStatus").as(status => status === AstalMpris.Shuffle.ON ? "Shuffle" - : "No shuffle")} onClicked={player.shuffle} + : "No shuffle")} onClicked={() => player.shuffle()} /> player.canGoPrevious && player.previous()} @@ -125,7 +111,7 @@ export const BigMedia = () => { iconName={createBinding(player, "playbackStatus").as(status => status === AstalMpris.PlaybackStatus.PLAYING ? "media-playback-pause-symbolic" - : "media-playback-start-symbolic")} onClicked={player.play_pause} + : "media-playback-start-symbolic")} onClicked={() => player.play_pause()} /> player.canGoNext && player.next()} @@ -148,11 +134,11 @@ export const BigMedia = () => { return "Loop playlist"; return "No loop"; - })} onClicked={player.loop} + })} onClicked={() => player.loop()} /> - { /* bananananananana */ + { /* bananananananana */ const sec = Math.floor(len % 60); return (len > 0 && Number.isFinite(len)) ? `${Math.floor(len / 60)}:${sec < 10 ? "0" : ""}${sec}` @@ -165,22 +151,3 @@ export const BigMedia = () => { as Gtk.Box; } - -/** - * This function handles album art/cover of playing media. If a file is provided - * by the player, it adds the "file://" uri as a prefix, so you can use it in css. - * - * @param player the player you want to pull album art from - * @returns Binding to player.artUrl containing the album art uri, or an undefined binding ig none was found. -* */ -function getAlbumArt(player: AstalMpris.Player): string|undefined { - const artUrl = player.artUrl; - - if(!artUrl) - return undefined; - - if(artUrl.startsWith("/")) - return "file://" + artUrl; - - return artUrl; -}