Skip to content

Commit 734c045

Browse files
committed
api/reboot: change confirmation text based on reboot purpose
1 parent a6bbc16 commit 734c045

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

py/bitbox02/bitbox02/communication/bitbox_api_protocol.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,17 @@ def _msg_query(
647647
print(response)
648648
return response
649649

650-
def reboot(self) -> bool:
651-
"""TODO: Document"""
650+
def reboot(
651+
self, purpose: system.RebootRequest.Purpose = system.RebootRequest.Purpose.UPGRADE
652+
) -> bool:
653+
"""
654+
Sends the reboot request. If the user confirms the request on the device, the device reboots
655+
into the bootloader.
656+
The purpose defines what confirmation message the user gets to see on the device.
657+
"""
652658
# pylint: disable=no-member
653659
request = hww.Request()
654-
request.reboot.CopyFrom(system.RebootRequest())
660+
request.reboot.CopyFrom(system.RebootRequest(purpose=purpose))
655661
try:
656662
self._msg_query(request)
657663
except OSError:

py/send_message.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ def _list_device_info(self) -> None:
241241
print(f"All info: {self._device.device_info()}")
242242

243243
def _reboot(self) -> None:
244-
if self._device.reboot():
244+
inp = input("Select one of: 1=upgrade; 2=go to startup settings: ").strip()
245+
purpose = {
246+
"1": bitbox02.system.RebootRequest.Purpose.UPGRADE, # pylint: disable=no-member
247+
"2": bitbox02.system.RebootRequest.Purpose.SETTINGS, # pylint: disable=no-member
248+
}[inp]
249+
if self._device.reboot(purpose=purpose):
245250
print("Device rebooted")
246251
self._stop = True
247252
else:
@@ -577,13 +582,6 @@ def _create_backup(self) -> None:
577582
except UserAbortException:
578583
print("Aborted by user")
579584

580-
def _reboot_bootloader(self) -> None:
581-
if self._device.reboot():
582-
print("Device rebooted")
583-
self._stop = True
584-
return
585-
print("User aborted")
586-
587585
def _toggle_mnemonic_passphrase(self) -> None:
588586
enabled = self._device.device_info()["mnemonic_passphrase_enabled"]
589587
try:
@@ -735,7 +733,7 @@ def _menu_init(self) -> None:
735733
("Check backup", self._check_backup),
736734
("Show mnemonic", self._show_mnemnoic_seed),
737735
("Create backup", self._create_backup),
738-
("Reboot into bootloader", self._reboot_bootloader),
736+
("Reboot into bootloader", self._reboot),
739737
("Check if SD card inserted", self._check_sd_presence),
740738
("Insert SD card", self._insert_sdcard),
741739
("Remove SD card", self._remove_sdcard),

src/rust/bitbox02-rust/src/hww/api/system.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@
1515
use super::Error;
1616
use crate::pb;
1717

18+
use pb::reboot_request::Purpose;
1819
use pb::response::Response;
1920

2021
use crate::workflow::confirm;
2122

22-
pub async fn reboot(&pb::RebootRequest {}: &pb::RebootRequest) -> Result<Response, Error> {
23+
pub async fn reboot(&pb::RebootRequest { purpose }: &pb::RebootRequest) -> Result<Response, Error> {
2324
confirm::confirm(&confirm::Params {
2425
title: "",
25-
body: "Proceed to upgrade?",
26+
body: match Purpose::from_i32(purpose) {
27+
Some(Purpose::Upgrade) => "Proceed to upgrade?",
28+
Some(Purpose::Settings) => "Go to\nstartup settings?",
29+
// No error, if new client library sends a purpose that we don't understand,
30+
// we reboot anyway.
31+
None => "Reboot?",
32+
},
2633
..Default::default()
2734
})
2835
.await?;

0 commit comments

Comments
 (0)