Merge lp:~3v1n0/libunity/desktop-use-snap-namespace-x into lp:libunity/xenial

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: 325
Merged at revision: 325
Proposed branch: lp:~3v1n0/libunity/desktop-use-snap-namespace-x
Merge into: lp:libunity/xenial
Diff against target: 221 lines (+69/-21)
7 files modified
Makefile.decl (+1/-1)
configure.ac (+1/-1)
debian/changelog (+7/-0)
examples/Makefile.am (+16/-3)
examples/launcher.py (+1/-1)
examples/launcher.vala (+2/-3)
src/unity-launcher.vala (+41/-12)
To merge this branch: bzr merge lp:~3v1n0/libunity/desktop-use-snap-namespace-x
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+337274@code.launchpad.net

Commit message

UnityLauncher: Prepend snap namespace to desktop file or desktop-id

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM.

review: Approve
326. By Marco Trevisan (Treviño)

launcher: fix a typo, don't double-check for same var

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.decl'
2--- Makefile.decl 2013-01-10 11:20:42 +0000
3+++ Makefile.decl 2018-02-09 14:37:54 +0000
4@@ -74,7 +74,7 @@
5 LOG_PATH = headless-logs
6 test-headless:
7 set -e; \
8- $(XVFB) -a make test-nonrecursive; \
9+ $(DBUS_LAUNCH) $(XVFB) -a make test-nonrecursive; \
10 sleep 1;
11 else
12 check-local: test-nonrecursive
13
14=== modified file 'configure.ac'
15--- configure.ac 2014-02-04 21:38:14 +0000
16+++ configure.ac 2018-02-09 14:37:54 +0000
17@@ -210,7 +210,7 @@
18
19 if test "x$enable_headless_tests" = "xyes"; then
20 AC_PATH_PROG([XVFB],[xvfb-run])
21- AC_PATH_PROG([DBUS_LAUNCH],[dbus-launch])
22+ AC_PATH_PROG([DBUS_LAUNCH],[dbus-run-session])
23 fi
24
25 ###########################
26
27=== modified file 'debian/changelog'
28--- debian/changelog 2016-07-01 10:44:10 +0000
29+++ debian/changelog 2018-02-09 14:37:54 +0000
30@@ -1,3 +1,10 @@
31+libunity (7.1.4+16.04.20160701-0ubuntu2) UNRELEASED; urgency=medium
32+
33+ * UnityLauncher: Prepend snap namespace to desktop file or desktop-id
34+ (LP: #1747814)
35+
36+ -- Marco Trevisan (Treviño) <mail@3v1n0.net> Wed, 07 Feb 2018 15:48:55 +0100
37+
38 libunity (7.1.4+16.04.20160701-0ubuntu1) xenial; urgency=medium
39
40 [ Andrea Azzarone ]
41
42=== modified file 'examples/Makefile.am'
43--- examples/Makefile.am 2013-06-25 08:09:45 +0000
44+++ examples/Makefile.am 2018-02-09 14:37:54 +0000
45@@ -13,6 +13,7 @@
46 unitylibdir = $(libdir)/unity
47
48 noinst_LTLIBRARIES = scope1.la scope2.la
49+noinst_PROGRAMS = launcher
50
51 scope1_la_VALASOURCES = scope1.vala
52 scope1_la_SOURCES = $(scope1_la_VALASOURCES:.vala=.c)
53@@ -28,9 +29,17 @@
54 $(top_builddir)/src/libunity.la \
55 $(LIBUNITY_LIBS)
56
57+launcher_VALASOURCES = launcher.vala
58+launcher_SOURCES = $(launcher_VALASOURCES:.vala=.c)
59+launcher_LDFLAGS = -shared -module -no-undefined -rpath $(unitylibdir)
60+launcher_LDADD = \
61+ $(top_builddir)/src/libunity.la \
62+ $(LIBUNITY_LIBS)
63+
64 BUILT_SOURCES = \
65 scope1.vala.stamp \
66- scope2.vala.stamp
67+ scope2.vala.stamp \
68+ launcher.vala.stamp
69
70 scope1.vala.stamp: $(scope1_la_VALASOURCES)
71 $(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
72@@ -40,11 +49,15 @@
73 $(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
74 @touch $@
75
76+launcher.vala.stamp: $(launcher_VALASOURCES)
77+ $(AM_V_GEN)$(VALAC) -C $(AM_VALAFLAGS) $(VALAFLAGS) $^
78+ @touch $@
79+
80 EXTRA_DIST = \
81 $(scope1_la_VALASOURCES) \
82 $(scope2_la_VALASOURCES) \
83- launcher.py \
84- launcher.vala
85+ $(launcher_VALASOURCES) \
86+ launcher.py
87
88 CLEANFILES = $(scope1_la_SOURCES) $(scope2_la_SOURCES) $(BUILT_SOURCES)
89
90
91=== modified file 'examples/launcher.py'
92--- examples/launcher.py 2011-04-07 08:05:31 +0000
93+++ examples/launcher.py 2018-02-09 14:37:54 +0000
94@@ -3,7 +3,7 @@
95 loop = GObject.MainLoop()
96
97 # Pretend to be evolution for the sake of the example
98-launcher = Unity.LauncherEntry.get_for_desktop_id ("evolution.desktop")
99+launcher = Unity.LauncherEntry.get_for_desktop_id ("firefox.desktop")
100
101 # Show a count of 124 on the icon
102 launcher.set_property("count", 124)
103
104=== modified file 'examples/launcher.vala'
105--- examples/launcher.vala 2011-04-07 08:05:31 +0000
106+++ examples/launcher.vala 2018-02-09 14:37:54 +0000
107@@ -4,7 +4,7 @@
108 public static void main ()
109 {
110 /* Pretend to be evolution for the sake of the example */
111- var l = Unity.LauncherEntry.get_for_desktop_id ("evolution.desktop");
112+ var l = Unity.LauncherEntry.get_for_desktop_id ("firefox.desktop");
113
114 /* Show a count of 124 on the icon */
115 l.count = 124;
116@@ -16,7 +16,7 @@
117
118 /* Set us as urgent. Quickly! Go! Go! Go! Now! Now! */
119 l.urgent = true;
120-
121+
122 /* We also want a quicklist */
123 var ql = new Dbusmenu.Menuitem ();
124 var item1 = new Dbusmenu.Menuitem ();
125@@ -29,5 +29,4 @@
126
127 new MainLoop().run();
128 }
129-
130 }
131
132=== modified file 'src/unity-launcher.vala'
133--- src/unity-launcher.vala 2015-09-21 17:53:48 +0000
134+++ src/unity-launcher.vala 2018-02-09 14:37:54 +0000
135@@ -28,7 +28,10 @@
136
137 using GLib;
138
139-namespace Unity {
140+namespace Unity {
141+
142+ private const string APP_PREFIX = "application://";
143+ private const string FILE_PREFIX = "file://";
144
145 /* Private class to wire up the DBus stuff. Private so that we don't
146 * leak DBus implementation details into the public API */
147@@ -170,27 +173,56 @@
148 {
149 Object (app_uri : app_uri);
150 }
151-
152+
153 public static LauncherEntry get_for_app_uri (string app_uri)
154 {
155 if (global_entries_map == null)
156 global_entries_map =
157 new HashTable<string, LauncherEntry> (str_hash, str_equal);
158-
159- LauncherEntry? entry = global_entries_map.lookup (app_uri);
160+
161+ string real_app_uri = app_uri;
162+ unowned string snap_path = Environment.get_variable ("SNAP");
163+ unowned string snap_name = Environment.get_variable ("SNAP_NAME");
164+
165+ if (snap_path != null && snap_name != null)
166+ {
167+ debug (@"App is running into a snap container ($snap_name)");
168+ string app = app_uri.substring (APP_PREFIX.length);
169+
170+ if (app[0] == '/')
171+ {
172+ if (!FileUtils.test (app, FileTest.IS_REGULAR))
173+ {
174+ real_app_uri = APP_PREFIX + snap_path + app;
175+ debug (@"Impossible to read file $app, trying with snap namespace: $real_app_uri");
176+ }
177+ }
178+ else
179+ {
180+ string snap_app_prefix = snap_name + "_";
181+
182+ if (!app.has_prefix (snap_app_prefix))
183+ {
184+ real_app_uri = APP_PREFIX + snap_app_prefix + app;
185+ debug (@"App uri does not contain the snap prefix, fixed: '$real_app_uri'");
186+ }
187+ }
188+ }
189+
190+ LauncherEntry? entry = global_entries_map.lookup (real_app_uri);
191 if (entry != null)
192 {
193 return entry;
194 }
195-
196- entry = new LauncherEntry (app_uri);
197- global_entries_map.insert (app_uri, entry);
198+
199+ entry = new LauncherEntry (real_app_uri);
200+ global_entries_map.insert (real_app_uri, entry);
201 return entry;
202 }
203-
204+
205 public static LauncherEntry get_for_desktop_id (string desktop_id)
206 {
207- return LauncherEntry.get_for_app_uri ("application://" + desktop_id);
208+ return LauncherEntry.get_for_app_uri (APP_PREFIX + desktop_id);
209 }
210
211 public static LauncherEntry get_for_desktop_file (string desktop_file)
212@@ -381,9 +413,6 @@
213 fav_cache.remove_all ();
214 fav_list = {};
215
216- const string APP_PREFIX = "application://";
217- const string FILE_PREFIX = "file://";
218-
219 foreach (string id in settings.get_strv ("favorites"))
220 {
221 if (id.has_prefix (APP_PREFIX))

Subscribers

People subscribed via source and target branches