From c28763c1691d26d2f83e1f430e1e6bab3b06a1fa Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Thu, 28 Jan 2021 12:21:43 +0100 Subject: [PATCH] refactor(core): use reload_settings_from_storage on boot --- core/src/apps/base.py | 17 +++++++++++------ core/src/apps/management/apply_settings.py | 12 ++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/core/src/apps/base.py b/core/src/apps/base.py index 966e7e959..e75a60951 100644 --- a/core/src/apps/base.py +++ b/core/src/apps/base.py @@ -3,7 +3,7 @@ import storage.device import storage.recovery import storage.sd_salt from storage import cache -from trezor import config, sdcard, utils, wire, workflow +from trezor import config, sdcard, ui, utils, wire, workflow from trezor.messages import Capability, MessageType from trezor.messages.Features import Features from trezor.messages.PreauthorizedRequest import PreauthorizedRequest @@ -260,6 +260,15 @@ def get_pinlocked_handler( return wrapper +# this function is also called when handling ApplySettings +def reload_settings_from_storage() -> None: + workflow.idle_timer.set( + storage.device.get_autolock_delay_ms(), lock_device_if_unlocked + ) + wire.experimental_enabled = storage.device.get_experimental_features() + ui.display.orientation(storage.device.get_rotation()) + + def boot() -> None: wire.register(MessageType.Initialize, handle_Initialize) wire.register(MessageType.GetFeatures, handle_GetFeatures) @@ -270,8 +279,4 @@ def boot() -> None: wire.register(MessageType.DoPreauthorized, handle_DoPreauthorized) wire.register(MessageType.CancelAuthorization, handle_CancelAuthorization) - wire.experimental_enabled = storage.device.get_experimental_features() - - workflow.idle_timer.set( - storage.device.get_autolock_delay_ms(), lock_device_if_unlocked - ) + reload_settings_from_storage() diff --git a/core/src/apps/management/apply_settings.py b/core/src/apps/management/apply_settings.py index 980670fcf..4f81bdc8a 100644 --- a/core/src/apps/management/apply_settings.py +++ b/core/src/apps/management/apply_settings.py @@ -1,11 +1,11 @@ import storage.device -from trezor import ui, wire, workflow +from trezor import ui, wire from trezor.messages import ButtonRequestType, SafetyCheckLevel from trezor.messages.Success import Success from trezor.strings import format_duration_ms from trezor.ui.components.tt.text import Text -from apps.base import lock_device_if_unlocked +from apps.base import reload_settings_from_storage from apps.common import safety_checks from apps.common.confirm import require_confirm, require_hold_to_confirm @@ -100,14 +100,6 @@ async def apply_settings(ctx: wire.Context, msg: ApplySettings): return Success(message="Settings applied") -def reload_settings_from_storage() -> None: - workflow.idle_timer.set( - storage.device.get_autolock_delay_ms(), lock_device_if_unlocked - ) - ui.display.orientation(storage.device.get_rotation()) - wire.experimental_enabled = storage.device.get_experimental_features() - - async def require_confirm_change_homescreen(ctx): text = Text("Set homescreen", ui.ICON_CONFIG) text.normal("Do you really want to", "change the homescreen", "image?")