Add MPRIS player grabbing to Delta menu

This commit is contained in:
2025-09-02 14:47:39 +01:00
parent b765e8f11c
commit 53367e5982
3 changed files with 37 additions and 2 deletions

29
main.go
View File

@@ -25,6 +25,8 @@ import (
extraWidgets "fyne.io/x/fyne/widget"
"github.com/rrivera/identicon"
"github.com/shreve/musicwand/pkg/mpris"
// xmpp - required
_ "mellium.im/xmpp/disco"
"mellium.im/xmpp/jid"
@@ -243,7 +245,6 @@ func CreateUITab(chatJidStr string) ChatTabUI {
guy := jid.MustParse(reply.To).Resourcepart()
// TODO: EXPERIMENTALLY GET REPLIED TO TEXT
for i := len(chatTabs[chatJidStr].Messages) - 1; i >= 0; i-- {
if reply.ID == chatTabs[chatJidStr].Messages[i].Raw.StanzaID.ID {
replytext.Show()
@@ -256,6 +257,7 @@ func CreateUITab(chatJidStr string) ChatTabUI {
author.SetText(fmt.Sprintf("%s > %s", chatTabs[chatJidStr].Messages[i].Author, guy))
} else {
author.SetText(chatTabs[chatJidStr].Messages[i].Author)
replytext.Hide()
}
sl := strings.Split(msgContent, " ")
@@ -265,6 +267,7 @@ func CreateUITab(chatJidStr string) ChatTabUI {
}
scroller.SetItemHeight(i, vbox.MinSize().Height)
vbox.Refresh()
},
)
@@ -1106,7 +1109,29 @@ func main() {
entry.Text = fmt.Sprintf("It is currently %s", time.Now().Format(time.RFC850))
SendCallback()
})
menu_jokes := fyne.NewMenu("Δ", mycurrenttime, hafjag, hotfuck, agree)
mycurrentplayingsong := fyne.NewMenuItem("Get currently playing song", func() {
client, err := mpris.NewClient()
if err != nil {
dialog.ShowError(err, w)
return
}
present := false
for _, player := range client.Players() {
old := entry.Text
entry.SetText(fmt.Sprintf("I'm currently listening to \"%v\" by %v", player.RawMetadata()["xesam:title"].Value(), player.RawMetadata()["xesam:artist"]))
SendCallback()
entry.SetText(old)
present = true
break
}
if !present {
dialog.ShowInformation("Failed", "Could not find any players. You might need an MPRIS plugin for players such as mpv.\nSee the MPRIS ArchWiki article for more information:\nhttps://wiki.archlinux.org/title/MPRIS\nMPRIS is not supported on Windows or MacOS.",w)
}
})
menu_jokes := fyne.NewMenu("Δ", mycurrenttime, hafjag, hotfuck, agree, mycurrentplayingsong)
bit := fyne.NewMenuItem("mark selected message as read", func() {
selectedScroller, ok := AppTabs.Selected().Content.(*widget.List)
if !ok {