richibrics / IoTuring

Your Windows, Linux, macOS computer as MQTT and HomeAssistant integration

Home Page:https://pypi.org/project/IoTuring/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Configuration file needs a new location

richibrics opened this issue · comments

Since in #13 we are moving the script in site-package folder, the configuration file isn't easy to access.
The idea is to move it in the home folder of the user, something like "/home/USER/.ioturing/configuration.json" for linux, in Library for macOS and in AppData (I think) for Windows.

Next step will be to convert the json file to a yaml file (with an auto convert method for older version users).

I don't create a branch now since I want to wait for #13 to be merged.

XDG Base Directory Specification says:

$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.

So if you want to follow the spec (all linux distros should follow this), it should be /home/USER/.config/IoTuring/configuration.json. But it should be read from the envvar: $XDG_CONFIG_HOME/IoTuring/configuration.json

On Windows config files are usually here: %AppData%\IoTuring\configuration.json. Again, this is an envvar, so it can be read without knowing the username.

On one of my other apps there was a user request, to store the path of the config file in an envvar. So a user can place it wherever it want, they just have to add an envvar pointing to the location. It's a nice touch, easy to implement, and also easy to set up for advanced users and platform independent.

Something like $IOTURING_CONFIG_DIR=/random/location/IoTuring

Sure this seems a solid solution.

So let's keep this idea:

  • If an envvar (like $IOTURING_CONFIG_DIR) is not set:
    • Linux
      • IoTuring subfolder in $XDG_CONFIG_HOME
    • Windows
      • IoTuring subfolder in %AppData%
    • macOS
      • IoTuring subfolder in ~/Library/Preferences/ (which I need to discover how to get it automatically from the OS)
  • Otherwise use the envvar folder.

This folder will contain the json file.

Found macOS folders enum to use in Cocoa but the only missing is ~/Library/Preferences/

https://developer.apple.com/documentation/foundation/filemanager/searchpathdirectory

As written on Apple website, also in Application Support there could be our file

https://developer.apple.com/library/archive/documentation/General/Conceptual/MOSXAppProgrammingGuide/AppRuntime/AppRuntime.html

Application Support: Use this directory to store all app data files except those associated with the user’s documents. For example, you might use this directory to store app-created data files, configuration files, templates, or other fixed or modifiable resources that are managed by the app.