[gnome-control-center/gnome-42] sound: Update theme directory modification time after bell sound changes



commit af469c99b654381b3c5d2480b783cb4be24279fd
Author: Sebastian Keller <skeller gnome org>
Date:   Mon Apr 25 08:42:03 2022 +0200

    sound: Update theme directory modification time after bell sound changes
    
    The sound plugin of gnome-settings-daemon which flushes the pulseaudio
    sample cache does non-recursive monitoring of the sounds directory. If
    the custom theme directory used for switching between bell sounds
    already exists due to previous bell sound changes, subsequent changes
    within that directory will not be noticed. The old bell sample will thus
    remain in the cache until the next session restart. Avoid this problem
    by manually updating the modification time of the directory.
    
    The alternative solution of adding recursive monitoring to the sound
    plugin would require significantly more complicated code as there is no
    support for this in glib itself. Given that sound themes never really
    caught on and there is an ongoing discussion of removing support for
    them entirely, going with this simple solution seems like the better
    choice.
    
    Fixes: https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/issues/681

 panels/sound/cc-alert-chooser.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/panels/sound/cc-alert-chooser.c b/panels/sound/cc-alert-chooser.c
index 4d56f5849..0cdae3c87 100644
--- a/panels/sound/cc-alert-chooser.c
+++ b/panels/sound/cc-alert-chooser.c
@@ -127,17 +127,20 @@ static void
 set_custom_theme (CcAlertChooser *self,
                   const gchar    *name)
 {
-  g_autofree gchar *dir = NULL;
+  g_autofree gchar *dir_path = NULL;
   g_autofree gchar *theme_path = NULL;
+  g_autoptr(GDateTime) now = NULL;
+  g_autoptr(GFile) dir = NULL;
   g_autoptr(GKeyFile) theme_file = NULL;
   g_autoptr(GVariant) default_theme = NULL;
   g_autoptr(GError) load_error = NULL;
   g_autoptr(GError) save_error = NULL;
+  g_autoptr(GError) mtime_error = NULL;
 
-  dir = get_theme_dir ();
-  g_mkdir_with_parents (dir, USER_DIR_MODE);
+  dir_path = get_theme_dir ();
+  g_mkdir_with_parents (dir_path, USER_DIR_MODE);
 
-  theme_path = g_build_filename (dir, "index.theme", NULL);
+  theme_path = g_build_filename (dir_path, "index.theme", NULL);
 
   default_theme = g_settings_get_default_value (self->sound_settings, "theme-name");
 
@@ -160,6 +163,22 @@ set_custom_theme (CcAlertChooser *self,
   set_sound_symlink ("bell-terminal", name);
   set_sound_symlink ("bell-window-system", name);
 
+  /* Ensure the g-s-d sound plugin which does non-recursive monitoring
+   * notices the change even if the theme directory already existed.
+   */
+  now = g_date_time_new_now_utc ();
+  dir = g_file_new_for_path (dir_path);
+  if (!g_file_set_attribute_uint64 (dir,
+                                    G_FILE_ATTRIBUTE_TIME_MODIFIED,
+                                    g_date_time_to_unix (now),
+                                    G_FILE_QUERY_INFO_NONE,
+                                    NULL,
+                                    &mtime_error))
+    {
+      g_warning ("Failed to update theme directory modification time for %s: %s",
+                 dir_path, mtime_error->message);
+    }
+
   g_settings_set_boolean (self->sound_settings, "event-sounds", TRUE);
   g_settings_set_string (self->sound_settings, "theme-name", CUSTOM_THEME_NAME);
 }


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