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

Configuration file should not be created in the $HOME directory on Linux #7

Closed
logix2 opened this issue Sep 3, 2019 · 14 comments
Closed
Labels
feature Enhancement linux Linux OS path Issues related to paths on OSes postponed Delaying the fix for the next release

Comments

@logix2
Copy link

logix2 commented Sep 3, 2019

guiscrcpy currently creates the guiscrcpy.cfg file in the user's home directory. This is not the correct way to do it. Instead, maybe you can follow the freedesktop specifications and use something like $XDG_CONFIG_HOME/guiscrcpy and save it there ($XDG_CONFIG_HOME defaults to ~/.config/ if it's empty by default).

Also, I don't see any documentation as to what I could specify in the guiscrcpy.cfg configuration file.

@srevinsaju srevinsaju reopened this Sep 3, 2019
@srevinsaju
Copy link
Owner

srevinsaju commented Sep 3, 2019

Is XDG_CONFIG_HOME works same as C:\Users\xxx\AppData\ in Windows.

The configuration file is not created by the user, but it is created by the python file to save the information. If the user would like to edit the configuration file, one may, the instructions on the config file is in the main.py. I shall transfer it to the README.md

@logix2
Copy link
Author

logix2 commented Sep 3, 2019

I don't know how C:\Users\xxx\AppData\ works on Windows, I rarely use it.

$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

There's also $XDG_DATA_HOME for data files.

See this for more information: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

@srevinsaju
Copy link
Owner

I have to restructure the code for this, applying for both Windows and Linux. The user home directory was easier for me,because on Linux, it points to ~/guiscrcpy.cfg and on Windows, it points to C:/Users//guiscrcpy.cfg

The commit fixing these will be released shortly with the fix for main window resizing problem, hidden landscape button, restructured debug statement with "LOG: ***" , or "ERR: ***" to create a uniformity..

@logix2
Copy link
Author

logix2 commented Sep 3, 2019

Until you get to that, maybe you can at least hardcode it to something like ~/.config/guiscrcpy/ ? (where ~ is the user home dir; this also works: $HOME/.config), or make the config file hidden by adding a . (dot) to the beginning of the filename? Users are generally unhappy with having apps creating files (that are not hidden) directly in their home folder.

@srevinsaju
Copy link
Owner

srevinsaju commented Sep 3, 2019 via email

@lhanson
Copy link

lhanson commented Sep 5, 2019

No need to guess on a default directory, the spec is clear on what the defaults are if the user hasn't specified an alternate and many libraries exist to derive it for you.

@srevinsaju
Copy link
Owner

@logix2, guiscrcpy.cfg file is moved to .config in home dir on Linux and AppData/Local on Windows, Home directory on Mac.

Marking this as fixed, you may try it.
I shall close the issue in 2days

@lhanson
Copy link

lhanson commented Sep 6, 2019

Does it simply save to $HOME/.config/guiscrcpy.cfg? If so, it shouldn't be hardcoded as such, it should respect $XDG_CONFIG_HOME if set.

@srevinsaju
Copy link
Owner

It saves to $HOME/.config/guiscrcpy.cfg. I am not sure if $XDG_CONFIG_HOME is available on all Linux platforms, and I would not like to edit System variables as such. Probably I didn't understand @lhanson 's comment on this. @lhanson , could you please explain me?

@lhanson
Copy link

lhanson commented Sep 6, 2019

@srevinsaju Sure. $XDG_CONFIG_HOME is not typically set by default on Linux systems, and it's not required by the spec. If the user doesn't set it, the specification says that an application's configuration goes in a subdirectory under $HOME/.config. In this case, it would be a directory called $HOME/.config/guiscrcpy, e.g. the file would be called $HOME/.config/guiscrcpy/guiscrcpy.py; or better yet, for less redundancy, $HOME/.config/guiscrcpy/config.py.

So users don't need to do anything if they are okay with the defaults or don't care, but they're able to express a different preference if they choose to.

It's best not to hardcode this logic in your code, I'd suggest using something like the xdg module; that way, you can just look up the path from the module and it handles the logic for you.

@srevinsaju
Copy link
Owner

@lhanson, I understood the benfits of using $XDG_CONFIG_HOME, but s this variable predefined in all the Linux distros, for example, in Raspbian, or in Gentoo, and other non-popular Linux Oses. I used ~/.config/guiscrcpy.cfg because, its safer compared to $XDG_CONFIG_HOME, because all the Linux distros have .config folder in their home directory. If $XDG_CONFIG_HOME is predefined in all Linux distros, including Android Linux, I shall implement it. I am planning to implement guiscrcpy for Android as well, which includes Android to Android screen mirroring as well.
Please advise me on $XDG_CONFIG_HOME variable. I would love to know more on this!

@lhanson
Copy link

lhanson commented Sep 6, 2019

$XDG_CONFIG_HOME is not predefined on any distro I know of. The point of the specification is to assume a default (~/.config/guiscrcpy/) until/unless the user wants it somewhere else, at which point they have the option to manually set $XDG_CONFIG_HOME, and compliant apps should respect that.

Hardcoding it to ~/.config is not safer because it still ignores the user's wishes if they don't want it there.

I suggest reading over the spec, it's not that long or complicated: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

@srevinsaju
Copy link
Owner

Hmm, thanks @lhanson for the info, will fix it for the next Linux Release v1.11. As running guiscrcpy config flle from ~/.config is not very tedious, I will keep this issue open, until I commit the $XDG_CONFIG_HOME. Thank you

@srevinsaju srevinsaju added feature Enhancement linux Linux OS path Issues related to paths on OSes postponed Delaying the fix for the next release labels Sep 6, 2019
@srevinsaju
Copy link
Owner

@logix2 @lhanson The configuration file has been moved to XDG_CONFIG_HOME if it is define, defaults to .config/guiscrcpy. Please review and let me know

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Enhancement linux Linux OS path Issues related to paths on OSes postponed Delaying the fix for the next release
Projects
None yet
Development

No branches or pull requests

3 participants