Commit 3e9386fd authored by Michael Terry's avatar Michael Terry

Tell user how to fix flatpak background permissions

If the user tries to back up automatically, but the permission
has been denied in the past, tell them how to fix it (going to
Settings application settings).

Unfortunately, we can't go further and open the settings panel,
because flatpak doesn't let us launch the control center.
parent 16efe247
Pipeline #203084 failed with stage
in 12 minutes and 17 seconds
......@@ -42,6 +42,7 @@ public class Background : Object
const string PORTAL_PATH = "/org/freedesktop/portal/desktop";
const string REQUEST_IFACE = "org.freedesktop.portal.Request";
Gtk.Window window = null;
MainLoop loop = null;
DBusConnection connection = null;
bool started = false;
......@@ -52,11 +53,6 @@ public class Background : Object
this.loop = new MainLoop(null, false);
}
~Background() {
if (signal_id > 0)
connection.signal_unsubscribe(signal_id);
}
string get_window_handle(Gtk.Window window)
{
var gdk_window = window.get_window();
......@@ -86,8 +82,10 @@ public class Background : Object
values.lookup("autostart", "b", out autostart);
this.autostart_allowed = autostart;
}
if (this.response == 1)
if (this.response == 1) {
this.permission_refused = true;
show_error_dialog();
}
this.loop.quit();
}
......@@ -123,6 +121,20 @@ public class Background : Object
}
}
void show_error_dialog()
{
var dlg = new Gtk.MessageDialog(
this.window,
Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.OK,
_("Cannot back up automatically")
);
dlg.format_secondary_text(_("Make sure Backups has permission to run in the background in Settings → Applications → Backups and try again."));
dlg.run();
DejaDup.destroy_widget(dlg);
}
public bool request_autostart(Gtk.Widget widget)
{
// We currently only actually bother checking with the Background portal in flatpak land.
......@@ -134,11 +146,17 @@ public class Background : Object
// Check to make sure that we haven't been called before
if (!this.started) {
this.started = true;
this.window = widget.get_toplevel() as Gtk.Window;
this.request_background_helper.begin(widget.get_toplevel() as Gtk.Window);
this.request_background_helper.begin(window);
// And wait for response (loop is quit in got_response)
this.loop.run();
if (signal_id > 0) {
connection.signal_unsubscribe(signal_id);
signal_id = 0;
}
}
return this.autostart_allowed;
......
......@@ -23,7 +23,6 @@ public class ConfigAutoBackup : BuilderWidget
if (state) {
var bg = new Background();
if (!bg.request_autostart(auto_backup)) {
auto_backup.sensitive = !bg.permission_refused;
auto_backup.active = false;
return true; // don't change state, skip default handler
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment