Fixed remaining problems with using xdg structure to store configuration files, e.g. key.

This commit is contained in:
Storm Dragon
2025-07-26 10:50:31 -04:00
parent 1b7a3e8113
commit 35fd332aab
+13 -11
View File
@@ -22,15 +22,7 @@ require 5.005;
use File::Path qw(make_path); use File::Path qw(make_path);
# Use XDG_CONFIG_HOME or default to ~/.config # XDG configuration will be set up in the BEGIN block
our $config = ($ENV{'XDG_CONFIG_HOME'} || "$ENV{'HOME'}/.config") . '/ttyverse';
# Check if the directory exists; if not, create it
unless (-d $config) {
eval { make_path($config) };
if ($@) {
die "Failed to create directory: $@";
}
}
BEGIN { BEGIN {
# ONLY STUFF THAT MUST RUN BEFORE INITIALIZATION GOES HERE! # ONLY STUFF THAT MUST RUN BEFORE INITIALIZATION GOES HERE!
@@ -240,10 +232,20 @@ EOF
$trendsurl = "${apibase}/trends"; $trendsurl = "${apibase}/trends";
} }
# Set up XDG config directory
our $config = ($ENV{'XDG_CONFIG_HOME'} || "$ENV{'HOME'}/.config") . '/ttyverse';
# Check if the directory exists; if not, create it
unless (-d $config) {
eval { make_path($config) };
if ($@) {
die "Failed to create directory: $@";
}
}
# try to find an OAuth keyfile if we haven't specified key+secret # try to find an OAuth keyfile if we haven't specified key+secret
# no worries if this fails; we could be Basic Auth, after all # no worries if this fails; we could be Basic Auth, after all
$whine = (length($keyf)) ? 1 : 0; $whine = (length($keyf)) ? 1 : 0;
$keyf ||= "$config key"; $keyf ||= "$config/key";
$attempted_keyf = $keyf; $attempted_keyf = $keyf;
if (!length($oauthkey) && !length($oauthsecret) # set later if (!length($oauthkey) && !length($oauthsecret) # set later
&& !length($tokenkey) && !length($tokenkey)
@@ -1130,7 +1132,7 @@ you use with TTYverse; only one account token can be stored per keyfile. If you
have multiple accounts, use -keyf=... to specify different keyfiles. KEEP THESE have multiple accounts, use -keyf=... to specify different keyfiles. KEEP THESE
FILES SECRET. FILES SECRET.
** This wizard will overwrite $config/$keyf ** This wizard will overwrite $keyf
Press RETURN/ENTER to continue or CTRL-C NOW! to abort. Press RETURN/ENTER to continue or CTRL-C NOW! to abort.
EOF EOF
$j = <STDIN>; $j = <STDIN>;