Webtorrent-desktop: Ubuntu: Add Unity shortcut on .deb install

Created on 5 Apr 2016  路  14Comments  路  Source: webtorrent/webtorrent-desktop

@dcposch: i think nearly all our Linux users will be on Ubuntu, so automatically adding to the launcher on unity is probably worth it

enhancement good first contribution help wanted

Most helpful comment

We should really do this, because most people don't know that they need to run webtorrent-desktop from the terminal the first time in order add the shortcuts, etc.

Proof in this media coverage of the app: http://www.webupd8.org/2016/05/webtorrent-desktop-040-released-with.html

All 14 comments

Ubuntu info

https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles

Basically it requires to execute

gsettings get com.canonical.Unity.Launcher favorites

and it will give you a list of desktop files and unity command shortcuts like this:

['application://google-chrome.desktop', 'application://skype.desktop', 'application://firefox.desktop', 'application://atom.desktop', 'unity://running-apps', 'unity://expo-icon', 'unity://devices']

it can be easly parsed as a json array and add the webtorrent-desktop menu item and then execute

gsettings set com.canonical.Unity.Launcher favorites "['application://google-chrome.desktop', 'application://skype.desktop', 'application://firefox.desktop', 'application://atom.desktop', 'application://webtorrent-desktop.desktop', 'unity://running-apps', 'unity://expo-icon', 'unity://devices'"

remember to add the double quotes because is single parameter

We should really do this, because most people don't know that they need to run webtorrent-desktop from the terminal the first time in order add the shortcuts, etc.

Proof in this media coverage of the app: http://www.webupd8.org/2016/05/webtorrent-desktop-040-released-with.html

Before adding the 'shortcut' to unity launcher we need to create the the .desktop files so the system is aware of the app path/icons, resources, etc.
.desktop file is dynamically created on startup as part of the initialization of the application, so you can not add (fix) to launcher before the .desktop file itself is there.

The dynamic launcher was created because originally the app only ran in standalone (single user) mode, but now you don't know if you are running in the app from a 'packaged' version, or a standalone version.

The solution for packaged version can be add a hardcoded .desktop file and install the app system-wide or run the app using a parameter that creates the .desktop file dynamically as part of the package installation script. Either way, the app initialization should check if we already have the system-wide .desktop file to skip the _local_ standard initialization.

Let me think about this for one day (and get some feedback from other users) and willstart the implementation

Howdy @feross, we recently implemented this in @internetarchive's archivecd project.

We placed our .desktop file in /usr/share/applications/<app>.desktop
... and an icon (which the .desktop references) in /usr/share/app-install/icons/<app>.png

We then ran (within DEBIAN/postinst) with approximately the following cruft:

#!/usr/bin/python
import subprocess
import json

app = 'application://archivecd.desktop'
res = subprocess.check_output([
    u'gsettings', u'get', u'com.canonical.Unity.Launcher', u'favorites'
])
data = json.loads(res[:-1].replace("'", '"'))
data.append(app)
x = json.dumps(data)
subprocess.check_output([
    u'gsettings', u'set', u'com.canonical.Unity.Launcher', u'favorites', x
])

Thanks @mekarpeles -- this is helpful!

@grunjol Any updates on this?

I think this week i will have time to create a suitable solution.

@grunjol Great!

@grunjol Sorry to bother you 馃榿 but any idea when you'll be able to implement this? 馃槈

No bother at all, I started early this week and hopefully will finish during weekend.

@grunjol 馃憤

@feross the PR fixes the issue mentioned in the article, but does not add the icon into the unity launcher, This is because when you install the package you are root and the unity launcher is user specific, and you don't know which user installed it.
We can go and be bold and add the launcher to all the users, but that is the same invasive behavior as making the default torrent handler which is not very welcomed in general.

The good thing is we now have the icon from the app menu even if we never launched the app.

image

Nice @grunjol, looks amazing!

This issue was fixed by @grunjol in https://github.com/feross/webtorrent-desktop/pull/793, so closing this issue now!

Was this page helpful?
0 / 5 - 0 ratings