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

Use flatpak portal for background and autostart #882

Merged
merged 29 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
116026b
First sketch
leolost2605 Apr 29, 2023
8d25690
Request background and autostart permissions via portal
leolost2605 Apr 29, 2023
aa0d455
Remove daemon
leolost2605 Apr 29, 2023
e7b8b0b
Cleanup
leolost2605 Apr 29, 2023
13349dc
Fix lint
leolost2605 Apr 29, 2023
07c1da8
Fix lint this time for real
leolost2605 Apr 29, 2023
2f9a3b2
Application: Only use background portal if sandboxed
leolost2605 Apr 30, 2023
e7b020f
Revert the removal of the daemon autostart file
leolost2605 Apr 30, 2023
80f385f
Revert removal of daemon.desktop
leolost2605 Apr 30, 2023
89ea109
Merge branch 'master' into use-portal-for-background
leolost2605 May 17, 2023
8cbee7d
Update
leolost2605 May 17, 2023
2894952
Merge branch 'master' into use-portal-for-background
danirabbit May 22, 2023
ff4c636
Merge branch 'master' into use-portal-for-background
leolost2605 May 23, 2023
2fff900
Remove daemon
leolost2605 May 23, 2023
afb471b
Merge branch 'use-portal-for-background' of github.com:elementary/mai…
leolost2605 May 23, 2023
8461ad2
Request autostart only on closing the window
leolost2605 May 23, 2023
ea1231d
Revert unnecessary change
leolost2605 May 23, 2023
de7b8fa
Releas on failure
leolost2605 May 23, 2023
c2e688e
Always ask for background
leolost2605 May 23, 2023
d693ee3
Merge branch 'master' into use-portal-for-background
leolost2605 May 23, 2023
b6498ee
Update src/MainWindow.vala
leolost2605 May 24, 2023
fae3625
Don't call hold in startup
leolost2605 May 24, 2023
0c86f2d
Always hold in activate
leolost2605 May 24, 2023
e73d5da
Guard hold with first_activation
leolost2605 Jun 1, 2023
bdca877
Update src/Application.vala
leolost2605 Jun 3, 2023
968dc37
Merge branch 'master' into use-portal-for-background
leolost2605 Jun 3, 2023
44d5e37
Don't release when background request failed
leolost2605 Jun 4, 2023
6b3e7fa
Update warning/debug messages
leolost2605 Jun 4, 2023
7539540
Merge branch 'master' into use-portal-for-background
leolost2605 Jun 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ You'll need the following dependencies:
* libglib2.0-dev
* libgranite-dev >= 6.0.0
* libhandy-1-dev >= 1.1.90
* libportal-dev
* libportal-gtk3-dev
* libwebkit2gtk-4.0-dev
* meson
* valac
Expand Down
11 changes: 0 additions & 11 deletions data/daemon.desktop

This file was deleted.

6 changes: 0 additions & 6 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ foreach i : icon_sizes
)
endforeach

install_data(
'daemon.desktop',
install_dir: join_paths(get_option('sysconfdir'), 'xdg', 'autostart'),
rename: meson.project_name() + '-daemon.desktop'
)

install_data(
meson.project_name() + '.gschema.xml',
install_dir: join_paths(get_option('datadir'), 'glib-2.0', 'schemas')
Expand Down
15 changes: 15 additions & 0 deletions io.elementary.mail.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@
}
]
},
{
"name": "libportal",
"buildsystem": "meson",
"config-opts": [
"-Ddocs=false",
"-Dbackends=['gtk3']"
],
"sources" : [
{
"type": "git",
"url": "https://github.com/flatpak/libportal.git",
"tag": "0.6"
}
]
},
{
"name": "mail",
"buildsystem": "meson",
Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ else
webkit2_dep = dependency('webkit2gtk-4.0', version: '>=2.28')
webkit2_web_extension_dep = dependency('webkit2gtk-web-extension-4.0', version: '>=2.28')
endif
libportal_dep = dependency('libportal')
libportal_gtk_dep = dependency('libportal-gtk3')
folks_dep = dependency('folks')
m_dep = meson.get_compiler('c').find_library('m')

Expand All @@ -39,6 +41,8 @@ dependencies = [
camel_dep,
libedataserver_dep,
libedataserverui_dep,
libportal_dep,
libportal_gtk_dep,
webkit2_dep,
folks_dep,
m_dep
Expand Down
24 changes: 24 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ public class Mail.Application : Gtk.Application {

new InboxMonitor ().start.begin ();
hold ();
leolost2605 marked this conversation as resolved.
Show resolved Hide resolved

request_background.begin ((obj, res) => {
var result = request_background.end (res);
if (!result) {
release ();
}
});
}

public override void activate () {
Expand Down Expand Up @@ -184,6 +191,23 @@ public class Mail.Application : Gtk.Application {

main_window.present ();
}

private async bool request_background () {
var portal = new Xdp.Portal ();

Xdp.Parent? parent = active_window != null ? Xdp.parent_new_gtk (active_window) : null;

var command = new GenericArray<weak string> ();
command.add ("io.elementary.mail");
command.add ("--background");

try {
return yield portal.request_background (parent, _("Mail needs to run in background in order to send notifications."), (owned) command, Xdp.BackgroundFlags.AUTOSTART, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

this line pass the 120 line limit, would be good to break it.

Suggested change
return yield portal.request_background (parent, _("Mail needs to run in background in order to send notifications."), (owned) command, Xdp.BackgroundFlags.AUTOSTART, null);
return yield portal.request_background (
active_window != null ? Xdp.parent_new_gtk (active_window) : null,
_("Mail needs to run in background in order to send notifications."),
(owned) command,
Xdp.BackgroundFlags.AUTOSTART,
null
);

Also, IIRC, the background frontend do not check if the application already has permission, so this would end in the permission dialog begin shown in every launch even when the user already give permission.

in the calendar PR, it stores if it had an successful request and skip the request_background call in the next launches.

} catch (Error e) {
warning ("Failed to request background and autostart permissions: %s", e.message);
return false;
}
}
}

public static int main (string[] args) {
Expand Down