webmastak / gnome-shell-extensions-mediaplayer

A mediaplayer indicator for GNOME Shell 3.18+.
https://extensions.gnome.org/extension/55/media-player-indicator/
GNU General Public License v2.0
376 stars 106 forks source link

How to start non-default media player? #135

Closed przekop closed 7 years ago

przekop commented 11 years ago

I want to start Nuvola player through extension, but do not link it to audio files.

JasonLG1979 commented 7 years ago

I'll look into a prefs setting that allows you to manually set the default player.

Galmido commented 7 years ago

@JasonLG1979 I opt for the possibility of setting a number of players that would be displayed in the list all the time, like eg. Pantheon Desktop, where volume indicator displays all known players, regardless of whether they are running or not. Clicking on such entry would result in the player launch and reveal of it's controls, which normally be hidden. Additionally, user should be able to set custom label for each of players.

Example from Pantheon: http://1.bp.blogspot.com/-Zhp-Qkxd3B8/UZ9tC7MKwbI/AAAAAAAABtc/rRR60sbZCuc/s1600/spotify_linux.jpg

What do you think?

JasonLG1979 commented 7 years ago

It's certainly possible to keep a list of players that have been used but I'm not sure how we would tell if/when they were uninstalled? When the extension starts we can look up the desktop files of the apps in the list to see if they're still installed but otherwise we end up with a situation where a player gets uninstalled but is still in our list. The only thing we could do at that point is remove it from the list if the user clicked on it and it didn't exist any longer.

Galmido commented 7 years ago

I think we can ignore this for now, in Pantheon this auto detecting all installed players was somewhat annoying, eg. you have several players installed but you normally use only one or two. In my opinion we could display only players added by user and ignore the rest unless one of them is currently running.

2017-02-04 0:17 GMT+01:00 Jason Gray notifications@github.com:

It's certainly possible to keep a list of players that have been used but I'm not sure how we would tell if/when they were uninstalled? When the extension starts we can look up the desktop files of the apps in the list to see if they're still installed but otherwise we end up with a situation where a player gets uninstalled but is still in our list. The only thing we could do at that point is remove it from the list if the user clicked on it and it didn't exist any longer.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/eonpatapon/gnome-shell-extensions-mediaplayer/issues/135#issuecomment-277389265, or mute the thread https://github.com/notifications/unsubscribe-auth/AHVb2tKLHV5dhgOg--UEW8hISNPHhaKwks5rY7VxgaJpZM4AuZew .

JasonLG1979 commented 7 years ago

The actual logic to allow a user to enter an apps name in the prefs and set it as the default player isn't hard. But again we'd have to do something in the event that the player was uninstalled mid-session.

Galmido commented 7 years ago

I think that there would not be a common problem. If you decide to add a player to extension list it means that you are using it regularly, and probably not going to uninstall it. We could define package manager hook to check if binary file defined by user are removed on package uninstall but IMO this is a overkill and simple warning modal about non-existent target binary on element click should be enough. Extensions like these are rather used by more experienced users who would know how to remove a non-existent player from the list.

JasonLG1979 commented 7 years ago

I think that there would not be a common problem.

Probably not. But any inconsistent/unexpected behavior is not good. The expected behavior would be you uninstall the player and it disappears from the menu.

We could define package manager hook to check if binary file defined by user are removed on package uninstall

I'll look into it but I'm not sure if that is possible. It may involve privileges we can't get.

Extensions like these are rather used by more experienced users who would know how to remove a non-existent player from the list.

I'm going to have to disagree with you on that one. This is a pretty widely used extension. For pre 3.20 users it's pretty much the defacto MPRIS extension. A few distros install it by default.

JasonLG1979 commented 7 years ago

I personally don't even have the option enabled. It actually takes more clicks to open the aggregated menu and start a player from the extension than it does to simply hit the hot corner and launch it from the launcher...

Galmido commented 7 years ago

Yes, but indicator that does nothing when you have no running players and this option disabled can be somewhat confusing in situation when you're used to the fact that this is place where you control things related to music. If you don't have any player running and you want to start playback it is easy to habitually move cursor to indicator rather to application menu.

We also could try to define timer function that periodically check if a player binary file was removed from filesystem.

JasonLG1979 commented 7 years ago

Yes, but indicator that does nothing when you have no running players and this option disabled can be somewhat confusing in situation when you're used to the fact that this is place where you control things related to music.

If the option is not enabled and there is no player the extension is hidden, as in as if it wasn't there. There's nothing to be confused about?

If you don't have any player running and you want to start playback it is easy to habitually move cursor to indicator rather to application menu.

That's a learned behavior, habit. Habits can and do change.

We also could try to define timer function that periodically check if a player binary file was removed from filesystem.

We wouldn't be checking for the binary. We'd be checking for the desktop file. And I'm not a fan of a timer spinning away using CPU cycles while most of the time not actually doing anything productive. Abuse of timers leads to wasted electricity because they keep the CPU awake. Think laptop batteries.

JasonLG1979 commented 7 years ago

The best way to do it would be to find some dbus interface to listen for a property change, find out how the app overview know when to add an app for example?

Galmido commented 7 years ago

If the option is not enabled and there is no player the extension is hidden, as in as if it wasn't there. There's nothing to be confused about?

Ah, you see, on my Arch the indicator don't dissapears when player isn't running, icon is hidden but it still takes space. I will try to use another GTK theme to see if it's related to it.

We wouldn't be checking for the binary. We'd be checking for the desktop file. And I'm not a fan of a timer spinning away using CPU cycles while most of the time not actually doing anything productive. Abuse of timers leads to wasted electricity because they keep the CPU awake. Think laptop batteries.

The best way to do it would be to find some dbus interface to listen for a property change, find out how the app overview know when to add an app for example?

That's good idea, it should be possible, Gnome uses DBus all the time so there should be some interface for listening on application list changes.

JasonLG1979 commented 7 years ago

Ah, you see, on my Arch the indicator don't dissapears when player isn't running, icon is hidden but it still takes space. I will try to use another GTK theme to see if it's related to it.

Do you have the most recent version installed? I'm on Fedora 25 with the most recent git and it's completely hidden.

JasonLG1979 commented 7 years ago

Gnome uses DBus all the time so there should be some interface for listening on application list changes.

That was my though. I'll search for extensions that deal with the app overview and see what they're doing. ATM the docs for Shell extension development suck really, really bad. Basically If I want to do something I look at the source of other extensions and/or read the PyGObject Python docs and adapt what it says there.

JasonLG1979 commented 7 years ago

This looks like it might be a way to do it. Basically monkey patch the method that GNOME Shell uses to actually add items to the app grid and man in the middle a signal to update the player list. I haven't looked but I'm guessing there's a removeItem or deleteItem method also?

https://github.com/RaphaelRochet/applications-overview-tooltip/blob/master/extension.js#L48-L69

JasonLG1979 commented 7 years ago

I can't find a good way to do it. That monkey patch would only work when the app overview is shown.(as far as I can tell?) Really thinking about removing the ability to even open any app default or otherwise. As I said before it's redundant, and actually takes more steps than just opening the app from the dash.

@eonpatapon and @badcel your thoughts on any of this?

JasonLG1979 commented 7 years ago

We can use Gio.FileMonitor(provided it exists in the js bindings?) to keep track of the .desktop file and if it disappears we remove the app from the menu.

badcel commented 7 years ago

I just checked what gnome-shell is doing. It looks like they are using GIO to get all the installed apps on the system:

Gio.AppInfo.get_all()

See: https://git.gnome.org/browse/gnome-shell/tree/js/ui/appDisplay.js#n514

JasonLG1979 commented 7 years ago

That's not the problem. The problem is how do we tell when an app has been uninstalled? My thought is monitor the .desktop file of the app that is set to be displayed in the extension as the "default" player.

JasonLG1979 commented 7 years ago

Looking for the most efficient way to get the path to the .desktop file hopefully avoiding walking a bunch of dir's.

JasonLG1979 commented 7 years ago

Got it I think? In Python at least:

        test = Gio.DesktopAppInfo.search('Pithos')[0][0]
        test = Gio.DesktopAppInfo.new(test)
        print(test.get_filename())

prints: /usr/local/share/applications/io.github.Pithos.desktop

JasonLG1979 commented 7 years ago

Well I can tell when an app is uninstalled but it's a PITA and I don't really like it. I think it's more trouble than it's worth. As I've said I'd rather just remove the ability to launch any player default or otherwise.

We've currently got other issues to though. We don't track the default apps at all that leads to a few potentially undesirable situations. 1. The user changes the default audio app and it doesn't get updated in the extension and 2. The user uninstalls the default audio app and it again doesn't get updated but this time in addition to that if the user tries to launch the now uninstalled player it causes an error. In both cases the user has to manually restart the extension to update the default app.

JasonLG1979 commented 7 years ago

Here's a branch with the functionality removed: https://github.com/JasonLG1979/gnome-shell-extensions-mediaplayer/tree/remove-default-app

JasonLG1979 commented 7 years ago

In the above branch, if no player is open the extension is pretty much totally hidden. With the exception that if you select the center of the panel as the position it nudges the clock over a tiny bit. But I don't think there's anything I can do about that? Otherwise if the position is set to right or the menu it takes up no space.

JasonLG1979 commented 7 years ago

@eonpatapon and @badcel IMHO we should remove the ability to launch a default app or any app for that matter. If we do keep the functionality it needs to be fixed.

As I've said the expected behavior would be that if/when the default app changed elsewhere that change would be reflected in the extension. That is not currently the case, so that's a fairly big bug.

JasonLG1979 commented 7 years ago

Tracking the default apps should be fixed.

Now I see a bug that I more than likely introduced when I added the ability to decide the order of the extension in the aggregated menu. Basically the placement of the default app gets rather messed up.

JasonLG1979 commented 7 years ago

This PR needs tested: https://github.com/eonpatapon/gnome-shell-extensions-mediaplayer/pull/311

It fixes the placement of the default app. The default app is always 1st no matter what. Additional players are added top down.

eonpatapon commented 7 years ago

I think the ability to run the default player is a good feature.

I'll try to look if we can be notified when it changes

JasonLG1979 commented 7 years ago

Well I tested that for a few hours and it seemed to work so I merged it.

So in summation, the default player behavior should be as expected:

  1. The default player is always the 1st player in the menu either when open or not. All other player are added from the top down.

  2. When the default audio player is changed in the GNOME settings it is also changed in the extension.

@Galmido I can now actually start the work of adding the ability to set a non-default player as the default player.

eonpatapon commented 7 years ago

Ok, I didn't see in the patch how you are detecting a change of the default player

JasonLG1979 commented 7 years ago

@Galmido and @eonpatapon This should allow the user to set the default app by entering it's name in the prefs. Ofc if nothing is entered the user's session default will be used. If what is entered is not an app name or if the entered app is not a media player the the user's session default will be used. If all else fails and there is no session default app set no app will be in the indicator.

https://github.com/JasonLG1979/gnome-shell-extensions-mediaplayer/tree/user-defined-default-app

Give that a test and if it works I'll merge it.

JasonLG1979 commented 7 years ago

The next step is to set up a file monitor like with the mimeapp.list to tell if the app in question has been uninstalled.

JasonLG1979 commented 7 years ago

Closing this since the default player feature has been removed.