-
Notifications
You must be signed in to change notification settings - Fork 58
Background portal (Rebased 05-21-2025) #70
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
base: master
Are you sure you want to change the base?
Background portal (Rebased 05-21-2025) #70
Conversation
8a4ca82
to
5d6e3f2
Compare
c725ec4
to
57e06f4
Compare
9a93471
to
d2d7b90
Compare
d2d7b90
to
0e5eeb2
Compare
78be554
to
b1026bb
Compare
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. |
c82b8ad
to
ff66c14
Compare
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. |
b4ef89f
to
535c254
Compare
@ids1024 Sorry for the tag! I rebased this on main and tested it again with a few Flatpaks to ensure it still works. To test:
Another useful command is Let me know if there is anything else I should do. Thanks for your time! 😁 |
src/background.rs
Outdated
}; | ||
|
||
AppState { | ||
app_id: info.app_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we don't do anything to verify the value the client gives in https://wayland.app/protocols/xdg-shell#xdg_toplevel:request:set_app_id, even for sandboxed apps. I wonder if that could cause issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I do anything about this? 🤔 I'm not sure how to verify if the ids are real.
src/background.rs
Outdated
#[zvariant(signature = "{sv}")] | ||
struct AppState { | ||
app_id: String, | ||
status: AppStatus, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably instead of HashSet<AppState>
, it could work to just use HashMap<String, AppStatus>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try it. I remember I had some problems figuring out the types, but HashMap<String, AppStatus>
should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I struggled with the types a bit but I finally got it to work again! 😸 I'll squash the last two temp commits pending any additional feedback.
I'll squash that commit after testing tonight or tomorrow. Sorry for taking so long! |
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
b7c92a7
to
1571858
Compare
Squashed: * Rebase on the latest zbus * Fix types for get_app_state to not return an error nor a nested dict * Fix get_app_state so that apps default to running in the background unless they have open toplevels
1571858
to
967b091
Compare
I've taken more of a look at how It uses pop-os/cosmic-protocols#59 has a prototype for how we could expose that on cosmic-comp. But we can probably merge this, and update it to use that later. |
Yep! I saw |
The implementation here generally looks good.
Edit: Easy enough to fix, and it looks like I can push to the branch here. |
`xdg-desktop-portal` expects this. It's easy enough to serialize this way.
It seems we do need to serialize
|
I'm not sure if It seems like GNOME only triggers it for apps that changed its background state (link is to GNOME code). I can update this patch to do so too by caching the old state then checking if an app is newly running in the background. |
It presumably shouldn't be sent every time the focused window changes. But should when an application that is running in the background opens a window, or closes one. Having it sent in response to It's also a bit awkward how |
I replaced the condvar with a subscription but I'll have to test it tomorrow. I pushed the commit anyway in case you want to comment on the code. 😺 I'm not sure what to do about the |
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 implementedCloses: #49