More of a desktop app than specifically a Compose ...
# compose-desktop
m
More of a desktop app than specifically a Compose question, but I'm trying to find a good place to store a config file for my application. I've seen the answer here is consistently to use the AppDirs library to find the correct directory to use. But it seems to base the provided path on the app version (
/home/user/.config/myapp/1.2.3
), meaning every time users update my app, they would get a new config directory, and to prevent losing their config on every app update I would need some migration mechanism to copy files over from the previous version. Looking on my system, most applications just use
/home/user/.config/myapp/
without a version, which is what makes sense to me, but that use case is unsupported by the AppDirs library. I'm curious how others solve this problem?
c
I use appdirs in my desktop apps, and I ran into this same issue. I solved it by treating the configuration version separately from the app version, much like you might do with a database version. Then if you need to change its structure, you write a migration
m
I ended up implementing it on my own without the versions, based on the library, which looking at the source code is actually very simple, maybe 10 lines of code per OS.
m
Not using a version is supported, just pass null when it asks for a version
m
I saw there were no `?`'s on the arguments. Now I realize the library is in Java... One dependency less I guess. 😄
a
I'm wrote this code snippet to follow the XDG specification:
Copy code
val xdgConfigHome: String? = System.getenv("XDG_CONFIG_HOME")

val settingsPath = if (xdgConfigHome.isNullOrBlank()) {
    val home = System.getProperty("user.home").orEmpty()
    "$home/.config/appName
} else {
    "$xdgConfigHome/appName"
}

// If using the preferences API from java:
System.setProperty("java.util.prefs.userRoot", settingsPath)