~ci-train-bot/ubuntu-app-launch/ubuntu-app-launch-ubuntu-zesty-2531

« back to all changes in this revision

Viewing changes to libubuntu-app-launch/application-impl-snap.cpp

  • Committer: Bileto Bot
  • Author(s): Ted Gould
  • Date: 2017-02-15 15:09:51 UTC
  • mfrom: (274.2.17 zg-ordering)
  • Revision ID: ci-train-bot@canonical.com-20170215150951-r736n25rz2vlg68t
Provide a popularity info item and a signal for info updating

Approved by: Charles Kerr

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
             const std::shared_ptr<Registry>& registry,
61
61
             const std::string& interface,
62
62
             const std::string& snapDir)
63
 
        : Desktop(
64
 
              [appid, snapDir]() -> std::shared_ptr<GKeyFile> {
65
 
                  /* This is a function to get the keyfile out of the snap using
66
 
                     the paths that snappy places things inside the dir. */
67
 
                  std::string path = snapDir + "/meta/gui/" + appid.appname.value() + ".desktop";
68
 
                  std::shared_ptr<GKeyFile> keyfile(g_key_file_new(), g_key_file_free);
69
 
                  GError* error = nullptr;
70
 
                  g_key_file_load_from_file(keyfile.get(), path.c_str(), G_KEY_FILE_NONE, &error);
71
 
                  if (error != nullptr)
72
 
                  {
73
 
                      auto perror = std::shared_ptr<GError>(error, g_error_free);
74
 
                      throw std::runtime_error("Unable to find keyfile for '" + std::string(appid) + "' at '" + path +
75
 
                                               "' because: " + perror.get()->message);
76
 
                  }
77
 
 
78
 
                  /* For bad reasons the Icon values in snaps have gotten to be a
79
 
                     bit crazy. We're going to try to un-fu-bar a few common patterns
80
 
                     here, but eh, we're just encouraging bad behavior */
81
 
                  auto iconvalue = g_key_file_get_string(keyfile.get(), "Desktop Entry", "Icon", nullptr);
82
 
                  if (iconvalue != nullptr)
83
 
                  {
84
 
                      const gchar* prefix{nullptr};
85
 
                      if (g_str_has_prefix(iconvalue, "${SNAP}/"))
86
 
                      {
87
 
                          /* There isn't environment parsing in desktop file values :-( */
88
 
                          prefix = "${SNAP}/";
89
 
                      }
90
 
 
91
 
                      auto currentdir = std::string{"/snap/"} + appid.package.value() + "/current/";
92
 
                      if (g_str_has_prefix(iconvalue, currentdir.c_str()))
93
 
                      {
94
 
                          /* What? Why would we encode the snap path from root in a package
95
 
                             format that is supposed to be relocatable? */
96
 
                          prefix = currentdir.c_str();
97
 
                      }
98
 
 
99
 
                      if (prefix != nullptr)
100
 
                      {
101
 
                          g_key_file_set_string(keyfile.get(), "Desktop Entry", "Icon", iconvalue + strlen(prefix) - 1);
102
 
                          /* -1 to leave trailing slash */
103
 
                      }
104
 
 
105
 
                      g_free(iconvalue);
106
 
                  }
107
 
 
108
 
                  return keyfile;
109
 
              }(),
110
 
              snapDir,
111
 
              snapDir,
112
 
              app_info::DesktopFlags::NONE,
113
 
              registry)
 
63
        : Desktop(appid,
 
64
                  [appid, snapDir]() -> std::shared_ptr<GKeyFile> {
 
65
                      /* This is a function to get the keyfile out of the snap using
 
66
                         the paths that snappy places things inside the dir. */
 
67
                      std::string path = snapDir + "/meta/gui/" + appid.appname.value() + ".desktop";
 
68
                      std::shared_ptr<GKeyFile> keyfile(g_key_file_new(), g_key_file_free);
 
69
                      GError* error = nullptr;
 
70
                      g_key_file_load_from_file(keyfile.get(), path.c_str(), G_KEY_FILE_NONE, &error);
 
71
                      if (error != nullptr)
 
72
                      {
 
73
                          auto perror = std::shared_ptr<GError>(error, g_error_free);
 
74
                          throw std::runtime_error("Unable to find keyfile for '" + std::string(appid) + "' at '" +
 
75
                                                   path + "' because: " + perror.get()->message);
 
76
                      }
 
77
 
 
78
                      /* For bad reasons the Icon values in snaps have gotten to be a
 
79
                         bit crazy. We're going to try to un-fu-bar a few common patterns
 
80
                         here, but eh, we're just encouraging bad behavior */
 
81
                      auto iconvalue = g_key_file_get_string(keyfile.get(), "Desktop Entry", "Icon", nullptr);
 
82
                      if (iconvalue != nullptr)
 
83
                      {
 
84
                          const gchar* prefix{nullptr};
 
85
                          if (g_str_has_prefix(iconvalue, "${SNAP}/"))
 
86
                          {
 
87
                              /* There isn't environment parsing in desktop file values :-( */
 
88
                              prefix = "${SNAP}/";
 
89
                          }
 
90
 
 
91
                          auto currentdir = std::string{"/snap/"} + appid.package.value() + "/current/";
 
92
                          if (g_str_has_prefix(iconvalue, currentdir.c_str()))
 
93
                          {
 
94
                              /* What? Why would we encode the snap path from root in a package
 
95
                                 format that is supposed to be relocatable? */
 
96
                              prefix = currentdir.c_str();
 
97
                          }
 
98
 
 
99
                          if (prefix != nullptr)
 
100
                          {
 
101
                              g_key_file_set_string(keyfile.get(), "Desktop Entry", "Icon",
 
102
                                                    iconvalue + strlen(prefix) - 1);
 
103
                              /* -1 to leave trailing slash */
 
104
                          }
 
105
 
 
106
                          g_free(iconvalue);
 
107
                      }
 
108
 
 
109
                      return keyfile;
 
110
                  }(),
 
111
                  snapDir,
 
112
                  snapDir,
 
113
                  app_info::DesktopFlags::NONE,
 
114
                  registry)
114
115
        , interface_(interface)
115
116
        , appId_(appid)
116
117
    {
519
520
    return _registry->impl->jobs->existing(appId(), "application-snap", instanceid, std::vector<Application::URL>{});
520
521
}
521
522
 
 
523
std::shared_ptr<info_watcher::Base> Snap::createInfoWatcher(const std::shared_ptr<Registry>& reg)
 
524
{
 
525
    return {};
 
526
}
 
527
 
522
528
}  // namespace app_impls
523
529
}  // namespace app_launch
524
530
}  // namespace ubuntu