Application.Client: Use GLib rather than lsb-release for OS info

Use `g_get_os_info()` instead of exec'ing lsb-release, bump min GLib
version req to ensure we have the function available.

Fixes #800
This commit is contained in:
Michael Gratton 2020-08-22 10:45:25 +10:00
parent b8ed6ed230
commit 591046ecee

View file

@ -289,44 +289,15 @@ public class Application.Client : Gtk.Application {
_("Unknown")
});
// Distro name and version using LSB util
/// Application runtime information label
info.add({ _("Distribution name"),
GLib.Environment.get_os_info(GLib.OsInfoKey.NAME)
});
GLib.SubprocessLauncher launcher = new GLib.SubprocessLauncher(
GLib.SubprocessFlags.STDOUT_PIPE |
GLib.SubprocessFlags.STDERR_SILENCE
);
// Reset lang vars so we can guess the strings below
launcher.setenv("LANGUAGE", "C", true);
launcher.setenv("LANG", "C", true);
launcher.setenv("LC_ALL", "C", true);
string lsb_output = "";
try {
GLib.Subprocess lsb_release = launcher.spawnv(
{ "lsb_release", "-ir" }
);
lsb_release.communicate_utf8(null, null, out lsb_output, null);
} catch (GLib.Error err) {
warning("Failed to exec lsb_release: %s", err.message);
}
if (lsb_output != "") {
foreach (string line in lsb_output.split("\n")) {
string[] parts = line.split(":", 2);
if (parts.length > 1) {
if (parts[0].has_prefix("Distributor ID")) {
/// Application runtime information label
info.add(
{ _("Distribution name"), parts[1].strip() }
);
} else if (parts[0].has_prefix("Release")) {
/// Application runtime information label
info.add(
{ _("Distribution release"), parts[1].strip() }
);
}
}
}
}
/// Application runtime information label
info.add({_("Distribution release"),
GLib.Environment.get_os_info(GLib.OsInfoKey.VERSION)
});
/// Application runtime information label
info.add({ _("Installation prefix"), INSTALL_PREFIX });