Commit Graph

299 Commits

Author SHA1 Message Date
Philip Withnall
21fdb3be24
gappinfo: Move all platform-independent API docs to gappinfo.c
Previously, some of the doc comments for platform-independent APIs were
in `gdesktopappinfo.c`, which is only built on Unix systems. This meant
the introspection annotations for those APIs were not used on non-Unix
systems, which caused platform differences in `Gio-2.0.gir`.

So, move those doc comments to `gappinfo.c` and put them next to some
new platform-independent wrapper functions which provide a consistent
entry point and location for the API preconditions.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3399
2024-07-24 17:45:22 +02:00
Philip Withnall
d1945c7abb
gdesktopappinfo: Add additional links to the Desktop Entry Spec
Might as well make it easy for people to look up what we’re talking
about.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-07-24 14:37:18 +02:00
Philip Withnall
c474d4065d
gdesktopappinfo: Port doc comments to gi-docgen syntax
Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3250
2024-07-24 14:23:18 +02:00
Georges Basile Stavracas Neto
b8db83940b gio/appinfo: Port docs to gi-docgen
Adjust all docs to use the gi-docgen referencing syntax, reindent
some of the comments, and add missing annotations to some async
methods.

The error arguments are not necessary with gi-docgen so they're
removed.

Confusingly enough, the docks for GAppInfo is spread between two
files.
2024-07-11 15:33:41 +01:00
Philip Withnall
b3cd9aaa98
gdesktopappinfo: Fix a maybe-uninitialized warning
scan-build thinks that `term_arg` could be used uninitialised. I think
there isn’t a bug here because that use is protected by the
`found_terminal == NULL` check and early return. But perhaps that logic
is a bit too complex for static analysis, so add a default value for the
variable.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
2024-04-25 23:15:55 +01:00
Philip Withnall
434d3ff524 docs: Mention GioUnix-2.0 GIR namespace alongside gio-unix-2.0.pc
This should clarify things a little for users of language bindings, who
don’t directly use `.pc` files.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-02-12 17:54:10 +00:00
Sophie Herold
0d268c4825 Remove all nicks and blurbs from param specs
Nicks and blurbs don't have any practical use for gio/gobject libraries.
Leaving tests untouched since this features is still used by other libraries.

Closes #2991
2023-11-29 13:41:34 +00:00
Philip Withnall
6c930587ad docs: Move the GDesktopAppInfo SECTION
Move it to the struct docs.

Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>

Helps: #3037
2023-10-25 15:10:16 +01:00
Alex Richardson
a1dfecf11f Use g_once_init_{enter,leave}_pointer where appropriate
This should not result in any functional changes, but will eventually
allow glib to be functional on CHERI-enabled systems such as Morello.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2842
2023-10-04 13:57:16 +01:00
Florian Müllner
794b18df34 gdesktopappinfo: Do not search Comment field
The Comment field provides a user-visible description of the app,
which usually contains generic words ("and", "or", "not", "is", ...)
that add noise when used for search.

It made some sense to match against the field as a fallback for
Keywords, before that key was well established. However that key
has been around for years now, so hopefully every app where additional
terms are helpful uses it by now.

With that, the downside of added noise outweighs the benefit, so
it's time to stop matching on comments.
2023-10-03 14:05:27 +02:00
Nelson Benítez León
40f567aa2a GDesktopAppInfo: prioritize match_type over match_category when searching apps
Commit 9e2ad88455 improved app search results by allowing to differentiate
their match_type: prefix match or substring match; while giving more priority
to prefix matches over substring matches, but only when they are in the same
match_category[1].

This was a step forward but, as outlined in #3082, still not enough to get
most relevant results first to the user, because apparently (and for the
specific case of desktop app searching) a prefix match in a lower category
is more relevant to the user than a substring match in a higher category.

So that's what this commit implements, i.e. it makes sure prefix matches
are still preferred over substring matches but this time not only when
in the same category but also across different categories.

[1] Match category is the Desktop file key where the match happened.
    They are shown below from top to lesser priority.
      DESKTOP_KEY_Name
      DESKTOP_KEY_Exec
      DESKTOP_KEY_Keywords
      DESKTOP_KEY_GenericName
      DESKTOP_KEY_X_GNOME_FullName
      DESKTOP_KEY_Comment

Fixes #3082
2023-10-03 09:10:21 +01:00
Philip Withnall
7cd57b3e85 gdesktopappinfo: Add a missing NULL check
It’s possible for the startup ID to be `NULL` if one wasn’t provided in
the platform data passed to `launch_uris_with_dbus()`.

Passing `NULL` to `g_app_launch_context_launch_failed()` causes a
critical warning.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-14 14:37:14 +00:00
Philip Withnall
438bd5cfa1 gutils: Make g_find_program_for_path() a proper private API
It’s not meant to be exposed publicly yet (we’re not ready to stabilise
it), but it was incorrectly decorated with `GLIB_AVAILABLE_IN_2_76`.

We can’t remove the decorator and use it that way, as it’s called in
libgio, so we have to expose it using `GLIB_PRIVATE_CALL()`.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2876
2023-02-13 16:12:07 +00:00
Sebastian Dröge
79fd6fd6a0 Fix a couple of closure annotations 2023-01-13 18:06:23 +02:00
Philip Withnall
8463155b21 gdesktopappinfo: Drop an unnecessary NULL check
`search_token` cannot be `NULL` at this point (guaranteed by all the
current call sites of `desktop_file_dir_unindexed_search()`), so remove
an unnecessary `NULL` check.

Add an assertion to make the nullability clear.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Coverity CID: #1502196, #1502193
2022-12-29 15:57:53 +00:00
Philip Withnall
9e2ad88455 Merge branch 'search-app-prefix-strstr' into 'main'
gdesktopappinfo: Group search results by both categories and match types

See merge request GNOME/glib!3107
2022-12-21 11:42:35 +00:00
Alynx Zhou
f81a9d226b gdesktopappinfo: Group search results by both categories and match types
Substring matches can have too much unwanted results, while prefix
matches is more accurate but cannot handle some special cases, this
commit combines them by adding a match_type member, then sort and group
result with both categories and match types.

For the same category, prefix matched results will be put in the first
group and substring matched results will be put in the second group.
2022-12-20 09:59:09 +08:00
Philip Withnall
d3a26bb4de Merge branch 'activation-token' into 'main'
gdesktopappinfo: Set XDG_ACTIVATION_TOKEN/activation-token startup ID key

Closes #2709

See merge request GNOME/glib!3090
2022-12-19 13:05:57 +00:00
Ilya Fedin
627f2738e0 gdesktopappinfo: Set XDG_ACTIVATION_TOKEN/activation-token startup ID key
See:
 * https://gitlab.freedesktop.org/xdg/xdg-specs/-/blob/master/desktop-entry/desktop-entry-spec.xml#L1061-1068
 * https://wayland.app/protocols/xdg-activation-v1
 * https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/staging/xdg-activation/x11-interoperation.rst

Fixes: #2709
2022-12-19 12:45:02 +00:00
Marco Trevisan (Treviño)
511d1cad02 gdesktopappinfo: Fail early if trying to launch an invalid executable
GDesktopAppInfo never failed in the most simple of the cases: when a
desktop file or a command line app info was pointing to an invalid
executable (for the context).

The reason for this is that we're launching all the programs using
gio-launch-desktop which will always exist in a sane GLib installation,
and thus our call to execvp won't ever fail on failure.

This was partially mitigated by not allowing to create a desktop app
icon using a non-existent executable (even if not fully correctly) but
still did not work in case a custom PATH was provided in the launch
context.

To avoid this, use g_find_program_for_path() to find early if a program
that we're about to launch is available, and if it's not the case return
the same error that g_spawn_async_with_fds() would throw in such cases.

While this is slowing a bit our preparation phase, would avoid to leave
to the exec function the job to find where our program is.

Add tests simulating this behavior.
2022-12-12 15:58:13 +01:00
Marco Trevisan (Treviño)
da8aa0b66d desktop-app-info: Use launch context PATH and desktop Path to find terminals
We used to launch applications with terminals using the normal program
finder logic that did not consider the context path nor the desktop file
working dir. Switch to g_find_program_for_path() to find terminals so we
can ensure that both conditions are true.

Update tests to consider this case too.
2022-12-12 15:58:13 +01:00
Marco Trevisan (Treviño)
e41e3dc601 gdesktopappinfo: Take in account the desktop Path to find executables
Desktop files can provide the executable working path and that can be
used to pick the file to launch.

So take it in account.
2022-12-12 15:58:13 +01:00
Alynx Zhou
6dd5f2515f gdesktopappinfo: Use strstr instead of g_str_has_prefix for search
Fixes: #1152
2022-12-02 19:19:47 +00:00
Maxime Gervais
ae65753b16 Add kgx (gnome console) known terminals lists 2022-10-27 00:21:39 +02:00
Marco Trevisan
b9e68b0bd4 Merge branch 'support-xdg-terminal-exec' into 'main'
Add support for xdg-terminal-exec for handling desktop applications using 'Terminal=true'

See merge request GNOME/glib!2839
2022-10-26 17:03:12 +00:00
Max Gautier
22e1b9bcc0 gio: add xdg-terminal-exec as a known terminal
Allow users to select their terminal of choice by using the
xdg-terminal-exec wrapper.

It is a temporary temporary solution while waiting for the
xdg-default-apps specification
(https://gitlab.freedesktop.org/xdg/xdg-specs/-/issues/54), in
accordance with this comment:
https://gitlab.gnome.org/GNOME/glib/-/issues/338#note_1076172
2022-10-26 18:41:26 +02:00
Max Gautier
b64347d279 gio: add support for terminal with no option
Introduce support for terminals executing commands without an option,
i.e., the command is passed directly as argument to the terminal emulator.
This is needed for xdg-terminal-exec.
2022-10-26 18:41:26 +02:00
Max Gautier
eb2d1d8fc8 gio: Refactor the known terminals search
Get rid of multiple conditionals branch by using a loop and storing the
options needed by particular terminal emulators directly in an array.
Remove intermediate variable term_argv as we don't need it.

Advantages:
- simpler logic, less branching
- the terminal emulator list is more readable, by virtue of being
  condensed in one array. Launch options to execute a terminal program
  are also more explicitly specified
- the logic become independent from the order
- one less allocation
2022-10-26 18:15:26 +02:00
Marco Trevisan (Treviño)
dafd6602dc gio/gdesktopappinfo: Free the wrapped argv array on launch failure
We create an array that we never free, ensure this is the case.
The previous commit gives CI a chance to check this with valgrind job.

Found as part of another review:
 - https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2839#note_1524922
2022-10-25 14:33:25 +02:00
Emmanuele Bassi
bafd025811 Merge branch 'ebassi/gcc-12-fixes' into 'main'
Fix array-bounds compiler warnings with GCC 12

See merge request GNOME/glib!2873
2022-09-02 23:17:25 +00:00
Marco Trevisan (Treviño)
221f22b6e1 gdesktopappinfo: Unref the GDBus call results
On our GDBus call callback wrapper we were completing the gdbus call but
ignoring the returned value, that was always leaked.

Fix this.

Helps with: https://gitlab.gnome.org/GNOME/glib/-/issues/333
2022-09-02 21:21:34 +02:00
Marco Trevisan (Treviño)
026a69905e gdesktopappinfo: Unref GDBus call result GVariant if no callback is set
When launching URIs via dbus we may ignore the callback if one was not
provided, however in such case we were also leaking the return value for
the gdbus call.

Unref it properly.

Helps with: https://gitlab.gnome.org/GNOME/glib/-/issues/333
2022-09-02 21:21:34 +02:00
Emmanuele Bassi
e08c954693 Fix check before a memcpy
The search_total_results address is always going to be non-zero, so the
check will always evaluate to true, and GCC is kind enough to point this
out to us.

The appropriate fix is checking if the size of the search results array
is larger than zero, and if so, copy them into the total results array.
2022-09-02 12:59:22 +01:00
Luca Bacci
d12cf95836 GDesktopAppInfo: Tidy up code a bit
* Remove an unneeded field from LaunchUrisData and add annotations
* Rename local GError* variables to local_error
* Use g_set_object
* Fix indentation
2022-08-26 11:33:22 +02:00
Simon McVittie
ae15c800ce Install gio-launch-desktop in a non-PATH location
This is an internal helper executable, which users shouldn't invoke
directly (see glib#1633).

When building for a single-architecture distribution, we can install
it as ${libexecdir}/gio-launch-desktop.

When building for a multiarch distribution, installing it into an
architecture-specific location and packaging it alongside the GLib
library avoids the problem discussed in glib#1633 where it would either
cause a circular dependency between the GLib library and a common
cross-architecture package (libglib2.0-bin in Debian), or require a
separate package just to contain gio-launch-desktop, or cause different
architectures' copies to overwrite each other.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:53 +02:00
Simon McVittie
8157668eac gdesktopappinfo: Don't trust $GIO_LAUNCH_DESKTOP if setuid
gio-launch-desktop was removed before checking GIO for potentially
unsafe environment variable references, so reverting its removal brought
this one back. If a setuid program is using GAppInfo then something is
probably already horribly wrong, but let's be careful anyway.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:53 +02:00
Simon McVittie
d0967c1d4a Revert "gdesktopappinfo: Use sh rather than gio-launch-desktop"
A shell one-liner was enough to set GIO_LAUNCHED_DESKTOP_FILE_PID,
but ideally we also want to do the equivalent of sd_journal_stream_fd()
to set up its standard output and standard error streams.

Ideally we would call sd_journal_stream_fd() in a process that will
exec the real program, otherwise it will report the wrong process ID
in the Journal, but we can't easily do that in a forked child when
using posix_spawn() for subprocesses.

This reverts commit 2b533ca99a.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-25 01:00:53 +02:00
Marco Trevisan (Treviño)
eee15225c7 GDesktopAppInfo: Ignore flushing the session bus when there's not
In some cases (such as in our CI tests) we may not have any dbus session
set after launching, but we always assumed so.

In case we have not a session bus set, we only have to return early.
2022-06-22 20:07:30 +02:00
Marco Trevisan (Treviño)
6fef60b65c GDesktopAppInfo: Ensure that URI scheme is a valid argument 2022-06-22 20:07:30 +02:00
Philip Withnall
5942cd7984 gio: Add SPDX license headers automatically
Add SPDX license (but not copyright) headers to all files which follow a
certain pattern in their existing non-machine-readable header comment.

This commit was entirely generated using the command:
```
git ls-files gio/*.[ch] | xargs perl -0777 -pi -e 's/\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/\n \*\n \* SPDX-License-Identifier: LGPL-2.1-or-later\n \*\n \* This library is free software; you can redistribute it and\/or\n \* modify it under the terms of the GNU Lesser General Public/igs'
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1415
2022-05-18 09:18:52 +01:00
Gabor Karsay
7e64004db0 docs: mark macros, flags, enums with percent sign 2022-03-04 16:21:55 +00:00
Philip Withnall
cb18e6b969 Merge branch 'empty-argv' into 'main'
Various minor fixes for empty argv handling

See merge request GNOME/glib!2466
2022-02-20 09:36:41 +00:00
Philip Withnall
f6aafcd028 gdesktopappinfo: Fix a leak when launching URIs over D-Bus
If any platform data is set, the temporary `GVariantDict` was being
leaked.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-18 10:35:10 +00:00
Philip Withnall
11654811ef gdesktopappinfo: Add checks for empty argv
There shouldn’t be any issues here with empty argv arrays since an empty
`Exec=` line is already checked for. Encode that explicitly with an
assertion.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2022-02-11 14:45:42 +00:00
Ivaylo Dimitrov
f065497acf GDesktopAppInfo: Try to always correctly set id
Specs say that on Unix id should be desktop file id from the xdg menu
specification, however, currently code just uses basename of .desktop file.
Fix that by finding the .desktop file in all the desktop_file_dirs and use
basename only as a fallback.

See https://specifications.freedesktop.org/menu-spec/latest/go01.html#term-desktop-file-id
and https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s02.html#desktop-file-id

"To determine the ID of a desktop file, make its full path relative to the
$XDG_DATA_DIRS component in which the desktop file is installed, remove the
"applications/" prefix, and turn '/' into '-'."

Also, add unit test that verifies Desktop Id is being correctly set

Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
2021-12-14 11:46:57 +00:00
Guido Günther
7665b748bb gappinfo: Add launch-started signal
Emit this when we're about to spawn or DBus activate a GAppInfo.  This
allows lauchers to keep the appinfo associated with a startup id.

We use a GVariant to allow for future exansion of the supplied data.
2021-10-04 10:29:08 +02:00
Guido Günther
5890b2bdea gdesktopappinfo: Emit "launched" and "launch-failed" signals for DBus activation too
When using g_desktop_app_info_launch_uris_as_manager the "launched"
signal allows to map a desktop-startup-id to a GAppInfo. Make this
possible for DBus activation too.

Since we don't have a PID there we pass a 0. Update the signal
description accordingly.
2021-10-04 10:29:08 +02:00
shironeko
b60cd327fe gdesktopappinfo: Return failure rather than blindly call xterm
Instead of calling xterm when it clearly does not exist and causes a silent error,
inform the user that the launch failed so they can take the right action.
2021-09-09 10:32:44 -04:00
Simon McVittie
e0b6b8037d Distinguish more clearly between wait status and exit status
On Unix platforms, wait() and friends yield an integer that encodes
how the process exited. Confusingly, this is usually not the same as
the integer passed to exit() or returned from main(): conceptually it's
an integer encoding of this tagged union:

    enum { EXITED, SIGNALLED, ... } tag;
    union {
        int exit_status;         /* if EXITED */
        struct {
            int terminating_signal;
            bool core_dumped;
        } terminating_signal;    /* if SIGNALLED */
        ...
    } detail;

Meanwhile, on Windows, wait statuses and exit statuses are
interchangeable.

I find that it's clearer what is going on if we are consistent about
referring to the result of wait() as a "wait status", and the value
passed to exit() as an "exit status".

GSubprocess already gets this right: g_subprocess_get_status() returns
the wait status, while g_subprocess_get_exit_status() genuinely returns
the exit status. However, the GSpawn family of APIs has tended to
conflate the two.

Confusingly, g_spawn_check_exit_status() has always checked a wait
status, and it would not be correct to pass an exit status to it; so
let's deprecate it in favour of g_spawn_check_wait_status(), which
does the same thing that g_spawn_check_exit_status() always did.
Code that needs backwards-compatibility with older GLib can use:

    #if !GLIB_CHECK_VERSION(2, 69, 0)
    #define g_spawn_check_wait_status(x) (g_spawn_check_exit_status (x))
    #endif

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-06-15 14:33:14 +01:00
Jan Kot
0b0fcfad11 Add support for Tilix and Konsole 2021-02-03 20:44:55 +01:00