Skip to content

Commit

Permalink
Parse all branding colors from appstream (#2226)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwood-grant authored Dec 10, 2024
1 parent be2fb50 commit e0641dc
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions src/Core/Package.vala
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,10 @@ public class AppCenterCore.Package : Object {

public string? description = null;
private string? summary = null;
private string? color_primary = null;
private string? color_primary_light = null;
private string? color_primary_dark = null;
private string? color_primary_unknown = null;
private string? color_primary_fallback = null;
private string? color_primary_text = null;
private string? payments_key = null;
private string? suggested_amount = null;
Expand Down Expand Up @@ -418,7 +421,10 @@ public class AppCenterCore.Package : Object {
name = null;
description = null;
summary = null;
color_primary = null;
color_primary_light = null;
color_primary_dark = null;
color_primary_unknown = null;
color_primary_fallback = null;
color_primary_text = null;
payments_key = null;
suggested_amount = null;
Expand Down Expand Up @@ -749,19 +755,44 @@ public class AppCenterCore.Package : Object {
}

public string? get_color_primary () {
if (color_primary != null) {
return color_primary;
cache_primary_colors ();

string? color_primary = null;
var gtk_settings = Gtk.Settings.get_default ();
if (color_primary_light != null && !gtk_settings.gtk_application_prefer_dark_theme) {
color_primary = color_primary_light;
} else if (color_primary_dark != null && gtk_settings.gtk_application_prefer_dark_theme) {
color_primary = color_primary_dark;
} else if (color_primary_unknown != null) {
color_primary = color_primary_unknown;
} else {
var branding = component.get_branding ();
if (branding != null) {
color_primary = branding.get_color (AppStream.ColorKind.PRIMARY, AppStream.ColorSchemeKind.UNKNOWN);
color_primary = color_primary_fallback;
}

return color_primary;
}

private void cache_primary_colors () {
var branding = component.get_branding ();
if (branding != null) {
if (color_primary_dark == null) {
color_primary_dark = branding.get_color (AppStream.ColorKind.PRIMARY,
AppStream.ColorSchemeKind.DARK);
}

if (color_primary == null) {
color_primary = component.get_custom_value ("x-appcenter-color-primary");
if (color_primary_light == null) {
color_primary_light = branding.get_color (AppStream.ColorKind.PRIMARY,
AppStream.ColorSchemeKind.LIGHT);
}

return color_primary;
if (color_primary_unknown == null) {
color_primary_unknown = branding.get_color (AppStream.ColorKind.PRIMARY,
AppStream.ColorSchemeKind.UNKNOWN);
}
}

if (color_primary_fallback == null) {
color_primary_fallback = component.get_custom_value ("x-appcenter-color-primary");
}
}

Expand Down

0 comments on commit e0641dc

Please sign in to comment.