From 45f9360a51c328877c0654d715fc94e94a349ee5 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 1 Nov 2022 19:41:37 +0100 Subject: [PATCH] Reboot to Firmware Setup (#253) --- src/Interfaces/LoginManager.vala | 23 +++++++++++++ src/Views/FirmwareView.vala | 55 ++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/Interfaces/LoginManager.vala b/src/Interfaces/LoginManager.vala index c5bea29ca..57a880591 100644 --- a/src/Interfaces/LoginManager.vala +++ b/src/Interfaces/LoginManager.vala @@ -23,6 +23,8 @@ public interface About.LoginInterface : Object { public abstract void reboot (bool interactive) throws GLib.Error; public abstract void power_off (bool interactive) throws GLib.Error; + public abstract void set_reboot_to_firmware_setup (bool interactive) throws GLib.Error; + public abstract string can_reboot_to_firmware_setup () throws GLib.Error; } public class About.LoginManager : Object { @@ -68,4 +70,25 @@ public class About.LoginManager : Object { return true; } + + public Error? set_reboot_to_firmware_setup () { + try { + interface.set_reboot_to_firmware_setup (true); + } catch (Error e) { + warning ("Could not set reboot to firmware setup: %s", e.message); + return e; + } + + return null; + } + + public bool can_reboot_to_firmware_setup () { + try { + return interface.can_reboot_to_firmware_setup () == "yes"; + } catch (Error e) { + warning ("Could not connect to login interface: %s", e.message); + } + + return false; + } } diff --git a/src/Views/FirmwareView.vala b/src/Views/FirmwareView.vala index 41a15147d..cd6de6384 100644 --- a/src/Views/FirmwareView.vala +++ b/src/Views/FirmwareView.vala @@ -84,6 +84,12 @@ public class About.FirmwareView : Granite.SimpleSettingsPage { content_area.add (frame); + if (LoginManager.get_instance ().can_reboot_to_firmware_setup ()) { + var reboot_to_firmware_setup_button = new Gtk.Button.with_label (_("Restart to Firmware Setup")); + reboot_to_firmware_setup_button.clicked.connect (reboot_to_firmware_setup_clicked); + action_area.add (reboot_to_firmware_setup_button); + } + fwupd_client = new Fwupd.Client (); fwupd_client.device_added.connect (on_device_added); fwupd_client.device_removed.connect (on_device_removed); @@ -392,4 +398,53 @@ public class About.FirmwareView : Granite.SimpleSettingsPage { message_dialog.destroy (); } + + private void reboot_to_firmware_setup_clicked () { + var dialog = new Granite.MessageDialog ( + _("Restart to firmware setup"), + _("This will close all open applications, restart this device, and open the firmware setup screen."), + new ThemedIcon ("system-reboot"), + Gtk.ButtonsType.CANCEL + ) { + badge_icon = new ThemedIcon ("application-x-firmware"), + modal = true, + transient_for = (Gtk.Window) get_toplevel () + }; + + var continue_button = dialog.add_button (_("Restart"), Gtk.ResponseType.ACCEPT); + continue_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION); + + dialog.response.connect ((result) => { + dialog.destroy (); + + if (result != Gtk.ResponseType.ACCEPT) { + return; + } + + var login_manager = LoginManager.get_instance (); + var error = login_manager.set_reboot_to_firmware_setup (); + + if (error != null) { + var message_dialog = new Granite.MessageDialog ( + _("Unable to restart to firmware setup"), + _("A system error prevented automatically restarting into firmware setup."), + new ThemedIcon ("system-reboot"), + Gtk.ButtonsType.CLOSE + ) { + badge_icon = new ThemedIcon ("dialog-error"), + modal = true, + transient_for = (Gtk.Window) get_toplevel () + }; + message_dialog.show_error_details (error.message); + message_dialog.present (); + message_dialog.response.connect (message_dialog.destroy); + + return; + } + + login_manager.reboot (); + }); + + dialog.present (); + } }