File: all_apps.patch

package info (click to toggle)
malcontent 0.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,756 kB
  • sloc: ansic: 7,414; python: 418; xml: 377; sh: 36; makefile: 14
file content (162 lines) | stat: -rw-r--r-- 6,899 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
From: Ken VanDine <ken.vandine@canonical.com>
Date: Wed, 14 Aug 2024 11:41:52 -0400
Subject: Allow blocking any installed desktop file

Don't filter only flatpak installed applications, allows filtering out
Debian and Snap apps instead of only Flatpak apps.

This only hides the apps from the Activities Overview but
does not prevent starting the apps in other ways.

Bug: https://gitlab.freedesktop.org/pwithnall/malcontent/-/issues/58

Forwarded: no
---
 libmalcontent-ui/restrict-applications-selector.c | 69 ++++++++++++++++-------
 libmalcontent/app-filter.c                        | 16 +++++-
 2 files changed, 63 insertions(+), 22 deletions(-)

diff --git a/libmalcontent-ui/restrict-applications-selector.c b/libmalcontent-ui/restrict-applications-selector.c
index 83121b6..fb5ca6c 100644
--- a/libmalcontent-ui/restrict-applications-selector.c
+++ b/libmalcontent-ui/restrict-applications-selector.c
@@ -557,17 +557,13 @@ reload_apps (MctRestrictApplicationsSelector *self)
       const gchar * const *supported_types;
 
       app_name = g_app_info_get_name (app);
+      g_autofree gchar *executable = NULL;
 
       supported_types = g_app_info_get_supported_types (app);
 
       if (!G_IS_DESKTOP_APP_INFO (app) ||
           !g_app_info_should_show (app) ||
           app_name[0] == '\0' ||
-          /* FIXME: Only list flatpak apps and apps with X-Parental-Controls
-           * key set for now; we really need a system-wide MAC to be able to
-           * reliably support blocklisting system programs. */
-          (!g_desktop_app_info_has_key (G_DESKTOP_APP_INFO (app), "X-Flatpak") &&
-           !g_desktop_app_info_has_key (G_DESKTOP_APP_INFO (app), "X-Parental-Controls")) ||
           /* Web browsers are special cased */
           (supported_types && g_strv_contains (supported_types, WEB_BROWSERS_CONTENT_TYPE)))
         {
@@ -595,7 +591,6 @@ reload_apps (MctRestrictApplicationsSelector *self)
       else if (g_desktop_app_info_has_key (G_DESKTOP_APP_INFO (app), "X-Parental-Controls"))
         {
           g_autofree gchar *parental_controls_type = NULL;
-          g_autofree gchar *executable = NULL;
 
           parental_controls_type = g_desktop_app_info_get_string (G_DESKTOP_APP_INFO (app),
                                                                   "X-Parental-Controls");
@@ -609,14 +604,35 @@ reload_apps (MctRestrictApplicationsSelector *self)
                    executable,
                    parental_controls_type);
 
-          /* Have we seen this executable before? */
-          if (!g_hash_table_add (seen_executables, g_steal_pointer (&executable)))
-            {
-              g_debug (" → Skipping ‘%s’ due to seeing its executable already",
-                       g_app_info_get_id (app));
-              continue;
-            }
         }
+      else if (g_desktop_app_info_has_key (G_DESKTOP_APP_INFO (app), "X-SnapInstanceName"))
+        {
+          executable = g_strdup (g_app_info_get_commandline (app));
+          g_debug ("Processing app ‘%s’ (Exec=%s)",
+                   g_app_info_get_id (app),
+                   executable);
+        }
+      else
+	{
+         executable = g_strdup (g_app_info_get_executable (app));
+          g_debug ("Processing app ‘%s’ (Exec=%s)",
+                   g_app_info_get_id (app),
+                   executable);
+	}
+
+        /* NULL executable */
+        if (executable == NULL)
+          {
+	    g_debug ("executable is NULL");
+	    continue;
+	  }
+        /* Have we seen this executable before? */
+        if (!g_hash_table_add (seen_executables, g_steal_pointer (&executable)))
+          {
+            g_debug (" → Skipping ‘%s’ due to seeing its executable already",
+                     g_app_info_get_id (app));
+            continue;
+          }
 
       g_list_store_insert_sorted (self->apps,
                                   app,
@@ -725,6 +741,7 @@ mct_restrict_applications_selector_build_app_filter (MctRestrictApplicationsSele
   while (g_hash_table_iter_next (&iter, (gpointer) &app, NULL))
     {
       g_autofree gchar *flatpak_id = NULL;
+      g_autofree gchar *snap_id = NULL;
 
       flatpak_id = g_desktop_app_info_get_string (app, "X-Flatpak");
       if (flatpak_id)
@@ -745,15 +762,27 @@ mct_restrict_applications_selector_build_app_filter (MctRestrictApplicationsSele
         }
       else
         {
-          const gchar *executable = g_app_info_get_executable (G_APP_INFO (app));
-          g_autofree gchar *path = (executable != NULL) ? g_find_program_in_path (executable) : NULL;
-
-          if (!path)
+	  g_autofree gchar *path = NULL;
+          if (g_desktop_app_info_has_key (G_DESKTOP_APP_INFO (app), "X-SnapInstanceName"))
             {
-              g_warning ("Skipping blocklisting executable ‘%s’ due to it not being found", executable);
-              continue;
+              const gchar *commandline = g_app_info_get_commandline (G_APP_INFO (app));
+	      g_autofree gchar **commandline_list = g_strsplit (commandline, " ", -1);
+	      if (g_strv_length (commandline_list) > 2)
+		{
+                  path = (commandline_list != NULL) ? commandline_list[2] : NULL;
+		}
             }
-
+	  else
+            {
+              const gchar *executable = g_app_info_get_executable (G_APP_INFO (app));
+              path = (executable != NULL) ? g_find_program_in_path (executable) : NULL;
+              if (!path)
+                {
+                  g_warning ("Skipping blocklisting executable ‘%s’ due to it not being found", executable);
+                  continue;
+                }
+            }
+ 
           g_debug ("\t\t → Blocklisting path: %s", path);
           mct_app_filter_builder_blocklist_path (builder, path);
         }
diff --git a/libmalcontent/app-filter.c b/libmalcontent/app-filter.c
index 130d1b4..c0e4410 100644
--- a/libmalcontent/app-filter.c
+++ b/libmalcontent/app-filter.c
@@ -411,8 +411,20 @@ mct_app_filter_is_appinfo_allowed (MctAppFilter *filter,
   g_return_val_if_fail (filter->ref_count >= 1, FALSE);
   g_return_val_if_fail (G_IS_APP_INFO (app_info), FALSE);
 
-  exec = g_app_info_get_executable (app_info);
-  abs_path = (exec != NULL) ? g_find_program_in_path (exec) : NULL;
+  if (g_desktop_app_info_has_key (G_DESKTOP_APP_INFO (app_info), "X-SnapInstanceName"))
+    {
+      const gchar *commandline = g_app_info_get_commandline (G_APP_INFO (app_info));
+      g_autofree gchar **commandline_list = g_strsplit (commandline, " ", -1);
+      if (g_strv_length (commandline_list) > 2)
+        {
+          abs_path = (commandline_list != NULL) ? commandline_list[2] : NULL;
+        }
+    }
+  else
+    {
+      exec = g_app_info_get_executable (app_info);
+      abs_path = (exec != NULL) ? g_find_program_in_path (exec) : NULL;
+    }
 
   if (abs_path != NULL &&
       filter_fold_should_short_circuit (filter,