60
60
const std::shared_ptr<Registry>& registry,
61
61
const std::string& interface,
62
62
const std::string& snapDir)
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);
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);
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)
84
const gchar* prefix{nullptr};
85
if (g_str_has_prefix(iconvalue, "${SNAP}/"))
87
/* There isn't environment parsing in desktop file values :-( */
91
auto currentdir = std::string{"/snap/"} + appid.package.value() + "/current/";
92
if (g_str_has_prefix(iconvalue, currentdir.c_str()))
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();
99
if (prefix != nullptr)
101
g_key_file_set_string(keyfile.get(), "Desktop Entry", "Icon", iconvalue + strlen(prefix) - 1);
102
/* -1 to leave trailing slash */
112
app_info::DesktopFlags::NONE,
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);
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);
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)
84
const gchar* prefix{nullptr};
85
if (g_str_has_prefix(iconvalue, "${SNAP}/"))
87
/* There isn't environment parsing in desktop file values :-( */
91
auto currentdir = std::string{"/snap/"} + appid.package.value() + "/current/";
92
if (g_str_has_prefix(iconvalue, currentdir.c_str()))
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();
99
if (prefix != nullptr)
101
g_key_file_set_string(keyfile.get(), "Desktop Entry", "Icon",
102
iconvalue + strlen(prefix) - 1);
103
/* -1 to leave trailing slash */
113
app_info::DesktopFlags::NONE,
114
115
, interface_(interface)