Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spotify segment (linux) #4732

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

luisegarduno
Copy link

Prerequisites

  • I have read and understood the contributing guide.
  • The commit message follows the conventional commits guidelines.
  • Tests for the changes have been added (for bug fixes / features).
  • Docs have been added/updated (for bug fixes / features).

Description

The goal of this PR is to create a working segment that displays the song & artist currently playing on the Spotify application via Linux.

mytheme

I created a solution to fetch information from the Spotify application on Linux (Ubuntu) by using a bash segment to run a command. Having said this, the command is written directly in the theme file (see gist).

About 2 years ago, I forked oh-my-posh with the intention of converting the command into a proper segment, but never got around to getting it to work. Given my limited experience with go, I figured I should ask for help.

Regarding the solution itself, here is the command that retrieves the Spotify information:

$ dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata

The command shown above has been tested on several Ubuntu machines and has show to work consistently well. However, I am uncertain on the compatibility across other Linux distributions.

@JanDeDobbeleer
Copy link
Owner

Cool! This isn't a bad start. Allow me to review that somewhere this week.

Copy link
Owner

@JanDeDobbeleer JanDeDobbeleer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to also update the docs, and eventually probably add a source property too specifying dbus or something else (but that's not relevant now)

src/segments/spotify_linux.go Outdated Show resolved Hide resolved
@luisegarduno
Copy link
Author

I'm able to get the tests to pass locally, however when testing the binary, the spotify segment is not showing.

@JanDeDobbeleer
Copy link
Owner

I'm able to get the tests to pass locally, however when testing the binary, the spotify segment is not showing.

You can use oh-my-posh debug to show what’s going on.

@JanDeDobbeleer
Copy link
Owner

@luisegarduno any update?

@luisegarduno
Copy link
Author

Thanks for tip, oh-my-posh debug has been very helpful.

I've made some progress in my latest commit, having {{.Artist}} - {{.Track}} now work.

The workflow will not get far though, as I deleted spotify_wsl & spotify_wsl_test (locally) so that I could get spotify_linux to build - matching boolean function names "Enabled". I assume this may be an easy fix, as I just need to figure out a way to separate the builds for wsl & linux since //go:build wsl isn't a thing yet.

@luisegarduno
Copy link
Author

Haven't made much progress so I figured I would clarify the issue just in case someone is able to figure it out before I do.

As mentioned in my last response, I have been able to verify spotify_linux.go works & passes its tests by temporarily deleting spotify_wsl.go & spotify_wsl_test.go. I have been unable to figure out a way to get both spotify_linux & spotify_wsl to work without having to delete one or the other.


WSL

//go:build !darwin && !windows

...

func (s *Spotify) Enabled() bool {

Linux

//go:build linux && !darwin && !windows

...

func (s *Spotify) Enabled() bool {

Error:

method Spotify.Enabled already declared at oh-my-posh/src/segments/spotify_linux.go:11:19compiler

I have a feeling that adding the wsl expression (see below) would fix the error:

  • spotify_linux.go: //go:build linux && !darwin && !windows && !wsl
    • This would constrain it to build on Linux but not on WSL (!wsl)
  • spotify_wsl.go: //go:build linux && !darwin && !windows && wsl
    • This would constrain it to build on Linux specifically within WSL (wsl)

However, I am not sure how I would go about implementing wsl as a build constraint.

  • [Go]: build package - go/build - Go Packages
  • [Go]: go command - cmd/go - Go Packages

Any help would be appreciated! 😺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants