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

Provide a method for OEMs to include a logo for dark backgrounds #209

Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions src/Views/HardwareView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class About.HardwareView : Gtk.Grid {
private bool oem_enabled;
private string manufacturer_icon_path;
private string? manufacturer_icon_dark_path = null;
private string manufacturer_name;
private string manufacturer_support_url;
private string memory;
Expand All @@ -41,7 +42,11 @@ public class About.HardwareView : Gtk.Grid {

private Gtk.Label storage_info;

private Granite.Settings granite_settings;

construct {
granite_settings = Granite.Settings.get_default ();

fetch_hardware_info ();

var product_name_info = new Gtk.Label (get_host_name ()) {
Expand Down Expand Up @@ -101,12 +106,6 @@ public class About.HardwareView : Gtk.Grid {
};

if (oem_enabled) {
var fileicon = new FileIcon (File.new_for_path (manufacturer_icon_path));

if (manufacturer_icon_path != null) {
manufacturer_logo.gicon = fileicon;
}

if (product_name != null) {
product_name_info.label = "<b>%s</b>".printf (product_name);
product_name_info.use_markup = true;
Expand All @@ -129,9 +128,7 @@ public class About.HardwareView : Gtk.Grid {
details_grid.add (product_name_info);
}

if (manufacturer_logo.gicon == null) {
load_fallback_manufacturer_icon.begin ();
}
update_manufacturer_logo ();

details_grid.add (processor_info);
details_grid.add (graphics_grid);
Expand Down Expand Up @@ -159,6 +156,28 @@ public class About.HardwareView : Gtk.Grid {

add (manufacturer_logo);
add (details_grid);

granite_settings.notify["prefers-color-scheme"].connect (() => {
update_manufacturer_logo ();
});
}

private void update_manufacturer_logo () {
if (oem_enabled) {
string path = manufacturer_icon_path;
if (granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK && manufacturer_icon_dark_path != null) {
path = manufacturer_icon_dark_path;
}
var fileicon = new FileIcon (File.new_for_path (path));

if (path != null) {
manufacturer_logo.gicon = fileicon;
}
}

if (manufacturer_logo.gicon == null) {
load_fallback_manufacturer_icon.begin ();
}
}

private async void load_fallback_manufacturer_icon () {
Expand Down Expand Up @@ -358,6 +377,10 @@ public class About.HardwareView : Gtk.Grid {
manufacturer_icon_path = oem_file.get_string ("OEM", "Logo");
}

if (oem_file.has_key ("OEM", "LogoDark")) {
manufacturer_icon_dark_path = oem_file.get_string ("OEM", "LogoDark");
}

if (oem_file.has_key ("OEM", "URL")) {
manufacturer_support_url = oem_file.get_string ("OEM", "URL");
}
Expand Down