feat(linux): Use XDG_STATE_HOME to storage logs

This commit is contained in:
Zhang Hua 2024-07-07 14:13:01 +08:00
parent d359d130de
commit e9479b1dcf
No known key found for this signature in database
GPG Key ID: 69528D6DCD2BE030

View File

@ -64,6 +64,11 @@ class AppLogger {
if (kIsMacOS) {
dir = join((await getLibraryDirectory()).path, "Logs");
}
if (kIsLinux) {
dir = join(_getXdgStateHome(), "spotube");
}
final file = File(join(dir, ".spotube_logs"));
if (!await file.exists()) {
await file.create(recursive: true);
@ -87,4 +92,18 @@ class AppLogger {
);
}
}
static String _getXdgStateHome() {
// path_provider seems does not support XDG_STATE_HOME,
// which is the specification to store application logs on Linux.
// See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
// TODO: Use path_provider once it supports XDG_STATE_HOME
if (bool.hasEnvironment("XDG_STATE_HOME")) {
String xdgStateHomeRaw = String.fromEnvironment("XDG_STATE_HOME");
if (!xdgStateHomeRaw.isEmpty) {
return xdgStateHomeRaw;
}
}
return join(String.fromEnvironment("HOME"), ".local", "state");
}
}