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 autostart and background permission #361

Merged
merged 4 commits into from
Jun 12, 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 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(
'gschema.xml',
install_dir: join_paths(get_option('datadir'), 'glib-2.0', 'schemas'),
Expand Down
10 changes: 10 additions & 0 deletions io.elementary.tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
41 changes: 39 additions & 2 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -61,13 +63,19 @@ public class Tasks.Application : Gtk.Application {

add_action (quit_action);
set_accels_for_action ("app.quit", {"<Control>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;
}

Expand Down Expand Up @@ -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<weak string> ();
command.add ("io.elementary.tasks");
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 for due 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<string, Gtk.CssProvider>? providers;
public static void set_task_color (E.Source source, Gtk.Widget widget) {
if (providers == null) {
Expand Down
6 changes: 6 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down