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

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 330
Merged at revision: 327
Proposed branch: lp:~3v1n0/libunity/desktop-use-snap-namespace
Merge into: lp:libunity
Diff against target: 206 lines (+62/-21)
6 files modified
Makefile.decl (+1/-1)
configure.ac (+1/-1)
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
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+337252@code.launchpad.net

Commit message

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

To post a comment you must log in.
330. By Marco Trevisan (Treviño)

tests: use dbus-run-session to init dbus session on headless tests

Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM.

review: Approve

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

Subscribers

People subscribed via source and target branches