~khurshid-alam/libunity/remove-deprecated-scopes

« back to all changes in this revision

Viewing changes to src/unity-launcher.vala

  • Committer: Bileto Bot
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2018-02-07 12:30:52 UTC
  • mfrom: (326.1.4 desktop-use-snap-namespace)
  • Revision ID: ci-train-bot@canonical.com-20180207123052-w79hg09rwp4wnyye
UnityLauncher: Prepend snap namespace to desktop file or desktop-id (LP: #1737835, #1747814)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
using GLib;
30
30
 
31
 
namespace Unity {  
 
31
namespace Unity {
 
32
 
 
33
  private const string APP_PREFIX = "application://";
 
34
  private const string FILE_PREFIX = "file://";
32
35
 
33
36
  /* Private class to wire up the DBus stuff. Private so that we don't
34
37
   * leak DBus implementation details into the public API */
170
173
    {
171
174
      Object (app_uri : app_uri);
172
175
    }
173
 
    
 
176
 
174
177
    public static LauncherEntry get_for_app_uri (string app_uri)
175
178
    {
176
179
      if (global_entries_map == null)
177
180
        global_entries_map =
178
181
                new HashTable<string, LauncherEntry> (str_hash, str_equal);
179
 
      
180
 
      LauncherEntry? entry = global_entries_map.lookup (app_uri);
 
182
 
 
183
      string real_app_uri = app_uri;
 
184
      unowned string snap_path = Environment.get_variable ("SNAP");
 
185
      unowned string snap_name = Environment.get_variable ("SNAP_NAME");
 
186
 
 
187
      if (snap_path != null && snap_path != null)
 
188
        {
 
189
          debug (@"App is running into a snap container ($snap_name)");
 
190
          string app = app_uri.substring (APP_PREFIX.length);
 
191
 
 
192
          if (app[0] == '/')
 
193
            {
 
194
              if (!FileUtils.test (app, FileTest.IS_REGULAR))
 
195
                {
 
196
                  real_app_uri = APP_PREFIX + snap_path + app;
 
197
                  debug (@"Impossible to read file $app, trying with snap namespace: $real_app_uri");
 
198
                }
 
199
            }
 
200
          else
 
201
            {
 
202
              string snap_app_prefix = snap_name + "_";
 
203
 
 
204
              if (!app.has_prefix (snap_app_prefix))
 
205
                {
 
206
                  real_app_uri = APP_PREFIX + snap_app_prefix + app;
 
207
                  debug (@"App uri does not contain the snap prefix, fixed: '$real_app_uri'");
 
208
                }
 
209
            }
 
210
        }
 
211
 
 
212
      LauncherEntry? entry = global_entries_map.lookup (real_app_uri);
181
213
      if (entry != null)
182
214
        {
183
215
          return entry;
184
216
        }
185
 
      
186
 
      entry = new LauncherEntry (app_uri);
187
 
      global_entries_map.insert (app_uri, entry);
 
217
 
 
218
      entry = new LauncherEntry (real_app_uri);
 
219
      global_entries_map.insert (real_app_uri, entry);
188
220
      return entry;
189
221
    }
190
 
    
 
222
 
191
223
    public static LauncherEntry get_for_desktop_id (string desktop_id)
192
224
    {
193
 
      return LauncherEntry.get_for_app_uri ("application://" + desktop_id);
 
225
      return LauncherEntry.get_for_app_uri (APP_PREFIX + desktop_id);
194
226
    }
195
227
    
196
228
    public static LauncherEntry get_for_desktop_file (string desktop_file)
381
413
      fav_cache.remove_all ();
382
414
      fav_list = {};
383
415
 
384
 
      const string APP_PREFIX = "application://";
385
 
      const string FILE_PREFIX = "file://";
386
 
 
387
416
      foreach (string id in settings.get_strv ("favorites"))
388
417
      {
389
418
        if (id.has_prefix (APP_PREFIX))