Fix track detection

This commit is contained in:
2025-09-03 08:59:19 +01:00
parent d8bb1c3232
commit ed559c09c4

31
main.go
View File

@@ -166,7 +166,7 @@ func CreateUITab(chatJidStr string) ChatTabUI {
content.Wrapping = fyne.TextWrapWord content.Wrapping = fyne.TextWrapWord
content.Selectable = true content.Selectable = true
icon := theme.FileVideoIcon() icon := theme.FileVideoIcon()
replytext := widget.NewLabel("> fallback reply text") replytext := widget.NewLabel(">fallback reply text")
replytext.Hide() replytext.Hide()
replytext.Importance = widget.SuccessImportance replytext.Importance = widget.SuccessImportance
btn := widget.NewButtonWithIcon("View media", icon, func() { btn := widget.NewButtonWithIcon("View media", icon, func() {
@@ -249,7 +249,7 @@ func CreateUITab(chatJidStr string) ChatTabUI {
for i := len(chatTabs[chatJidStr].Messages) - 1; i >= 0; i-- { for i := len(chatTabs[chatJidStr].Messages) - 1; i >= 0; i-- {
if reply.ID == chatTabs[chatJidStr].Messages[i].Raw.StanzaID.ID { if reply.ID == chatTabs[chatJidStr].Messages[i].Raw.StanzaID.ID {
replytext.Show() replytext.Show()
replytext.SetText(fmt.Sprintf("> %s", chatTabs[chatJidStr].Messages[i].Content)) replytext.SetText(fmt.Sprintf(">%s", chatTabs[chatJidStr].Messages[i].Content))
guy = chatTabs[chatJidStr].Messages[i].Author guy = chatTabs[chatJidStr].Messages[i].Author
break break
} }
@@ -1125,6 +1125,13 @@ func main() {
}) })
mycurrentplayingsong := fyne.NewMenuItem("Get currently playing song", func() { mycurrentplayingsong := fyne.NewMenuItem("Get currently playing song", func() {
// BEGIN PLATFORM SPECIFIC CODE
if os.PathSeparator == '\\' && os.PathListSeparator == ';' { // Windows
dialog.ShowError(errors.New("This feature is not supported on your operating system"), w)
return
}
// END PLATFORM SPECIFIC CODE
client, err := mpris.NewClient() client, err := mpris.NewClient()
if err != nil { if err != nil {
dialog.ShowError(err, w) dialog.ShowError(err, w)
@@ -1137,16 +1144,26 @@ func main() {
newtext := "" newtext := ""
title, t_ok := player.RawMetadata()["xesam:title"] title, t_ok := player.RawMetadata()["xesam:title"]
artist, a_ok := player.RawMetadata()["xesam:artist"] artist, a_ok := player.RawMetadata()["xesam:artist"]
if t_ok && a_ok { album, al_ok := player.RawMetadata()["xesam:album"]
newtext = fmt.Sprintf("I'm currently listening to %s by %s", title.String(), artist.String()) artists := []string{}
if a_ok{
artist.Store(&artists)
}
if t_ok && a_ok && al_ok && album.String() != "\"\""{
newtext = fmt.Sprintf("I'm currently listening to %s by %s, in the %s album", strings.Trim(title.String(), "\""), strings.Join(artists, ","), album)
} else if t_ok && a_ok {
newtext = fmt.Sprintf("I'm currently listening to %s by %s", strings.Trim(title.String(), "\""), strings.Join(artists, ",") )
} else if t_ok { } else if t_ok {
newtext = fmt.Sprintf("I'm currently listening to %s", title.String()) newtext = fmt.Sprintf("I'm currently listening to %s", strings.Trim(title.String(), "\""))
} else if a_ok { } else if a_ok {
newtext = fmt.Sprintf("I'm currently listening to a song by %s", artist.String()) newtext = fmt.Sprintf("I'm currently listening to a song by %s", artists[0])
} else { } else {
dialog.ShowError(errors.New("error: There's a playing song, but we could not get the artist or title information."), w) dialog.ShowError(errors.New("error: There's a playing song, but we could not get any information."), w)
return return
} }
entry.SetText(newtext) entry.SetText(newtext)
SendCallback() SendCallback()
entry.SetText(old) entry.SetText(old)