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

Flatpak: Create Autostart File Via Background Portal #681

Merged
merged 6 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 0 additions & 12 deletions data/daemon.desktop

This file was deleted.

9 changes: 9 additions & 0 deletions data/io.elementary.calendar.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
<p>A slim, lightweight calendar app that syncs and manages multiple calendars in one place, like Google Calendar, Outlook and CalDAV.</p>
</description>
<releases>
<release version="6.2.0" date="2023-05-23" urgency="medium">
<description>
<p>Minor Updates:</p>
<ul>
<li>Ask the user's permission to run in background if required</li>
</ul>
</description>
</release>

<release version="6.1.3" date="2023-05-15" urgency="medium">
<description>
<p>Minor Updates:</p>
Expand Down
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',
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')
Expand Down
11 changes: 11 additions & 0 deletions io.elementary.calendar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 36 additions & 2 deletions src/Application.vala
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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") },
Expand Down Expand Up @@ -61,10 +63,17 @@ namespace Maya {
}

protected override void activate () {
new Calendar.TodayEventMonitor ();
Copy link
Member

Choose a reason for hiding this comment

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

Should this be done in activate? it looks like Mail does the equivalent in startup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, Calendar doesn't have a startup method. This work since TodayEventMonitor is marked as a [SingleInstance] class and the construct method will only be called one time.

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;
}

Expand Down Expand Up @@ -166,6 +175,31 @@ namespace Maya {
Calendar.EventStore.get_default ().delete_trashed_calendars ();
}

public async bool ask_for_background () {
const string[] DAEMON_COMMAND = { "io.elementary.calendar", "--background" };
if (portal == null) {
portal = new Xdp.Portal ();
}

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<unowned string> (2);
foreach (unowned var arg in DAEMON_COMMAND) {
command.add (arg);
}

var window = Xdp.parent_new_gtk (active_window);

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 () {
var selected_day = saved_state.get_string ("selected-day");
if (selected_day == null || selected_day == "") {
Expand Down
15 changes: 14 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/TodayEventMonitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

[SingleInstance]
public class Calendar.TodayEventMonitor : GLib.Object {
private Gee.HashMultiMap<ECal.Component, string> event_uids;

Expand Down
3 changes: 2 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ calendar_deps = [
clutter_gtk_dep,
folks_dep,
geocode_glib_dep,
gclue_dep
gclue_dep,
libportal_dep
]

executable(
Expand Down