From 10cc9dddf90e08fbbc6e410abac79d80f26ae45a Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 5 May 2021 21:24:40 -0400 Subject: [PATCH] add check for XDG_CONFIG_HOME env var add XDG Directory Specification check --- protonvpn_cli/constants.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/protonvpn_cli/constants.py b/protonvpn_cli/constants.py index cd8f144..2a43266 100644 --- a/protonvpn_cli/constants.py +++ b/protonvpn_cli/constants.py @@ -1,7 +1,9 @@ import os import getpass import pwd - +from xdg import ( + xdg_config_home +) # This implementation is mostly for GUI support. See #168 try: USER = pwd.getpwuid(int(os.environ["PKEXEC_UID"])).pw_name @@ -11,7 +13,11 @@ except KeyError: USER = getpass.getuser() -CONFIG_DIR = os.path.join(os.path.expanduser("~{0}".format(USER)), ".pvpn-cli") +try: + CONFIG_DIR = os.path.join(xdg_config_home(), "pvpn-cli") +except KeyError: + CONFIG_DIR = os.path.join(os.path.expanduser("~{0}".format(USER)), ".pvpn-cli") + CONFIG_FILE = os.path.join(CONFIG_DIR, "pvpn-cli.cfg") SERVER_INFO_FILE = os.path.join(CONFIG_DIR, "serverinfo.json") SPLIT_TUNNEL_FILE = os.path.join(CONFIG_DIR, "split_tunnel.txt")