Skip to content

Commit

Permalink
Enhancement for issue SeedSigner#546
Browse files Browse the repository at this point in the history
Provides 3 microSD options:
- Toast disabled
- 5-sec toast (default)
- SD card removal required* (fullscreen dialog,
cannot proceed unless microSD is removed)
  • Loading branch information
alvroble committed Aug 31, 2024
1 parent 235f1d9 commit 2554647
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/seedsigner/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from seedsigner.models.seed import Seed
from seedsigner.models.seed_storage import SeedStorage
from seedsigner.models.settings import Settings
from seedsigner.models.settings import SettingsConstants
from seedsigner.models.singleton import Singleton
from seedsigner.models.threads import BaseThread
from seedsigner.views.screensaver import ScreensaverScreen
Expand Down Expand Up @@ -285,7 +286,10 @@ def run(self):
next_destination = Destination(MainMenuView)

# Set up our one-time toast notification tip to remove the SD card
self.activate_toast(RemoveSDCardToastManagerThread())
if self.settings.get_value(SettingsConstants.SETTING__MICROSD_TOAST_TIMER) == SettingsConstants.MICROSD_TOAST_TIMER_FIVE_SECONDS:
self.activate_toast(RemoveSDCardToastManagerThread())
elif self.settings.get_value(SettingsConstants.SETTING__MICROSD_TOAST_TIMER) == SettingsConstants.MICROSD_TOAST_TIMER_FOREVER:
self.activate_toast(RemoveSDCardToastManagerThread(duration=1e6, hw_input_lock=True))

while True:
# Destination(None) is a special case; render the Home screen
Expand Down
22 changes: 16 additions & 6 deletions src/seedsigner/gui/toast.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ class BaseToastOverlayManagerThread(BaseThread):
def __init__(self,
activation_delay: int = 0, # seconds before toast is displayed
duration: int = 3, # seconds toast is displayed
hw_input_lock: bool = False,
):
from seedsigner.controller import Controller
from seedsigner.gui.renderer import Renderer
from seedsigner.hardware.buttons import HardwareButtons
super().__init__()
self.activation_delay: int = activation_delay
self.duration: int = duration
self.hw_input_lock: bool = hw_input_lock
self._toggle_renderer_lock: bool = False

self.renderer = Renderer.get_instance()
Expand Down Expand Up @@ -124,7 +126,7 @@ def run(self):
logger.info(f"{self.__class__.__name__}: started")
start = time.time()
while time.time() - start < self.activation_delay:
if self.hw_inputs.has_any_input():
if self.hw_inputs.has_any_input() and not self.hw_input_lock:
# User has pressed a button, cancel the toast
logger.info(f"{self.__class__.__name__}: Canceling toast due to user input")
return
Expand All @@ -140,7 +142,7 @@ def run(self):
has_rendered = False
previous_screen_state = None
while self.keep_running and self.should_keep_running():
if self.hw_inputs.has_any_input():
if self.hw_inputs.has_any_input() and not self.hw_input_lock:
# User has pressed a button, hide the toast
logger.info(f"{self.__class__.__name__}: Exiting due to user input")
break
Expand Down Expand Up @@ -187,21 +189,29 @@ def run(self):


class RemoveSDCardToastManagerThread(BaseToastOverlayManagerThread):
def __init__(self, activation_delay=3):
def __init__(self, activation_delay=3, duration=5, hw_input_lock=False):
# Note: activation_delay is configurable so the screenshot generator can get the
# toast to immediately render.
super().__init__(
activation_delay=activation_delay, # seconds
duration=1e6, # seconds ("forever")
duration=duration, # seconds
hw_input_lock=hw_input_lock,
)


def instantiate_toast(self) -> ToastOverlay:
if self.hw_input_lock:
self.height=self.renderer.canvas_height # Fullscreen toast
label_text="You must remove\nthe SD card now"
else:
self.height=GUIConstants.BODY_FONT_SIZE * 2 + GUIConstants.BODY_LINE_SPACING + GUIConstants.EDGE_PADDING
label_text="You can remove\nthe SD card now"

return ToastOverlay(
icon_name=SeedSignerIconConstants.MICROSD,
label_text="You can remove\nthe SD card now",
label_text=label_text,
font_size=GUIConstants.BODY_FONT_SIZE,
height=GUIConstants.BODY_FONT_SIZE * 2 + GUIConstants.BODY_LINE_SPACING + GUIConstants.EDGE_PADDING,
height=self.height
)


Expand Down
18 changes: 18 additions & 0 deletions src/seedsigner/models/settings_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ def map_network_to_embit(cls, network) -> str:
(CUSTOM_DERIVATION, "Custom Derivation"),
]

MICROSD_TOAST_TIMER_DISABLED = "D"
MICROSD_TOAST_TIMER_FIVE_SECONDS = "E"
MICROSD_TOAST_TIMER_FOREVER = "inf"
ALL_MICROSD_TOAST_TIMERS = [
(MICROSD_TOAST_TIMER_DISABLED, "Disabled"),
(MICROSD_TOAST_TIMER_FIVE_SECONDS, "5 seconds"),
(MICROSD_TOAST_TIMER_FOREVER, "Until SD removed")
]

WORDLIST_LANGUAGE__ENGLISH = "en"
WORDLIST_LANGUAGE__CHINESE_SIMPLIFIED = "zh_Hans_CN"
WORDLIST_LANGUAGE__CHINESE_TRADITIONAL = "zh_Hant_TW"
Expand Down Expand Up @@ -167,6 +176,7 @@ def map_network_to_embit(cls, network) -> str:
SETTING__DIRE_WARNINGS = "dire_warnings"
SETTING__QR_BRIGHTNESS_TIPS = "qr_brightness_tips"
SETTING__PARTNER_LOGOS = "partner_logos"
SETTING__MICROSD_TOAST_TIMER = "microsd_toast_timer"

SETTING__DEBUG = "debug"

Expand Down Expand Up @@ -478,6 +488,14 @@ class SettingsDefinition:
help_text="Native Segwit only",
visibility=SettingsConstants.VISIBILITY__ADVANCED,
default_value=SettingsConstants.OPTION__DISABLED),

SettingsEntry(category=SettingsConstants.CATEGORY__FEATURES,
attr_name=SettingsConstants.SETTING__MICROSD_TOAST_TIMER,
display_name="MicroSD toast timer",
type=SettingsConstants.TYPE__SELECT_1,
visibility=SettingsConstants.VISIBILITY__ADVANCED,
selection_options=SettingsConstants.ALL_MICROSD_TOAST_TIMERS,
default_value=SettingsConstants.MICROSD_TOAST_TIMER_FIVE_SECONDS),

SettingsEntry(category=SettingsConstants.CATEGORY__FEATURES,
attr_name=SettingsConstants.SETTING__MESSAGE_SIGNING,
Expand Down
1 change: 1 addition & 0 deletions tests/screenshot_generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def add_op_return_to_psbt(psbt: PSBT, raw_payload_data: bytes):
(MainMenuView, {}, 'MainMenuView_SDCardStateChangeToast_removed', SDCardStateChangeToastManagerThread(action=MicroSD.ACTION__REMOVED)),
(MainMenuView, {}, 'MainMenuView_SDCardStateChangeToast_inserted', SDCardStateChangeToastManagerThread(action=MicroSD.ACTION__INSERTED)),
(MainMenuView, {}, 'MainMenuView_RemoveSDCardToast', RemoveSDCardToastManagerThread(activation_delay=0)),
(MainMenuView, {}, 'MainMenuView_RemoveSDCardToast_Forever', RemoveSDCardToastManagerThread(activation_delay=0, fullscreen=True, hw_input_lock=True)),
PowerOptionsView,
RestartView,
PowerOffView,
Expand Down

0 comments on commit 2554647

Please sign in to comment.