Preserve pre-existing user settings

This prioritises pre-existing user settings in HOME over the XDG_CONFIG_HOME variable being set. HOME is still used as a fallback.
This commit is contained in:
jackbashford 2024-01-30 20:15:03 +11:00 committed by GitHub
parent 91b29e615e
commit 4fb8391364
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,11 +37,14 @@ public class SettingsBase implements AttributeListener {
protected SettingsBase(List<Key> settingsKeys, String name) {
this.settingsKeys = settingsKeys;
File defaultSettings = new File(new File(System.getProperty("user.home")), name);
String settingsDir = System.getenv("XDG_CONFIG_HOME");
if (settingsDir == null) {
settingsDir = System.getProperty("user.home");
if (defaultSettings.isFile() || settingsDir == null) {
filename = defaultSettings;
} else {
filename = new File(settingsDir, name);
}
filename = new File(new File(settingsDir), name);
ElementAttributes attr = null;
if (filename.exists()) {