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

Background portal #70

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

joshuamegnauth54
Copy link
Contributor

@joshuamegnauth54 joshuamegnauth54 commented Jul 28, 2024

Requires the access portal to be enabled or else it does nothing

I based my implementation on the official specs as well as code from GNOME, KDE, Xapp (Xfce), and Pantheon (elementary). KDE's immaculately readable codebase served as this implementation's primary inspiration.

Like KDE, I intend to show a dialog, so the user may choose whether to grant privileges to an application. I will also provide an option to bypass the dialog for greater choice especially considering that GNOME automatically grants permissions.

According to the docs, the Autostart method is deprecated. However, I think I still need to implement it because background requests aren't routed to the COSMIC portal unless it's available. Autostart is implemented

Closes: #49

@joshuamegnauth54 joshuamegnauth54 force-pushed the feat-background-autorun-portal branch 10 times, most recently from 8a4ca82 to 5d6e3f2 Compare August 4, 2024 11:39
@joshuamegnauth54 joshuamegnauth54 force-pushed the feat-background-autorun-portal branch 3 times, most recently from c725ec4 to 57e06f4 Compare August 8, 2024 06:42
@joshuamegnauth54 joshuamegnauth54 force-pushed the feat-background-autorun-portal branch 3 times, most recently from 9a93471 to d2d7b90 Compare August 18, 2024 05:48
@joshuamegnauth54 joshuamegnauth54 force-pushed the feat-background-autorun-portal branch 4 times, most recently from 78be554 to b1026bb Compare September 11, 2024 02:07
@ids1024
Copy link
Member

ids1024 commented Sep 11, 2024

According to the docs, the Autostart method is deprecated. However, I think I still need to implement it because background requests aren't routed to the COSMIC portal unless it's available.

Looks like it was deprecated in May (flatpak/xdg-desktop-portal@458560c) and the last release was in April. So presumably it's still required on released versions of xdg-desktop-portal, but won't in the next.

I based my implementation on the official specs as well as code from
GNOME, KDE, Xapp (Xfce), and Pantheon (elementary). KDE's imminently
readable codebase served as this implementation's primary inspiration.

Autostart is deprecated but seemingly still used, so this implementation
will still support it for compatibility.

The Background portal depends on a working Access portal as
`xdg-desktop-portal` calls it to show the initial warning.

References:
* https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.impl.portal.Background.html
* https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/blob/main/src/background.c
* https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/blob/master/src/background.cpp
* https://github.com/linuxmint/xdg-desktop-portal-xapp/blob/f1c24244f90571209c56b7f45802b70e80da4922/src/background.c
* https://github.com/elementary/portals/blob/d868cfa854c731e0f37615e225d5db07cc3f4604/src/Background/Portal.vala
* flatpak/xdg-desktop-portal#1188
@joshuamegnauth54 joshuamegnauth54 force-pushed the feat-background-autorun-portal branch 2 times, most recently from 3e21b4e to c82b8ad Compare September 16, 2024 04:32
@joshuamegnauth54
Copy link
Contributor Author

Their reasoning makes sense. Every portal backend I checked implements autostart the same way (which, in a way, was really nice because it made it easier to implement here 😂 ).

This is finally done and it works too! I learned a lot in the process as well.

@joshuamegnauth54 joshuamegnauth54 marked this pull request as ready for review September 18, 2024 06:53
@joshuamegnauth54 joshuamegnauth54 changed the title WIP Background portal Background portal Sep 18, 2024
// xxx Is this the correct way to determine if a program is running in the
// background? If a toplevel exists but isn't running, activated, et cetera,
// then it logically must be in the background (?)
AppStatus::Background
Copy link
Member

@Drakulix Drakulix Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right. A toplevel is a window, this state seems to describe applications without a window. So the logic should be: If any toplevel exists, then the app is either Running or Active. We currently don't have a protocol to enumerate applications without a window.

I would think the portal would have to track apps launched in the background.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review and help!

I checked how GNOME handles GetAppState. GNOME exposes a D-Bus interface that allows retrieving the list of running applications. It also has a signal for app updates.

Its Background portal uses that interface to check app statuses. An app that is running without windows is in the background. Apps with windows have their toplevel status checked (active, running).

KDE doesn't seem to check if a program is in the background at all. 🤔 I find this confusing.

The code for the GNOME background portal is pretty straightforward, but I'll have to check if there is a way to get running apps easily via COSMIC.

Copy link
Member

@Drakulix Drakulix Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't because we don't track "running applications" (which KDE probably also isn't doing), because doing so isn't exactly easy. Any running binary could be an "app".

I assume what Gnome is doing internally is:

  1. Handle flatpaks as apps
  2. Use app-scopes to identify apps it launched through one of it's interfaces (still doesn't help with stuff started e.g. via a terminal).

You can do similar things on cosmic, as we also set the corresponding app-scopes. (e.g. systemctl --user list-units -t scope | grep -e "app-flatpak" -e "app-cosmic")

You would use the systemd dbus interface in the portal to enumerate the scopes, filter for app-cosmic and app-flatpak and pull the app_id from the name (the third component). Afterwards you can lookup the desktop-file, if you need anything more.

@joshuamegnauth54 joshuamegnauth54 marked this pull request as draft September 19, 2024 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Background Portal unsupported
3 participants