From 9cd9fdd0ceb44887a90f8744bf813f0b32d6d3a6 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Mon, 12 Jun 2023 22:32:33 +0200 Subject: [PATCH 1/4] Use flatpak portal for autostart and background permission --- data/daemon.desktop | 10 ---------- data/meson.build | 6 ------ io.elementary.tasks.yml | 10 ++++++++++ meson.build | 4 +++- src/Application.vala | 41 +++++++++++++++++++++++++++++++++++++++-- src/MainWindow.vala | 6 ++++++ 6 files changed, 58 insertions(+), 19 deletions(-) delete mode 100644 data/daemon.desktop diff --git a/data/daemon.desktop b/data/daemon.desktop deleted file mode 100644 index 27efa734c6..0000000000 --- a/data/daemon.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Name=Tasks Daemon -Comment=Create notifications for due tasks -Exec=io.elementary.tasks --background -Icon=io.elementary.tasks -Terminal=false -Type=Application -NoDisplay=true -X-GNOME-AutoRestart=true -X-GNOME-Autostart-Phase=Applications diff --git a/data/meson.build b/data/meson.build index 9e12474a6a..152af74b92 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( 'gschema.xml', install_dir: join_paths(get_option('datadir'), 'glib-2.0', 'schemas'), diff --git a/io.elementary.tasks.yml b/io.elementary.tasks.yml index 03971059db..17a3ae337c 100644 --- a/io.elementary.tasks.yml +++ b/io.elementary.tasks.yml @@ -137,6 +137,16 @@ modules: url: https://download.gnome.org/sources/geocode-glib/3.26/geocode-glib-3.26.4.tar.xz sha256: 2d9a6826d158470449a173871221596da0f83ebdcff98b90c7049089056a37aa + - name: libportal + buildsystem: meson + config-opts: + - '-Ddocs=false' + - "-Dbackends=['gtk3']" + sources: + - type: archive + url: https://github.com/flatpak/libportal/releases/download/0.6/libportal-0.6.tar.xz + sha256: 88a12c3ba71bc31acff7238c280de697d609cebc50830c3766776ec35abc6566 + - name: tasks buildsystem: meson sources: diff --git a/meson.build b/meson.build index e6197e170d..c4e63e96a3 100644 --- a/meson.build +++ b/meson.build @@ -40,7 +40,9 @@ tasks_deps = [ dependency('libedataserver-1.2'), dependency('libgeoclue-2.0'), dependency('libhandy-1', version: '>=0.90.0'), - dependency('libical-glib') + dependency('libical-glib'), + dependency('libportal'), + dependency('libportal-gtk3') ] if libecal_dep.version().version_compare('>=3.46.0') diff --git a/src/Application.vala b/src/Application.vala index 8603e0c463..5f693f42ec 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -32,6 +32,8 @@ public class Tasks.Application : Gtk.Application { { "text/uri-list", Gtk.TargetFlags.SAME_APP | Gtk.TargetFlags.OTHER_WIDGET, 0 } // TODO: TEXT_URI }; + private bool first_activation = true; + public Application () { Object ( application_id: "io.elementary.tasks", @@ -61,13 +63,19 @@ public class Tasks.Application : Gtk.Application { add_action (quit_action); set_accels_for_action ("app.quit", {"q"}); + + new Tasks.TodayTaskMonitor ().start.begin (); } protected override void activate () { + if (first_activation) { + first_activation = false; + hold (); + } + if (run_in_background) { run_in_background = false; - new Tasks.TodayTaskMonitor ().start.begin (); - hold (); + request_background.begin (); return; } @@ -108,6 +116,35 @@ public class Tasks.Application : Gtk.Application { active_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, + _("Tasks will automatically start when this device turns on and run when its window is closed so that it can send notifications about todays tasks."), + (owned) command, + Xdp.BackgroundFlags.AUTOSTART, + null + )) { + release (); + } + } catch (Error e) { + if (e is IOError.CANCELLED) { + debug ("Request for autostart and background permissions denied: %s", e.message); + release (); + } else { + warning ("Failed to request autostart and background permissions: %s", e.message); + } + } + } + private static Gee.HashMap? providers; public static void set_task_color (E.Source source, Gtk.Widget widget) { if (providers == null) { diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 821a322f55..7b81c91297 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -139,6 +139,12 @@ public class Tasks.MainWindow : Hdy.ApplicationWindow { add (paned); + delete_event.connect (() => { + ((Application)application).request_background.begin (() => destroy ()); + + return Gdk.EVENT_STOP; + }); + online_accounts_button.clicked.connect (() => { try { AppInfo.launch_default_for_uri ("settings://accounts/online", null); From 29bff88178947c91ec8f2956b89c083c25767e26 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Mon, 12 Jun 2023 22:45:29 +0200 Subject: [PATCH 2/4] Fix a copy/paste issue --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index 5f693f42ec..e2edc05559 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -122,7 +122,7 @@ public class Tasks.Application : Gtk.Application { Xdp.Parent? parent = active_window != null ? Xdp.parent_new_gtk (active_window) : null; var command = new GenericArray (); - command.add ("io.elementary.mail"); + command.add ("io.elementary.tasks"); command.add ("--background"); try { From 56e962df4d199530cec6b7bb35fea3b3f895ced7 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Mon, 12 Jun 2023 22:46:14 +0200 Subject: [PATCH 3/4] Update wording --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index e2edc05559..385b18786f 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -128,7 +128,7 @@ public class Tasks.Application : Gtk.Application { try { if (!yield portal.request_background ( parent, - _("Tasks will automatically start when this device turns on and run when its window is closed so that it can send notifications about todays tasks."), + _("Tasks will automatically start when this device turns on and run when its window is closed so that it can send notifications for due tasks."), (owned) command, Xdp.BackgroundFlags.AUTOSTART, null From c5146ada03ab5bfb849d6b93d7db292087c52cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 12 Jun 2023 15:08:31 -0700 Subject: [PATCH 4/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c0ee8ace73..5ecd953b9b 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ You'll need the following dependencies: * libgeoclue-2-dev * libgeocode-glib-dev * libhandy-1-dev >= 0.90.0 +* libportal-dev +* libportal-gtk3-dev * libical * meson * valac