From 116026b87d684cc9a39a4a26cf5dda0190b4cdc1 Mon Sep 17 00:00:00 2001 From: Leonhard K Date: Sat, 29 Apr 2023 12:47:00 +0200 Subject: [PATCH 01/22] First sketch --- meson.build | 4 ++++ src/Application.vala | 15 +++++++++++++++ src/MessageList/MessageListItem.vala | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 93fe3a47c..1c67e735c 100644 --- a/meson.build +++ b/meson.build @@ -26,6 +26,8 @@ else webkit2_web_extension_dep = dependency('webkit2gtk-web-extension-4.0', version: '>=2.28') endif folks_dep = dependency('folks') +xdp_dep = dependency('libportal') +xdpgtk_dep = dependency('libportal-gtk3') m_dep = meson.get_compiler('c').find_library('m') webkit2_extension_path = join_paths(get_option('prefix'), get_option('libdir'), meson.project_name(), 'webkit2') @@ -41,6 +43,8 @@ dependencies = [ libedataserverui_dep, webkit2_dep, folks_dep, + xdp_dep, + xdpgtk_dep, m_dep ] diff --git a/src/Application.vala b/src/Application.vala index 13e6c9f46..d5c043145 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -176,6 +176,21 @@ public class Mail.Application : Gtk.Application { } main_window.present (); + + if (!run_in_background) { + var portal = new Xdp.Portal (); + var parent = Xdp.parent_new_gtk (main_window); + var args = new GenericArray (); + args.add ("-b"); + portal.request_background.begin (parent, "Try it :)", (owned) args, Xdp.BackgroundFlags.AUTOSTART, null, (obj, res) => { + try { + var result = portal.request_background.end (res); + print (result.to_string ()); + } catch (Error e) { + critical (e.message); + } + }); + } } } diff --git a/src/MessageList/MessageListItem.vala b/src/MessageList/MessageListItem.vala index c944acef0..697dc7209 100644 --- a/src/MessageList/MessageListItem.vala +++ b/src/MessageList/MessageListItem.vala @@ -333,7 +333,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { expanded = false; show_all (); - avatar.set_loadable_icon (new GravatarIcon (parsed_address, get_style_context ().get_scale ())); + // avatar.set_loadable_icon (new GravatarIcon (parsed_address, get_style_context ().get_scale ())); /* Override default handler to stop event propagation. Otherwise clicking the menu will expand or collapse the MessageListItem. */ From 8d25690b286454789dbec654e288d4e27246a968 Mon Sep 17 00:00:00 2001 From: Leonhard K Date: Sat, 29 Apr 2023 15:34:38 +0200 Subject: [PATCH 02/22] Request background and autostart permissions via portal --- README.md | 2 ++ io.elementary.mail.json | 17 ++++++++++++++++ meson.build | 8 ++++---- src/Application.vala | 43 ++++++++++++++++++++++++++++------------- 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index bdea8261c..962ff3918 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/io.elementary.mail.json b/io.elementary.mail.json index 63cbb6ad0..9883a4aa5 100644 --- a/io.elementary.mail.json +++ b/io.elementary.mail.json @@ -127,6 +127,23 @@ } ] }, + { + "name": "libportal", + "buildsystem": "meson", + "config-opts": [ + "-Ddocs=false", + "-Dbackend-gtk3=enabled", + "-Dbackend-gtk4=disabled", + "-Dbackend-qt5=disabled" + ], + "sources" : [ + { + "type": "git", + "url": "https://github.com/flatpak/libportal.git", + "branch": "main" + } + ] + }, { "name": "mail", "buildsystem": "meson", diff --git a/meson.build b/meson.build index 1c67e735c..f1bc46d13 100644 --- a/meson.build +++ b/meson.build @@ -25,9 +25,9 @@ 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') -xdp_dep = dependency('libportal') -xdpgtk_dep = dependency('libportal-gtk3') m_dep = meson.get_compiler('c').find_library('m') webkit2_extension_path = join_paths(get_option('prefix'), get_option('libdir'), meson.project_name(), 'webkit2') @@ -41,10 +41,10 @@ dependencies = [ camel_dep, libedataserver_dep, libedataserverui_dep, + libportal_dep, + libportal_gtk_dep, webkit2_dep, folks_dep, - xdp_dep, - xdpgtk_dep, m_dep ] diff --git a/src/Application.vala b/src/Application.vala index d5c043145..4305c99cf 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -12,6 +12,8 @@ public class Mail.Application : Gtk.Application { public static GLib.Settings settings; public static bool run_in_background; + private bool request_autostart = true; + public Application () { Object ( application_id: "io.elementary.mail", @@ -139,8 +141,17 @@ public class Mail.Application : Gtk.Application { public override void activate () { if (run_in_background) { run_in_background = false; + request_autostart = false; + new InboxMonitor ().start.begin (); hold (); + + request_background.begin ((obj,res) => { + if (!request_background.end (res)) { + release (); + } + }); + return; } @@ -177,19 +188,25 @@ public class Mail.Application : Gtk.Application { main_window.present (); - if (!run_in_background) { - var portal = new Xdp.Portal (); - var parent = Xdp.parent_new_gtk (main_window); - var args = new GenericArray (); - args.add ("-b"); - portal.request_background.begin (parent, "Try it :)", (owned) args, Xdp.BackgroundFlags.AUTOSTART, null, (obj, res) => { - try { - var result = portal.request_background.end (res); - print (result.to_string ()); - } catch (Error e) { - critical (e.message); - } - }); + if (request_autostart) { + request_background.begin (); + } + } + + 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 (); + 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); + } catch (Error e) { + warning ("Failed to request background and autostart permissions: %s", e.message); + return false; } } } From aa0d45580570380fcbad6c9872e29c72b9774fe3 Mon Sep 17 00:00:00 2001 From: Leonhard K Date: Sat, 29 Apr 2023 15:37:40 +0200 Subject: [PATCH 03/22] Remove daemon --- data/daemon.desktop | 11 ----------- data/meson.build | 6 ------ 2 files changed, 17 deletions(-) delete mode 100644 data/daemon.desktop diff --git a/data/daemon.desktop b/data/daemon.desktop deleted file mode 100644 index 16c61812d..000000000 --- a/data/daemon.desktop +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Name=Mail Daemon -Comment=Send and receive mail -Exec=io.elementary.mail --background -Icon=io.elementary.mail -Terminal=false -Type=Application -NoDisplay=true -X-GNOME-AutoRestart=true -X-GNOME-Autostart-Delay=5 -X-GNOME-Autostart-Phase=Applications diff --git a/data/meson.build b/data/meson.build index f6b6bb55b..672b9aa41 100644 --- a/data/meson.build +++ b/data/meson.build @@ -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') From e7b8b0bbc1072ab27aed805cf526ca9031cb20d9 Mon Sep 17 00:00:00 2001 From: Leonhard K Date: Sat, 29 Apr 2023 15:46:52 +0200 Subject: [PATCH 04/22] Cleanup --- io.elementary.mail.json | 6 ++---- src/MessageList/MessageListItem.vala | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/io.elementary.mail.json b/io.elementary.mail.json index 9883a4aa5..91f80427f 100644 --- a/io.elementary.mail.json +++ b/io.elementary.mail.json @@ -132,15 +132,13 @@ "buildsystem": "meson", "config-opts": [ "-Ddocs=false", - "-Dbackend-gtk3=enabled", - "-Dbackend-gtk4=disabled", - "-Dbackend-qt5=disabled" + "-Dbackends=['gtk3']" ], "sources" : [ { "type": "git", "url": "https://github.com/flatpak/libportal.git", - "branch": "main" + "tag": "0.6" } ] }, diff --git a/src/MessageList/MessageListItem.vala b/src/MessageList/MessageListItem.vala index 697dc7209..c944acef0 100644 --- a/src/MessageList/MessageListItem.vala +++ b/src/MessageList/MessageListItem.vala @@ -333,7 +333,7 @@ public class Mail.MessageListItem : Gtk.ListBoxRow { expanded = false; show_all (); - // avatar.set_loadable_icon (new GravatarIcon (parsed_address, get_style_context ().get_scale ())); + avatar.set_loadable_icon (new GravatarIcon (parsed_address, get_style_context ().get_scale ())); /* Override default handler to stop event propagation. Otherwise clicking the menu will expand or collapse the MessageListItem. */ From 13349dced53142279c081fff120b1606fced06f5 Mon Sep 17 00:00:00 2001 From: Leonhard K Date: Sat, 29 Apr 2023 15:49:03 +0200 Subject: [PATCH 05/22] Fix lint --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index 4305c99cf..5768b72e2 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -146,7 +146,7 @@ public class Mail.Application : Gtk.Application { new InboxMonitor ().start.begin (); hold (); - request_background.begin ((obj,res) => { + request_background.begin ( (obj,res) => { if (!request_background.end (res)) { release (); } From 07c1da81c0b62638df947e81d606a7150026729c Mon Sep 17 00:00:00 2001 From: Leonhard K Date: Sat, 29 Apr 2023 15:50:05 +0200 Subject: [PATCH 06/22] Fix lint this time for real --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index 5768b72e2..0a06b3412 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -146,7 +146,7 @@ public class Mail.Application : Gtk.Application { new InboxMonitor ().start.begin (); hold (); - request_background.begin ( (obj,res) => { + request_background.begin ((obj, res) => { if (!request_background.end (res)) { release (); } From 2f9a3b277d3b3db7e66013cd1c253da2ca886cae Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sun, 30 Apr 2023 20:53:41 +0000 Subject: [PATCH 07/22] Application: Only use background portal if sandboxed --- src/Application.vala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Application.vala b/src/Application.vala index 0a06b3412..b0cb619d4 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -190,10 +190,15 @@ public class Mail.Application : Gtk.Application { if (request_autostart) { request_background.begin (); + request_autostart = false; } } private async bool request_background () { + if (!Xdp.Portal.running_under_sandbox ()) { + return true; + } + var portal = new Xdp.Portal (); Xdp.Parent? parent = active_window != null ? Xdp.parent_new_gtk (active_window) : null; From e7b020f1276463af415693727fabdfb46ea8f1db Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sun, 30 Apr 2023 20:58:46 +0000 Subject: [PATCH 08/22] Revert the removal of the daemon autostart file --- data/meson.build | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/data/meson.build b/data/meson.build index 672b9aa41..f6b6bb55b 100644 --- a/data/meson.build +++ b/data/meson.build @@ -13,6 +13,12 @@ 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') From 80f385fa6385afd3e84c4ab4ce74a80f6caef23b Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sun, 30 Apr 2023 20:59:40 +0000 Subject: [PATCH 09/22] Revert removal of daemon.desktop --- data/daemon.desktop | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 data/daemon.desktop diff --git a/data/daemon.desktop b/data/daemon.desktop new file mode 100644 index 000000000..16c61812d --- /dev/null +++ b/data/daemon.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Name=Mail Daemon +Comment=Send and receive mail +Exec=io.elementary.mail --background +Icon=io.elementary.mail +Terminal=false +Type=Application +NoDisplay=true +X-GNOME-AutoRestart=true +X-GNOME-Autostart-Delay=5 +X-GNOME-Autostart-Phase=Applications From 8cbee7d4db08eb95aabcd941f7f29645c88c365d Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Wed, 17 May 2023 20:25:03 +0200 Subject: [PATCH 10/22] Update --- src/Application.vala | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index c6c5fa305..c4be45885 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -12,8 +12,6 @@ public class Mail.Application : Gtk.Application { public static GLib.Settings settings; public static bool run_in_background; - private bool request_autostart = true; - public Application () { Object ( application_id: "io.elementary.mail", @@ -145,6 +143,13 @@ public class Mail.Application : Gtk.Application { new InboxMonitor ().start.begin (); hold (); + + request_background.begin ((obj, res) => { + var result = request_background.end (res); + if (!result) { + release (); + } + }); } public override void activate () { @@ -185,18 +190,9 @@ public class Mail.Application : Gtk.Application { } main_window.present (); - - if (request_autostart) { - request_background.begin (); - request_autostart = false; - } } private async bool request_background () { - if (!Xdp.Portal.running_under_sandbox ()) { - return true; - } - var portal = new Xdp.Portal (); Xdp.Parent? parent = active_window != null ? Xdp.parent_new_gtk (active_window) : null; From 2fff9005acecfe0ab4291a1c763ebf3e448ee9cc Mon Sep 17 00:00:00 2001 From: Leonhard Date: Tue, 23 May 2023 19:06:15 +0200 Subject: [PATCH 11/22] Remove daemon --- data/daemon.desktop | 11 ----------- data/meson.build | 6 ------ src/Application.vala | 2 +- 3 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 data/daemon.desktop diff --git a/data/daemon.desktop b/data/daemon.desktop deleted file mode 100644 index 16c61812d..000000000 --- a/data/daemon.desktop +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Name=Mail Daemon -Comment=Send and receive mail -Exec=io.elementary.mail --background -Icon=io.elementary.mail -Terminal=false -Type=Application -NoDisplay=true -X-GNOME-AutoRestart=true -X-GNOME-Autostart-Delay=5 -X-GNOME-Autostart-Phase=Applications diff --git a/data/meson.build b/data/meson.build index f6b6bb55b..672b9aa41 100644 --- a/data/meson.build +++ b/data/meson.build @@ -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') diff --git a/src/Application.vala b/src/Application.vala index c4be45885..0b82e1849 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -202,7 +202,7 @@ public class Mail.Application : Gtk.Application { 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); + return yield portal.request_background (parent, _("Mail needs to run in background in order to send notifications."), (owned) command, Xdp.BackgroundFlags.AUTOSTART, null); } catch (Error e) { warning ("Failed to request background and autostart permissions: %s", e.message); return false; From 8461ad29d2945fe89a6dcc6d49f53e9e178b13de Mon Sep 17 00:00:00 2001 From: Leonhard Date: Tue, 23 May 2023 23:59:39 +0200 Subject: [PATCH 12/22] Request autostart only on closing the window --- src/Application.vala | 30 ------------------------------ src/MainWindow.vala | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 0b82e1849..635d1b4a0 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -135,21 +135,8 @@ public class Mail.Application : Gtk.Application { add_action (quit_action); set_accels_for_action ("app.quit", {"q"}); - /* Needed to ask the flatpak portal for autostart and background permissions with a parent window - and to prevent issues with Session.start being called from the InboxMonitor first */ - if (!run_in_background) { - activate (); - } - new InboxMonitor ().start.begin (); hold (); - - request_background.begin ((obj, res) => { - var result = request_background.end (res); - if (!result) { - release (); - } - }); } public override void activate () { @@ -191,23 +178,6 @@ 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 (); - 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); - } catch (Error e) { - warning ("Failed to request background and autostart permissions: %s", e.message); - return false; - } - } } public static int main (string[] args) { diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 935831721..d360945de 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -202,7 +202,9 @@ public class Mail.MainWindow : Hdy.ApplicationWindow { session.start.begin ((obj, res) => { session.start.end (res); - if (session.get_accounts ().size > 0) { + var accounts = session.get_accounts (); + + if (accounts.size > 0) { placeholder_stack.visible_child = paned_end; get_action (ACTION_COMPOSE_MESSAGE).set_enabled (true); } else { @@ -214,6 +216,15 @@ public class Mail.MainWindow : Hdy.ApplicationWindow { session_started (); }); + delete_event.connect (() => { + request_autostart.begin ((obj, res) => { + request_autostart.end (res); + destroy (); + }); + + return true; + }); + destroy.connect (() => { session.disconnect (account_removed_handler); session.disconnect (account_added_handler); @@ -327,4 +338,28 @@ public class Mail.MainWindow : Hdy.ApplicationWindow { return base.configure_event (event); } + + private async void request_autostart () { + var portal = new Xdp.Portal (); + + var parent = Xdp.parent_new_gtk (this); + + var command = new GenericArray (); + command.add ("io.elementary.mail"); + command.add ("--background"); + + try { + if (!yield portal.request_background ( + parent, + _("Mail needs to autostart and run in background in order to send notifications even while closed."), + (owned) command, + Xdp.BackgroundFlags.AUTOSTART, + null + )) { + GLib.Application.get_default ().release (); + } + } catch (Error e) { + warning ("Failed to request autostart permissions: %s", e.message); + } + } } From ea1231debb94f48d122953ee241ef521a5343df4 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Wed, 24 May 2023 00:01:12 +0200 Subject: [PATCH 13/22] Revert unnecessary change --- src/MainWindow.vala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index d360945de..ce94f3271 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -202,9 +202,7 @@ public class Mail.MainWindow : Hdy.ApplicationWindow { session.start.begin ((obj, res) => { session.start.end (res); - var accounts = session.get_accounts (); - - if (accounts.size > 0) { + if (session.get_accounts ().size > 0) { placeholder_stack.visible_child = paned_end; get_action (ACTION_COMPOSE_MESSAGE).set_enabled (true); } else { From de7b8fa67666b15bcd3333540d2e6f8547791f4a Mon Sep 17 00:00:00 2001 From: Leonhard Date: Wed, 24 May 2023 00:04:01 +0200 Subject: [PATCH 14/22] Releas on failure --- src/MainWindow.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index ce94f3271..6978b06e7 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -358,6 +358,7 @@ public class Mail.MainWindow : Hdy.ApplicationWindow { } } catch (Error e) { warning ("Failed to request autostart permissions: %s", e.message); + GLib.Application.get_default ().release (); } } } From c2e688e5a25cb9be0d6a1f53c71d20430a3118a1 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Wed, 24 May 2023 00:23:12 +0200 Subject: [PATCH 15/22] Always ask for background --- src/Application.vala | 26 ++++++++++++++++++++++++++ src/MainWindow.vala | 30 +++--------------------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 635d1b4a0..28792cacd 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -141,6 +141,7 @@ public class Mail.Application : Gtk.Application { public override void activate () { if (run_in_background) { + request_background.begin (); run_in_background = false; return; } @@ -178,6 +179,31 @@ public class Mail.Application : Gtk.Application { main_window.present (); } + + public async void request_background () { + var portal = new Xdp.Portal (); + + Xdp.Parent? parent = active_window != null ? Xdp.parent_new_gtk (active_window) : null; + + var command = new GenericArray (); + command.add ("io.elementary.mail"); + command.add ("--background"); + + try { + if (!yield portal.request_background ( + parent, + _("Mail needs to autostart and run in background in order to send notifications even while closed."), + (owned) command, + Xdp.BackgroundFlags.AUTOSTART, + null + )) { + release (); + } + } catch (Error e) { + warning ("Failed to request autostart permissions: %s", e.message); + release (); + } + } } public static int main (string[] args) { diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 6978b06e7..086e442aa 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -215,8 +215,9 @@ public class Mail.MainWindow : Hdy.ApplicationWindow { }); delete_event.connect (() => { - request_autostart.begin ((obj, res) => { - request_autostart.end (res); + unowned var application = (Application)GLib.Application.get_default (); + application.request_background.begin ((obj, res) => { + application.request_background.end (res); destroy (); }); @@ -336,29 +337,4 @@ public class Mail.MainWindow : Hdy.ApplicationWindow { return base.configure_event (event); } - - private async void request_autostart () { - var portal = new Xdp.Portal (); - - var parent = Xdp.parent_new_gtk (this); - - var command = new GenericArray (); - command.add ("io.elementary.mail"); - command.add ("--background"); - - try { - if (!yield portal.request_background ( - parent, - _("Mail needs to autostart and run in background in order to send notifications even while closed."), - (owned) command, - Xdp.BackgroundFlags.AUTOSTART, - null - )) { - GLib.Application.get_default ().release (); - } - } catch (Error e) { - warning ("Failed to request autostart permissions: %s", e.message); - GLib.Application.get_default ().release (); - } - } } From b6498eea69d679c8f150d2fe2b61b61aedad17f3 Mon Sep 17 00:00:00 2001 From: Leonhard <106322251+leolost2605@users.noreply.github.com> Date: Wed, 24 May 2023 12:01:08 +0200 Subject: [PATCH 16/22] Update src/MainWindow.vala Co-authored-by: Gustavo Marques --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 086e442aa..5aef663da 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -221,7 +221,7 @@ public class Mail.MainWindow : Hdy.ApplicationWindow { destroy (); }); - return true; + return Gdk.EVENT_STOP; }); destroy.connect (() => { From fae3625b0f49a46a78406296f3d252973ecdb396 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Wed, 24 May 2023 12:13:17 +0200 Subject: [PATCH 17/22] Don't call hold in startup --- src/Application.vala | 7 ++++++- src/MainWindow.vala | 6 +----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index b24e5d28f..2c8b13f46 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -12,6 +12,7 @@ public class Mail.Application : Gtk.Application { public static GLib.Settings settings; public static bool run_in_background; private Gtk.Settings gtk_settings; + private bool first_activation = true; public Application () { Object ( @@ -141,10 +142,14 @@ public class Mail.Application : Gtk.Application { set_accels_for_action ("app.quit", {"q"}); new InboxMonitor ().start.begin (); - hold (); } public override void activate () { + if (first_activation) { + first_activation = false; + hold (); + } + if (run_in_background) { request_background.begin (); run_in_background = false; diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 5aef663da..b54def0d4 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -215,11 +215,7 @@ public class Mail.MainWindow : Hdy.ApplicationWindow { }); delete_event.connect (() => { - unowned var application = (Application)GLib.Application.get_default (); - application.request_background.begin ((obj, res) => { - application.request_background.end (res); - destroy (); - }); + ((Application)application).request_background.begin (() => destroy ()); return Gdk.EVENT_STOP; }); From 0c86f2de4a6d760601ddb6ac9037fce11fd31332 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Wed, 24 May 2023 17:18:59 +0200 Subject: [PATCH 18/22] Always hold in activate --- src/Application.vala | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 2c8b13f46..a49f842d1 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -12,7 +12,6 @@ public class Mail.Application : Gtk.Application { public static GLib.Settings settings; public static bool run_in_background; private Gtk.Settings gtk_settings; - private bool first_activation = true; public Application () { Object ( @@ -145,10 +144,7 @@ public class Mail.Application : Gtk.Application { } public override void activate () { - if (first_activation) { - first_activation = false; - hold (); - } + hold (); if (run_in_background) { request_background.begin (); From e73d5daae9485bc18b530b3ec0bc8152aeca098c Mon Sep 17 00:00:00 2001 From: Leonhard Date: Thu, 1 Jun 2023 19:07:38 +0200 Subject: [PATCH 19/22] Guard hold with first_activation --- src/Application.vala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index a49f842d1..2c8b13f46 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -12,6 +12,7 @@ public class Mail.Application : Gtk.Application { public static GLib.Settings settings; public static bool run_in_background; private Gtk.Settings gtk_settings; + private bool first_activation = true; public Application () { Object ( @@ -144,7 +145,10 @@ public class Mail.Application : Gtk.Application { } public override void activate () { - hold (); + if (first_activation) { + first_activation = false; + hold (); + } if (run_in_background) { request_background.begin (); From bdca877f7fa07e89406e2e52c4cbbd40b5620942 Mon Sep 17 00:00:00 2001 From: Leonhard <106322251+leolost2605@users.noreply.github.com> Date: Sat, 3 Jun 2023 23:03:16 +0200 Subject: [PATCH 20/22] Update src/Application.vala MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Danielle Foré --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index 2c8b13f46..4a5c71c5f 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -202,7 +202,7 @@ public class Mail.Application : Gtk.Application { try { if (!yield portal.request_background ( parent, - _("Mail needs to autostart and run in background in order to send notifications even while closed."), + _("Mail will automatically start when this device turns on and run when its window is closed so that it can send notifications when new mail arrives."), (owned) command, Xdp.BackgroundFlags.AUTOSTART, null From 44d5e37f79ccdcb6ea49d57287a3437164772f2e Mon Sep 17 00:00:00 2001 From: Leonhard Date: Sun, 4 Jun 2023 23:14:32 +0200 Subject: [PATCH 21/22] Don't release when background request failed --- src/Application.vala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index b1557db4d..1a567955f 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -213,8 +213,12 @@ public class Mail.Application : Gtk.Application { release (); } } catch (Error e) { - warning ("Failed to request autostart permissions: %s", e.message); - release (); + if (e is IOError.CANCELLED) { + debug ("Request for autostart permissions denied: %s", e.message); + release (); + } else { + warning ("Failed to request autostart permissions: %s", e.message); + } } } From 6b3e7fa0c20e3b8531b1e627381fa5c81ff7c535 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Sun, 4 Jun 2023 23:15:20 +0200 Subject: [PATCH 22/22] Update warning/debug messages --- src/Application.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 1a567955f..47c4b1ca7 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -214,10 +214,10 @@ public class Mail.Application : Gtk.Application { } } catch (Error e) { if (e is IOError.CANCELLED) { - debug ("Request for autostart permissions denied: %s", e.message); + debug ("Request for autostart and background permissions denied: %s", e.message); release (); } else { - warning ("Failed to request autostart permissions: %s", e.message); + warning ("Failed to request autostart and background permissions: %s", e.message); } } }