add a persistent settings store

This commit is contained in:
bea
2026-10-01 23:30:41 +02:00
parent a3c750c479
commit 8b869fe4e9
5 changed files with 436 additions and 0 deletions
@@ -1,5 +1,6 @@
package wtf.beatrice.autosqueal.util;
import java.nio.file.Path;
import java.util.Locale;
public class SystemUtil
@@ -9,6 +10,27 @@ public class SystemUtil
return fromOsName(System.getProperty("os.name"));
}
/**
* The per-user directory where the app keeps its settings, following
* the conventions of the host platform.
*/
public static Path getAppConfigDir() {
String home = System.getProperty("user.home", ".");
String appData = System.getenv("APPDATA");
String xdgConfigHome = System.getenv("XDG_CONFIG_HOME");
return switch (getHostSystem()) {
case MAC_OS -> Path.of(home, "Library", "Application Support", "autosqueal");
case WINDOWS -> appData != null && !appData.isBlank()
? Path.of(appData, "autosqueal")
: Path.of(home, ".autosqueal");
case LINUX -> xdgConfigHome != null && !xdgConfigHome.isBlank()
? Path.of(xdgConfigHome, "autosqueal")
: Path.of(home, ".config", "autosqueal");
default -> Path.of(home, ".autosqueal");
};
}
public static OperatingSystem fromOsName(String osName) {
String normalizedOsName = osName.toLowerCase(Locale.ENGLISH);
if (normalizedOsName.contains("win")) {