Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toga GTK breaks if status icons are used in Flatpak environemnt #3001

Open
sarayourfriend opened this issue Nov 28, 2024 · 6 comments
Open
Labels
bug A crash or error in behavior. documentation An improvement required in the project's documentation. linux The issue relates Linux support.

Comments

@sarayourfriend
Copy link
Contributor

Describe the bug

Toga GTK's status icon implementation relies on the Xapps API, which is not available in the GNOME Flatpak runtime.

Steps to reproduce

  1. Build the statusiconapp example on Linux, adding a new entry for a Flatpak target to pyproject.toml
  2. Run the app and observe the crash
$ flatpak run org.beeware.toga.examples.statusiconapp
Traceback (most recent call last):
  File "/app/briefcase/app_packages/toga_gtk/app.py", line 54, in gtk_startup
    self.interface._startup()
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/app/briefcase/app_packages/toga/app.py", line 664, in _startup
    self.startup()
    ~~~~~~~~~~~~^^
  File "/app/briefcase/app/statusiconapp/app.py", line 14, in startup
    self.status_icons.add(
    ~~~~~~~~~~~~~~~~~~~~~^
        status_1,
        ^^^^^^^^^
        toga.MenuStatusIcon(id="second", text="Other icon"),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        toga.SimpleStatusIcon(icon="resources/blue.png", on_press=self.do_stuff),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/app/briefcase/app_packages/toga/statusicons.py", line 208, in add
    status_icon._impl.create()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/app/briefcase/app_packages/toga_gtk/statusicons.py", line 22, in create
    raise RuntimeError(
    ...<2 lines>...
    )
RuntimeError: Unable to import XApp. Ensure that the system package providing libxapp and its GTK bindings have been installed.

Expected behavior

Documentation should be updated to indicate that the Toga GTK implementation of status icon will crash apps running in Flatpaks.

Screenshots

No response

Environment

  • Operating System: Linux (tested on Fedora both KDE and GNOME)
  • Python version: 3.13
  • Software versions:
    • Briefcase: 0.3.20
    • Toga: main

Logs

No response

Additional context

No response

@sarayourfriend sarayourfriend added the bug A crash or error in behavior. label Nov 28, 2024
@freakboy3742 freakboy3742 added linux The issue relates Linux support. documentation An improvement required in the project's documentation. labels Nov 28, 2024
@freakboy3742
Copy link
Member

Thanks for the report. Agreed that if this is the current state, it should be documented; the bigger question is whether it is possible to be fixed at all. You could argue (badly) that it is documented in that Toga's docs say that XApps is a required library... but the connection between that a Flatpak deployment definitely won't be clear, so it should be made explicit.

My guess is that the fix here is going to be adding XApps as a binary build step in the Flatpak manifest - either as an additional build step, or by defining a "Briefcase Gnome" base image for the Flatpak runtime. That sounds like a lot of work to maintain, though. It might be worth exploring whether it would be possible to leverage a "system_packages" style declaration for installing libraries that can be built in the flatpak. I'll open a Briefcase ticket to track this.

@rmartin16
Copy link
Member

FWIW, a "runtime extension" seems like a reasonable approach as well. It is interesting, though, that this seeming doesn't already exist...

Additionally, Flatpak seems to have some words about status icons. They also explicitly mention XEmbed working to add status icons.

@freakboy3742
Copy link
Member

FWIW, a "runtime extension" seems like a reasonable approach as well. It is interesting, though, that this seeming doesn't already exist...

It turns out - this option does exist - so no new ticket is needed.

Adding something like:

modules_extra_content = """
  - name: xapps
    buildsystem: meson
    config-opts:
      - -Dbuild_man=false
    sources:
      - type: archive
        url: https://github.com/linuxmint/xapp/archive/refs/tags/master.mint22.tar.gz
"""

will add a libxapps build and install into the project before the app code is installed. (That code sample likely needs some tweaking to the actual build instructions)

Additionally, Flatpak seems to have some words about status icons. They also explicitly mention XEmbed working to add status icons.

IIRC, XApps status icons meet the XEmbed standard; the rest of that section matches what I'd expect of a Linux Desktop - "The concept exists, but there's no guarantee they'll actually be visible, so don't rely on them for core functionality" - which is what the Toga docs already say.

@sarayourfriend
Copy link
Contributor Author

sarayourfriend commented Nov 28, 2024

Yeah, the entire concept of status notifiers on Linux desktop is unfortunately complex, and has an ambiguous future, especially if trying to consider a cross-DE solution. The current Toga GTK implementation for status icons doesn't work on KDE, even though KDE has a status tray. It's unfortunate XApps doesn't try to use StatusNotifierItem (SNI). I wonder if Toga GTK could detect the desktop environment and use SNI directly when on KDE? I'd like to know which DEs support SNI, but at least with the quick searching I've done just now, I can't tell for sure which ones support it. From what I understand, it isn't easy to directly translate concepts between XApps, XEmbed, and SNI 😞

Fully agreed that this situation is pretty much par for the course, and anything that happens to "just work" everywhere is more of a bonus when it comes to desktop Linux. Toga docs make that clear, for sure 👍

@rmartin16
Copy link
Member

FWIW, a "runtime extension" seems like a reasonable approach as well. It is interesting, though, that this seeming doesn't already exist...

It turns out - this option does exist - so no new ticket is needed.

Adding something like:

modules_extra_content = """
  - name: xapps
    buildsystem: meson
    config-opts:
      - -Dbuild_man=false
    sources:
      - type: archive
        url: https://github.com/linuxmint/xapp/archive/refs/tags/master.mint22.tar.gz
"""

will add a libxapps build and install into the project before the app code is installed. (That code sample likely needs some tweaking to the actual build instructions)

Yeah, I had tried something like this....but I seem to end up in a potential dependency hell.

[statusiconapp] Building Flatpak...

(flatpak-builder:2163830): flatpak-builder-WARNING **: 18:17:16.800: Unknown property runtime-extensions for type BuilderManifest
Emptying app dir 'build'
Downloading sources
Starting build of org.beeware.toga.examples.statusiconapp
Cache miss, checking out last cache hit
========================================================================
Building module xapps in /home/russell/github/beeware/toga/examples/statusiconapp/build/statusiconapp/linux/flatpak/.flatpak-builder/build/xapps-2
========================================================================
The Meson build system
Version: 1.5.2
Source dir: /run/build/xapps
Build dir: /run/build/xapps/_flatpak_build
Build type: native build
Project name: xapp
Project version: 2.8.6
C compiler for the host machine: ccache cc (gcc 14.2.0 "cc (GCC) 14.2.0")
C linker for the host machine: cc ld.bfd 2.43.1
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: YES (/usr/bin/pkg-config) 2.3.0
Run-time dependency dbus-1 found: YES 1.14.10
Configuring config.h using configuration
Run-time dependency gio-2.0 found: YES 2.82.2
Run-time dependency gio-unix-2.0 found: YES 2.82.2
Run-time dependency glib-2.0 found: YES 2.82.2
Run-time dependency gtk+-3.0 found: YES 3.24.43
Run-time dependency gmodule-2.0 found: YES 2.82.2
Run-time dependency gdk-pixbuf-2.0 found: YES 2.42.12
Run-time dependency cairo found: YES 1.18.2
Run-time dependency x11 found: YES 1.8.10
Dependency gio-2.0 found: YES 2.82.2 (cached)
Program /usr/bin/gdbus-codegen found: YES (/usr/bin/gdbus-codegen)
Found CMake: /usr/bin/cmake (3.31.0)
Run-time dependency libgnomekbdui found: NO (tried pkgconfig and cmake)

../libxapp/meson.build:75:15: ERROR: Dependency "libgnomekbdui" not found, tried pkgconfig and cmake

A full log can be found at /run/build/xapps/_flatpak_build/meson-logs/meson-log.txt
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.
Error: module xapps: Child process exited with code 1
Building... errored

Error while building app statusiconapp.

@freakboy3742
Copy link
Member

I wonder if Toga GTK could detect the desktop environment and use SNI directly when on KDE? I'd like to know which DEs support SNI, but at least with the quick searching I've done just now, I can't tell for sure which ones support it. From what I understand, it isn't easy to directly translate concepts between XApps, XEmbed, and SNI 😞

I don't have any objection to having a parallel implementation of status icons to support a different underlying protocol - as long as someone else does the leg work to work out how it works and implement it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior. documentation An improvement required in the project's documentation. linux The issue relates Linux support.
Projects
None yet
Development

No branches or pull requests

3 participants