Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Pretty Hostname #227

Merged
merged 6 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions data/io.elementary.switchboard.about.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<description>
<p>Minor updates:</p>
<ul>
<li>Use formatted device name when available</li>
<li>Display more information for certain GPUs, including Intel® Xe Graphics</li>
<li>Updated translations</li>
</ul>
Expand Down
45 changes: 36 additions & 9 deletions src/Views/HardwareView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class About.HardwareView : Gtk.Grid {
construct {
fetch_hardware_info ();

var product_name_info = new Gtk.Label (Environment.get_host_name ()) {
var product_name_info = new Gtk.Label (get_host_name ()) {
ellipsize = Pango.EllipsizeMode.MIDDLE,
selectable = true,
xalign = 0
Expand Down Expand Up @@ -162,16 +162,10 @@ public class About.HardwareView : Gtk.Grid {
}

private async void load_fallback_manufacturer_icon () {
try {
system_interface = yield Bus.get_proxy (
BusType.SYSTEM,
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1"
);
get_system_interface_instance ();

if (system_interface != null) {
manufacturer_logo.icon_name = system_interface.icon_name;
} catch (IOError e) {
critical (e.message);
}
}

Expand Down Expand Up @@ -488,12 +482,45 @@ public class About.HardwareView : Gtk.Grid {
string regex;
string replacement;
}

private void get_system_interface_instance () {
if (system_interface == null) {
try {
system_interface = Bus.get_proxy_sync (
BusType.SYSTEM,
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1"
);
} catch (GLib.Error e) {
warning ("%s", e.message);
}
}
}

private string get_host_name () {
get_system_interface_instance ();

if (system_interface == null) {
return GLib.Environment.get_host_name ();
}

string hostname = system_interface.pretty_hostname;
meisenzahl marked this conversation as resolved.
Show resolved Hide resolved

if (hostname.length == 0) {
hostname = system_interface.static_hostname;
}

return hostname;
}
}

[DBus (name = "org.freedesktop.hostname1")]
public interface SystemInterface : Object {
[DBus (name = "IconName")]
public abstract string icon_name { owned get; }

public abstract string pretty_hostname { owned get; }
public abstract string static_hostname { owned get; }
}

[DBus (name = "org.gnome.SessionManager")]
Expand Down