Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Installing menu shortcuts via setup.py rather than on first run #82

Closed
cameel opened this issue Apr 11, 2020 · 4 comments
Closed

Installing menu shortcuts via setup.py rather than on first run #82

cameel opened this issue Apr 11, 2020 · 4 comments

Comments

@cameel
Copy link

cameel commented Apr 11, 2020

I originally mentioned the shortcuts in #80 but they were only tangentially related to that issue (a crash) so I'm creating a new one. By the way, I'm posting it mainly because I see an easy and elegant solution but please don't bother with it if it turns out to be more complicated than this. The shortcuts are not really all that important.

Shortcuts

Currently the application on Linux creates two .desktop files: one on user's desktop (desktop shortcut) and the other in share/applications/ (menu shortcut).

Menu shortcut

When the application runs, it's already too late for creating a menu shortcut because the it may not have enough privileges to put it in the right place. E.g. the menu shortcut should be placed in /usr/share/applications/ if the app was installed globally, for all users, not in ~/.local/share/applications/. Fortunately setuptools provides a way to deal with that in setup.py.

The solution is nicely described in this SO answer: Install .desktop file with setup.py. Basically, if you add the shortcut to data_files in your setup.py and use a relative path to share/applications, the script will put it in the right place, depending on whether the installation is local or global.

Here's the relevant example from that post:

from setuptools import setup

setup(
    name       = 'myapplication',
    version    = '0.1',
    packages   = ['myapplication'],
    data_files = [
        ('share/applications', ['data/org.myapplication.desktop']),
    ],
)

Desktop shortcut

I think that the "right" solution that follows conventions of each platform would be to create such a shortcut only on Windows. I don't think that users expect a desktop shortcut on Linux and there's no standard mechanism in setup.py or package installers to create one. But if some users were confused and asked for it even on Linux then, well, one shortcut is not a big deal. Better to have happy users than to be too strict and lose them :) Also, it would require creating an actual Windows installer, which is a big effort just for a shortcut.

So for desktop shortcut I'd say that creating it on first run is fine. If user does not want it, it can be easily deleted. Or you could provide a command-line flag (e.g. --no-desktop-shortcut) and/or an option in configuration file for those who really hate desktop shortcuts with a passion :)

@srevinsaju
Copy link
Owner

Thanks. your code snippet looks good. I had tried other stuff on the setup.py before, but most of them didn't end up in the wheel (the python binary distribution), because, the wheel marking follows a complicated procedure within itself. However, the current code snippet looks really genuine to me, and I guess it will work. I will test it shortly and let you know.

For Linux, here is what I think can be done:

  • add the --no-desktop-shortcut flag.
  • check is therr is a desktop shortcut in /usr/.. or ~/.local/... . If both does not exist, create the desktop shortcut. (By the way, the desktop shortcut is not the direct shortcut on the Linux Desktop, but rather, . desktop file in the applications view).

I have to still do this on the first run because

  • there are binaries for Linux (AppImage), which although no on uses, rather than some third-party people to get some 💰 out of guiscrcpy's AppImage
  • Windows EXE's, the most demanded guiscrcpy mode of download
  • MacOS .app. (very less users).

all the above binaries, do not use the setup.py, so that's the reason I am forced to create the desktop shortcut thingy on startup. On windows, it could have been done by installers, but, I and many other users are not a fan of the UAC (User Administrator Control) and I would like to develop more features than try to package guiscrcpy in different ways.

thanks for your analysis. I would surely take this into account and give you appropriate credit of it works out well. (I hope adding the above snippet won't cause any FileNotFoundError on Windows 😂)

thanks again

@cameel
Copy link
Author

cameel commented Apr 13, 2020

OK. Sounds reasonable.

BTW, the snippet comes from the SO post I linked to, so you should actually credit the author of the post. But, honestly, only a single line is relevant and you'll need to modify it anyway so if I were the author I wouldn't be upset about not being credited for something like this :)

@srevinsaju
Copy link
Owner

I would add the SO link to the setup.py if I use it. I haven't tested on WIndows yet. Will let you know soon. :)

@srevinsaju
Copy link
Owner

@cameel Fixed it; releasing v3.9 (stable) in a few hours

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

No branches or pull requests

2 participants