From 0e9ecc44fb2b9a7004d7f2f08acf12292bf11649 Mon Sep 17 00:00:00 2001 From: Marukesu Date: Tue, 20 Jul 2021 03:07:38 -0300 Subject: [PATCH 1/6] remove daemon.desktop --- data/daemon.desktop | 12 ------------ data/meson.build | 6 ------ 2 files changed, 18 deletions(-) delete mode 100644 data/daemon.desktop diff --git a/data/daemon.desktop b/data/daemon.desktop deleted file mode 100644 index 27bd758e7..000000000 --- a/data/daemon.desktop +++ /dev/null @@ -1,12 +0,0 @@ -[Desktop Entry] -Name=Calendar Daemon -Comment=View Event Reminders -Icon=io.elementary.calendar -Exec=io.elementary.calendar --background -Terminal=false -Type=Application -Categories=System; -OnlyShowIn=Pantheon; -NoDisplay=true -X-GNOME-AutoRestart=true -X-GNOME-Autostart-Phase=Applications diff --git a/data/meson.build b/data/meson.build index e28dd5b4b..7e6fbbeef 100644 --- a/data/meson.build +++ b/data/meson.build @@ -13,12 +13,6 @@ foreach i : icon_sizes ) endforeach -install_data( - 'daemon.desktop', - rename: meson.project_name() + '-daemon.desktop', - install_dir: join_paths(get_option('sysconfdir'), 'xdg', 'autostart') -) - install_data( meson.project_name() + '.gschema.xml', install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'glib-2.0', 'schemas') From 3a8f4bf0f26d14a748646498c073f7ecd7def495 Mon Sep 17 00:00:00 2001 From: Marukesu Date: Tue, 20 Jul 2021 15:04:21 -0300 Subject: [PATCH 2/6] create the autostart file via the background portal --- io.elementary.calendar.yml | 11 +++++++++++ meson.build | 2 ++ src/Application.vala | 24 +++++++++++++++++++++++- src/meson.build | 3 ++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/io.elementary.calendar.yml b/io.elementary.calendar.yml index 4bc89204d..2d3e9b95a 100644 --- a/io.elementary.calendar.yml +++ b/io.elementary.calendar.yml @@ -120,6 +120,17 @@ modules: url: https://gitlab.gnome.org/GNOME/geocode-glib.git tag: '3.26.2' + - name: libportal + buildsystem: meson + config-opts: + - "-Dbackends=['gtk3']" + - '-Ddocs=false' + - '-Dtests=false' + sources: + - type: git + url: https://github.com/flatpak/libportal.git + tag: '0.6' + - name: calendar buildsystem: meson sources: diff --git a/meson.build b/meson.build index b331aee5a..ddedba417 100644 --- a/meson.build +++ b/meson.build @@ -52,6 +52,8 @@ folks_dep = dependency('folks') gclue_dep = dependency('libgeoclue-2.0') libecal_dep = dependency('libecal-2.0') libical_dep = dependency('libical-glib') +libportal_dep = [ dependency('libportal'), dependency('libportal-gtk3') ] + add_project_arguments('-DLIBICAL_GLIB_UNSTABLE_API=1', language: 'c') m_dep = meson.get_compiler('c').find_library('m', required : false) diff --git a/src/Application.vala b/src/Application.vala index 1e428ffff..655360f63 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -1,6 +1,6 @@ // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- /*- - * Copyright (c) 2011-2018 elementary, Inc. (https://elementary.io) + * Copyright (c) 2011-2023 elementary, Inc. (https://elementary.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +28,8 @@ namespace Maya { private static bool add_event = false; private static string show_day = null; + private Xdp.Portal? portal = null; + private const OptionEntry[] APP_OPTIONS = { { "add-event", 'a', 0, OptionArg.NONE, out add_event, N_("Create an event"), null }, { "show-day", 's', 0, OptionArg.STRING, out show_day, N_("Focus the given day"), N_("date") }, @@ -101,6 +103,8 @@ namespace Maya { }); } + ask_for_background (); + var granite_settings = Granite.Settings.get_default (); var gtk_settings = Gtk.Settings.get_default (); @@ -166,6 +170,24 @@ namespace Maya { Calendar.EventStore.get_default ().delete_trashed_calendars (); } + private void ask_for_background () { + const string[] DAEMON_COMMAND = { "io.elementary.calendar", "--background" }; + if (portal == null) { + portal = new Xdp.Portal (); + } + + string reason = _("Calendar wants to initialize with the session"); + var command = new GenericArray (2); + foreach (unowned var arg in DAEMON_COMMAND) { + command.add (arg); + } + + var window = Xdp.parent_new_gtk (active_window); + + //TODO: handle response + portal.request_background.begin (window, reason, command, AUTOSTART, null); + } + public static DateTime get_selected_datetime () { var selected_day = saved_state.get_string ("selected-day"); if (selected_day == null || selected_day == "") { diff --git a/src/meson.build b/src/meson.build index 0a97a372f..9a37815c0 100644 --- a/src/meson.build +++ b/src/meson.build @@ -61,7 +61,8 @@ calendar_deps = [ clutter_gtk_dep, folks_dep, geocode_glib_dep, - gclue_dep + gclue_dep, + libportal_dep ] executable( From 1a1adc46e1371514a69d3d909f0616c6ff504222 Mon Sep 17 00:00:00 2001 From: Marukesu Date: Fri, 17 Dec 2021 21:56:17 -0300 Subject: [PATCH 3/6] show the dialog only when required --- src/Application.vala | 23 ++++++++++++++++------- src/MainWindow.vala | 15 ++++++++++++++- src/TodayEventMonitor.vala | 1 + 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index 655360f63..9907de192 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -63,10 +63,17 @@ namespace Maya { } protected override void activate () { + new Calendar.TodayEventMonitor (); if (run_in_background) { run_in_background = false; - new Calendar.TodayEventMonitor (); hold (); + + ask_for_background.begin ((obj, res) => { + if (!ask_for_background.end (res)) { + release (); + } + }); + return; } @@ -103,8 +110,6 @@ namespace Maya { }); } - ask_for_background (); - var granite_settings = Granite.Settings.get_default (); var gtk_settings = Gtk.Settings.get_default (); @@ -170,13 +175,13 @@ namespace Maya { Calendar.EventStore.get_default ().delete_trashed_calendars (); } - private void ask_for_background () { + public async bool ask_for_background () { const string[] DAEMON_COMMAND = { "io.elementary.calendar", "--background" }; if (portal == null) { portal = new Xdp.Portal (); } - string reason = _("Calendar wants to initialize with the session"); + string reason = _("Calendar wants to run on background and initialize with the session for events notifications"); var command = new GenericArray (2); foreach (unowned var arg in DAEMON_COMMAND) { command.add (arg); @@ -184,8 +189,12 @@ namespace Maya { var window = Xdp.parent_new_gtk (active_window); - //TODO: handle response - portal.request_background.begin (window, reason, command, AUTOSTART, null); + try { + return yield portal.request_background (window, reason, command, AUTOSTART, null); + } catch (Error e) { + warning ("Error during portal request: %s", e.message); + return e is IOError.FAILED; + } } public static DateTime get_selected_datetime () { diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 32ee46242..18340f8c6 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -1,6 +1,6 @@ // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- /*- - * Copyright (c) 2011-2020 elementary, Inc. (https://elementary.io) + * Copyright (c) 2011-2023 elementary, Inc. (https://elementary.io) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -182,4 +182,17 @@ public class Maya.MainWindow : Hdy.ApplicationWindow { return base.configure_event (event); } + + public override bool delete_event (Gdk.EventAny event) { + ((Application) application).ask_for_background.begin ((obj, res) => { + unowned var app = (Application) obj; + if (app.ask_for_background.end (res)) { + hide (); + } else { + destroy (); + } + }); + + return Gdk.EVENT_STOP; + } } diff --git a/src/TodayEventMonitor.vala b/src/TodayEventMonitor.vala index b452db595..1132031e4 100644 --- a/src/TodayEventMonitor.vala +++ b/src/TodayEventMonitor.vala @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +[SingleInstance] public class Calendar.TodayEventMonitor : GLib.Object { private Gee.HashMultiMap event_uids; From 01e043ad892b75fa68bc9bc1ca52a41451e0f38f Mon Sep 17 00:00:00 2001 From: Gustavo Marques Date: Wed, 12 Jan 2022 19:19:21 -0300 Subject: [PATCH 4/6] apply suggestions from code review Co-authored-by: Jeremy Wootten --- src/Application.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index 9907de192..c9d6f973f 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -181,7 +181,7 @@ namespace Maya { portal = new Xdp.Portal (); } - string reason = _("Calendar wants to run on background and initialize with the session for events notifications"); + string reason = _("Calendar wants to run in the background and initialize with the session for events notifications"); var command = new GenericArray (2); foreach (unowned var arg in DAEMON_COMMAND) { command.add (arg); From b63de51386d1dca35be5d85c14cce8052691ce92 Mon Sep 17 00:00:00 2001 From: Gustavo Marques Date: Sun, 11 Jun 2023 00:16:27 -0300 Subject: [PATCH 5/6] Update reason string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Danielle Foré --- src/Application.vala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Application.vala b/src/Application.vala index c9d6f973f..81b576a5f 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -181,7 +181,10 @@ namespace Maya { portal = new Xdp.Portal (); } - string reason = _("Calendar wants to run in the background and initialize with the session for events notifications"); + string reason = _( + "Calendar will automatically start when this device turns on " + + "and run when its window is closed so that it can send event notifications." + ); var command = new GenericArray (2); foreach (unowned var arg in DAEMON_COMMAND) { command.add (arg); From 147228e5dee19b7955540b356fa71262e8074452 Mon Sep 17 00:00:00 2001 From: Marukesu Date: Fri, 17 Dec 2021 22:47:48 -0300 Subject: [PATCH 6/6] Update Appdata --- data/io.elementary.calendar.appdata.xml.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/data/io.elementary.calendar.appdata.xml.in b/data/io.elementary.calendar.appdata.xml.in index 475e4396e..65e85959d 100644 --- a/data/io.elementary.calendar.appdata.xml.in +++ b/data/io.elementary.calendar.appdata.xml.in @@ -11,6 +11,15 @@

A slim, lightweight calendar app that syncs and manages multiple calendars in one place, like Google Calendar, Outlook and CalDAV.

+ + +

Minor Updates:

+
    +
  • Ask the user's permission to run in background if required
  • +
+
+
+

Minor Updates: