gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / glib-appinfo-watch.patch
CommitLineData
ae10ec44
LC
1This patch lets GLib's GDesktopAppInfo API watch and notice changes
2to the Guix user and system profiles. That way, the list of available
3applications shown by the desktop environment is immediately updated
4when the user runs "guix install", "guix remove", or "guix system
5reconfigure" (see <https://issues.guix.gnu.org/35594>).
6
7It does so by monitoring /var/guix/profiles (for changes to the system
8profile) and /var/guix/profiles/per-user/USER (for changes to the user
9profile) and crawling their share/applications sub-directory when
10changes happen.
11
12diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
13index f1e2fdd..095c110 100644
14--- a/gio/gdesktopappinfo.c
15+++ b/gio/gdesktopappinfo.c
16@@ -148,6 +148,7 @@ typedef struct
17 gchar *alternatively_watching;
18 gboolean is_config;
19 gboolean is_setup;
20+ gchar *guix_profile_watch_dir;
21 GFileMonitor *monitor;
22 GHashTable *app_names;
23 GHashTable *mime_tweaks;
24@@ -180,6 +181,7 @@ desktop_file_dir_unref (DesktopFileDir *dir)
25 {
26 desktop_file_dir_reset (dir);
27 g_free (dir->path);
28+ g_free (dir->guix_profile_watch_dir);
29 g_free (dir);
30 }
31 }
32@@ -204,6 +206,13 @@ desktop_file_dir_get_alternative_dir (DesktopFileDir *dir)
33 {
34 gchar *parent;
35
36+ /* If DIR is a profile, watch the specified directory--e.g.,
37+ * /var/guix/profiles/per-user/$USER/ for the user profile. Do not watch
38+ * ~/.guix-profile or /run/current-system/profile because GFileMonitor does
39+ * not pass IN_DONT_FOLLOW and thus cannot notice any change. */
40+ if (dir->guix_profile_watch_dir != NULL)
41+ return g_strdup (dir->guix_profile_watch_dir);
42+
43 /* If the directory itself exists then we need no alternative. */
44 if (g_access (dir->path, R_OK | X_OK) == 0)
45 return NULL;
46@@ -249,11 +258,11 @@ desktop_file_dir_changed (GFileMonitor *monitor,
47 *
48 * If this is a notification for a parent directory (because the
49 * desktop directory didn't exist) then we shouldn't fire the signal
50- * unless something actually changed.
51+ * unless something actually changed or it's in /var/guix/profiles.
52 */
53 g_mutex_lock (&desktop_file_dir_lock);
54
55- if (dir->alternatively_watching)
56+ if (dir->alternatively_watching && dir->guix_profile_watch_dir == NULL)
57 {
58 gchar *alternative_dir;
59
60@@ -1555,6 +1564,32 @@ desktop_file_dirs_lock (void)
61 for (i = 0; dirs[i]; i++)
62 g_ptr_array_add (desktop_file_dirs, desktop_file_dir_new (dirs[i]));
63
64+ {
65+ /* Monitor the system and user profile under /var/guix/profiles and
66+ * treat modifications to them as if they were modifications to their
67+ * /share sub-directory. */
68+ const gchar *user;
69+ DesktopFileDir *system_profile_dir, *user_profile_dir;
70+
71+ system_profile_dir =
72+ desktop_file_dir_new ("/var/guix/profiles/system/profile/share");
73+ system_profile_dir->guix_profile_watch_dir = g_strdup ("/var/guix/profiles");
74+ g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (system_profile_dir));
75+
76+ user = g_get_user_name ();
77+ if (user != NULL)
78+ {
79+ gchar *profile_dir, *user_data_dir;
80+
81+ profile_dir = g_build_filename ("/var/guix/profiles/per-user", user, NULL);
82+ user_data_dir = g_build_filename (profile_dir, "guix-profile", "share", NULL);
83+ user_profile_dir = desktop_file_dir_new (user_data_dir);
84+ user_profile_dir->guix_profile_watch_dir = profile_dir;
85+ g_ptr_array_add (desktop_file_dirs, desktop_file_dir_ref (user_profile_dir));
86+ g_free (user_data_dir);
87+ }
88+ }
89+
90 /* The list of directories will never change after this, unless
91 * g_get_user_config_dir() changes due to %G_TEST_OPTION_ISOLATE_DIRS. */
92 desktop_file_dirs_config_dir = user_config_dir;