Martchus / syncthingtray

Tray application and Dolphin/Plasma integration for Syncthing
https://martchus.github.io/syncthingtray/
Other
1.5k stars 42 forks source link

Support for environment variables for data/config folders #243

Closed jintaxi closed 1 month ago

jintaxi commented 3 months ago

Relevant components

Is your feature request specific to a certain platform/environment? Please specify. Both for Windows and Linux.

Is your feature request related to a problem? Please describe. In the Syncthing Tray -> Settings -> Startup -> Syncthing launcher -> Config directory/Data directory support for environment variables is needed. Such as %LocalAppData% in Windows.

Describe the solution you'd like When writing something like %LocalAppData%/Syncthing, the program interprets it not as %LocalAppData%/Syncthing to a folder in the local directory, but actually follows the path specified in the environment variable.

Describe alternatives you've considered I write the full path to the AppData/local folder, which makes it difficult to port the program (for example, for a USB stick), or leave it in the program folder (./data).

Martchus commented 3 months ago

Another alternative would be to use the environment variables mentioned by syncthing serve --help and not set anything in the settings dialog. At least I think the integrated Syncthing instance allows that as well.

However, I guess I can add support for those substituions (or would accept a PR adding this feature). I suppose under Windows it would go though all environment variables and substitues %NAME_OF_VARIABLE% with the value of that variable. Under Linux it would substitue ${NAME_OF_VARIABLE}. Implementing further syntax and escaping is probably not needed.

stale[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Martchus commented 1 month ago

Closing as this is now implemented. The implementation uses https://pkg.go.dev/os#ExpandEnv under the hood so the syntax is $VAR or ${VAR} and I suppose that also counts under Windows.

EDIT: I've just tested it under Windows and it works (but only with $, so e.g. $AppData/libsyncthing-test will put files under %AppData%/libsyncthing-test).