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

Implement support for XDG Desktop Portal #4406

Merged
merged 20 commits into from
Dec 22, 2023

Conversation

Jacalz
Copy link
Member

@Jacalz Jacalz commented Nov 18, 2023

Description:

This is a WIP PR to implement support for using XDG Desktop Portal (https://flatpak.github.io/xdg-desktop-portal/) for interacting with the host system (notifications, file choosers etc.). At this point only notifications are added.

I have decided to only use these when we compile with -tags flatpak for now. If we want to use native file dialogs outside of the sandbox then that's a different decision to be had.

Fixes #3378, #3377

File and folder dialogs

Everything except for file filters and changing the dismiss button text has been set up and is working perfect. The first one seems like it might be problematic to get working but should be possible. The latter will not be possible to implement (and probably doesn't matter that much).

Running inside Flatpak with no added file or notification permissions:
Screencast from 2023-11-19 21-50-07.webm

Opening URLS

The app.OpenURL() method has been updated to use the OpenURI portal. Not 100% necessary because the xdg-open command we used before already works but going through the portal is the recommended approach as far as I know. It should allow the user to theoretically deny an app from opening links.

Notifications

From the documentation:

The portal only accepts serialized GThemedIcon and GBytesIcons. Both of these have the form (sv). For themed icons, the string is "themed", and the value is an array of strings containing the icon names. For bytes icons, the string is "bytes", and the value is a bytestring containing the icon data in png, jpeg or svg form. For historical reasons, it is also possible to send a simple string for themed icons with a single icon name. 

I decided to go with the last part where we can use the name of the application icon. It has the downside of resulting in applications having no icon unless they have been installed. It is perhaps not optimal but it is a lot better than no icon at all and I didn't want to mess around with some GTK icon serialization stuff.

The code is currently using the appID as the icon key even though we are building tarballs where the icon is named after the application name in fyne package. Flatpak and other tools want the desktop files and icons to be named after the application id and not the application name so we were doing the wrong thing all along. I will update the code to use that instead.

No icon:
image

Using io.github.jacalz.rymdport as appID (with it installed) works:
image

TODO:

  • Switch Linux/BSD tarballs using fyne package to use appid instead of app name for files.
  • Look at dialog.FileDialog and dialog.FolderDialog implementations with FileChooser.
  • Look into opening links using OpenURI.
  • Implement a way to get the parent window.
  • Get parent window working on Wayland as well.
  • Get file filters working.
  • Only use these portals when compiling with -tags flatpak.

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

@coveralls
Copy link

coveralls commented Nov 18, 2023

Coverage Status

coverage: 65.047% (-0.05%) from 65.096%
when pulling 212042d on Jacalz:poc-desktop-portals
into 4a18a7f on fyne-io:develop.

@Jacalz Jacalz changed the title Initial support for notifications through xdg-desktop-portal Implement support for XDG Desktop Portal Nov 18, 2023
@Jacalz

This comment was marked as outdated.

@Jacalz
Copy link
Member Author

Jacalz commented Nov 19, 2023

Never mind. I've decided to only use these portals when compiling with a new flatpak buildtag.

@Jacalz Jacalz marked this pull request as ready for review November 21, 2023 21:54
@Jacalz
Copy link
Member Author

Jacalz commented Nov 21, 2023

I couldn't figure out how to get the Wayland window handle so I think I'll leave that until another time. The way file filters work also seem to be very different so I think it would be wise to tackle that later as well. This should be good to be reviewed now. It is working very nicely :)

@Jacalz Jacalz force-pushed the poc-desktop-portals branch from 06c675b to 212042d Compare November 27, 2023 12:12
Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

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

This is really cool thanks so much.

Can you open a new issue (or PR? ;) ) to track the missing waylaid handle lookup and file filter etc?

@Jacalz
Copy link
Member Author

Jacalz commented Dec 22, 2023

Sure. I'll open an issue for now but will likely try to implement it myself going forward. Especially now with Wayland takin shape

@Jacalz Jacalz merged commit 62c45ee into fyne-io:develop Dec 22, 2023
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.

3 participants