Skip to content

Commit

Permalink
Reboot to Firmware Setup (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
meisenzahl authored Nov 1, 2022
1 parent 940acc5 commit 45f9360
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Interfaces/LoginManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
55 changes: 55 additions & 0 deletions src/Views/FirmwareView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ();
}
}

0 comments on commit 45f9360

Please sign in to comment.