[gnome-clocks/zbrown/style-loader: 3/3] css: ignore resource not found



commit 09fe2b97327055ce136d90b42ec8096973b435d3
Author: Zander Brown <zbrown gnome org>
Date:   Fri Mar 20 10:32:18 2020 +0000

    css: ignore resource not found
    
    Fix https://gitlab.gnome.org/GNOME/gnome-clocks/issues/89

 src/application.vala |  4 ++--
 src/utils.vala       | 26 ++++++++++++--------------
 2 files changed, 14 insertions(+), 16 deletions(-)
---
diff --git a/src/application.vala b/src/application.vala
index 24ac931..3a880cd 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -111,13 +111,13 @@ public class Application : Gtk.Application {
         string theme_name;
 
         settings.get ("gtk-theme-name", out theme_name);
-        Utils.load_theme_css (theme_name);
+        Utils.load_css ("gnome-clocks." + theme_name.down ());
     }
 
     protected override void startup () {
         base.startup ();
 
-        Utils.load_main_css ();
+        Utils.load_css ("gnome-clocks");
 
         set_resource_base_path ("/org/gnome/clocks/");
 
diff --git a/src/utils.vala b/src/utils.vala
index 74b912d..8b89988 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -36,21 +36,19 @@ const double RISESET_CORRECTION_ASTRONOMICAL = 18.0;
 namespace Clocks {
 namespace Utils {
 
-private void load_css (string css, bool required) {
+public void load_css (string css) {
     var provider = new Gtk.CssProvider ();
-    provider.load_from_resource ("/org/gnome/clocks/css/" + css + ".css");
-
-    Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
-                                              provider,
-                                              Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
-}
-
-public void load_main_css () {
-    load_css ("gnome-clocks", true);
-}
-
-public void load_theme_css (string theme_name) {
-    load_css ("gnome-clocks." + theme_name.down (), false);
+    try {
+        var data = resources_lookup_data ("/org/gnome/clocks/css/" + css + ".css", NONE);
+        provider.load_from_data ((string) data.get_data ());
+        Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
+                                                  provider,
+                                                  Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
+    } catch (ResourceError.NOT_FOUND e) {
+        /* Ignore */
+    } catch (Error e) {
+        warning ("Didn't load css for %s: %s".printf (css, e.message));
+    }
 }
 
 public void time_to_hms (double t, out int h, out int m, out int s, out double remainder) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]