[gnome-builder] app: make follow-night-light more robust



commit 6fc72e71c5bd1b10ca5a7648e0175989d2435a8d
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 25 00:50:48 2018 -0700

    app: make follow-night-light more robust
    
    This fixes the application of night light on startup as well as ensures
    that we track night light changes immediately when the setting changes.

 src/libide/application/ide-application-color.c   | 25 +++++++++++++++++-------
 src/libide/application/ide-application-private.h |  1 +
 src/libide/application/ide-application.c         |  8 +++++++-
 3 files changed, 26 insertions(+), 8 deletions(-)
---
diff --git a/src/libide/application/ide-application-color.c b/src/libide/application/ide-application-color.c
index 5700cf82f..86cbfab95 100644
--- a/src/libide/application/ide-application-color.c
+++ b/src/libide/application/ide-application-color.c
@@ -23,21 +23,20 @@
 #include "application/ide-application.h"
 #include "application/ide-application-private.h"
 
-static void
-ide_application_color_properties_changed (IdeApplication      *self,
-                                          GVariant            *properties,
-                                          const gchar * const *invalidated,
-                                          GDBusProxy          *proxy)
+void
+_ide_application_update_color (IdeApplication *self)
 {
   g_assert (IDE_IS_APPLICATION (self));
-  g_assert (G_IS_DBUS_PROXY (proxy));
+
+  if (self->color_proxy == NULL || self->settings == NULL)
+    return;
 
   if (g_settings_get_boolean (self->settings, "follow-night-light"))
     {
       g_autoptr(GVariant) activev = NULL;
       gboolean active;
 
-      activev = g_dbus_proxy_get_cached_property (proxy, "NightLightActive");
+      activev = g_dbus_proxy_get_cached_property (self->color_proxy, "NightLightActive");
       active = g_variant_get_boolean (activev);
 
       if (active != g_settings_get_boolean (self->settings, "night-mode"))
@@ -45,6 +44,18 @@ ide_application_color_properties_changed (IdeApplication      *self,
     }
 }
 
+static void
+ide_application_color_properties_changed (IdeApplication      *self,
+                                          GVariant            *properties,
+                                          const gchar * const *invalidated,
+                                          GDBusProxy          *proxy)
+{
+  g_assert (IDE_IS_APPLICATION (self));
+  g_assert (G_IS_DBUS_PROXY (proxy));
+
+  _ide_application_update_color (self);
+}
+
 void
 _ide_application_init_color (IdeApplication *self)
 {
diff --git a/src/libide/application/ide-application-private.h 
b/src/libide/application/ide-application-private.h
index 95e6b7f9a..a785964c5 100644
--- a/src/libide/application/ide-application-private.h
+++ b/src/libide/application/ide-application-private.h
@@ -93,6 +93,7 @@ gboolean ide_application_open_finish                (IdeApplication        *self
                                                      GAsyncResult          *reuslt,
                                                      GError               **error);
 void     _ide_application_init_color                (IdeApplication        *self);
+void     _ide_application_update_color              (IdeApplication        *self);
 void     _ide_application_init_shortcuts            (IdeApplication        *self);
 void     _ide_application_set_mode                  (IdeApplication        *self,
                                                      IdeApplicationMode     mode);
diff --git a/src/libide/application/ide-application.c b/src/libide/application/ide-application.c
index 82cdcd5ff..9c51dd24a 100644
--- a/src/libide/application/ide-application.c
+++ b/src/libide/application/ide-application.c
@@ -441,7 +441,7 @@ on_night_mode_changed (IdeApplication *self,
   IDE_ENTRY;
 
   g_assert (IDE_IS_APPLICATION (self));
-  g_assert (key != NULL);
+  g_assert (dzl_str_equal0 (key, "night-mode"));
   g_assert (G_IS_SETTINGS (settings));
 
   gtk_settings = gtk_settings_get_default ();
@@ -488,6 +488,12 @@ ide_application_register_settings (IdeApplication *self)
                                G_CALLBACK (on_night_mode_changed),
                                self,
                                G_CONNECT_SWAPPED);
+      g_signal_connect_object (self->settings,
+                               "changed::follow-night-light",
+                               G_CALLBACK (_ide_application_update_color),
+                               self,
+                               G_CONNECT_SWAPPED);
+      on_night_mode_changed (self, "night-mode", self->settings);
     }
 
   IDE_EXIT;


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