mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 15:03:39 +02:00
gio-tool-launch: fix %k field code expansion
As per the desktop entry specification, the `%k` field code should be expanded to the location of the desktop entry file being processed. This is only possible if the constructor-only filename property is populated, which does not happen when using g_desktop_app_info_new_from_keyfile(). Moreover, since the Path directive in a desktop entry can be used to set the working directory for the program to be launched, the location passed as argument to the program must be modified such that it points at the correct file when interpreted by the launched program. The simplest way to achieve this consistently is to pass an absolute path. However, g_desktop_app_info_new_from_keyfile() does not indicate why it fails when it does. Because the tool aims to indicate whether launching failed due to a missing file or a malformed one we first check this with g_key_file_load_from_file().
This commit is contained in:
committed by
Philip Withnall
parent
c2debf4fa9
commit
c924de69f0
@@ -88,12 +88,12 @@ handle_launch (int argc, char *argv[], gboolean do_help)
|
||||
retval = 1;
|
||||
#else
|
||||
retval = 0;
|
||||
desktop_file = argv[1];
|
||||
desktop_file = g_canonicalize_filename (argv[1], NULL);
|
||||
|
||||
/* Use keyfile api for loading desktop app in order to check for
|
||||
* - not existing file.
|
||||
* - invalid keyfile format.
|
||||
*/
|
||||
/* Use g_key_file_load_from_file() to give better user feedback (missing vs.
|
||||
* malformed file), then load it with g_desktop_app_info_new_from_filename()
|
||||
* to set the constructor-only filename property required for expanding %k.
|
||||
*/
|
||||
keyfile = g_key_file_new ();
|
||||
if (!g_key_file_load_from_file (keyfile, desktop_file, G_KEY_FILE_NONE, &error))
|
||||
{
|
||||
@@ -103,7 +103,7 @@ handle_launch (int argc, char *argv[], gboolean do_help)
|
||||
}
|
||||
else
|
||||
{
|
||||
app = (GAppInfo*)g_desktop_app_info_new_from_keyfile (keyfile);
|
||||
app = (GAppInfo *)g_desktop_app_info_new_from_filename (desktop_file);
|
||||
if (!app)
|
||||
{
|
||||
print_error (_("Unable to load application information for ‘%s’"), desktop_file);
|
||||
|
Reference in New Issue
Block a user