Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support putting config dir in $XDG_CONFIG_HOME #308

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/modules/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { promises: fs } = require( 'fs' )
const { HOME } = process.env
const { HOME, XDG_CONFIG_HOME } = process.env
let has_alerted_user_no_home = false

const { dialog } = require( 'electron' )
Expand All @@ -19,7 +19,10 @@ const log = async ( ...messages ) => {

// Log to file if possible
try {
if( HOME ) {
if( XDG_CONFIG_HOME ) {
await fs.mkdir( `${ XDG_CONFIG_HOME }/battery/`, { recursive: true } )
await fs.appendFile( `${ XDG_CONFIG_HOME }/battery/gui.log`, `${ messages.join( '\n' ) }\n`, 'utf8' )
} else if( HOME ) {
await fs.mkdir( `${ HOME }/.battery/`, { recursive: true } )
await fs.appendFile( `${ HOME }/.battery/gui.log`, `${ messages.join( '\n' ) }\n`, 'utf8' )
} else if( !has_alerted_user_no_home ) {
Expand Down
2 changes: 1 addition & 1 deletion battery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin
binfolder=/usr/local/bin
visudo_folder=/private/etc/sudoers.d
visudo_file=${visudo_folder}/battery
configfolder=$HOME/.battery
[ -n "$XDG_CONFIG_HOME" ] && configfolder=$XDG_CONFIG_HOME/battery || configfolder=$HOME/.battery
pidfile=$configfolder/battery.pid
logfile=$configfolder/battery.log
maintain_percentage_tracker_file=$configfolder/maintain.percentage
Expand Down
4 changes: 2 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ echo -e "# Note: this script will ask for your password once or multiple times."
echo -e "####################################################################\n\n"

# Set environment variables
tempfolder=~/.battery-tmp
tempfolder=$(mktemp -d)
binfolder=/usr/local/bin
mkdir -p $tempfolder

# Set script value
calling_user=${1:-"$USER"}
configfolder=/Users/$calling_user/.battery
[ -n "$XDG_CONFIG_HOME" ] && configfolder=$XDG_CONFIG_HOME/battery || configfolder=/Users/$calling_user/.battery
pidfile=$configfolder/battery.pid
logfile=$configfolder/battery.log

Expand Down
2 changes: 1 addition & 1 deletion update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
PATH="$PATH:/usr/sbin"

# Set environment variables
tempfolder=~/.battery-tmp
tempfolder=$(mktemp -d)
binfolder=/usr/local/bin
batteryfolder="$tempfolder/battery"
mkdir -p $batteryfolder
Expand Down