From e73ff1f3c25cbba123d4f5231f5d13c4354410c6 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Thu, 15 Dec 2016 12:48:33 +0100 Subject: [PATCH] apps: improve language getters/setters --- src/apps/common/storage.py | 15 +++++++++++++-- src/apps/homescreen/__init__.py | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/apps/common/storage.py b/src/apps/common/storage.py index 44eae19031..be81ee35a2 100644 --- a/src/apps/common/storage.py +++ b/src/apps/common/storage.py @@ -96,6 +96,10 @@ def get_label() -> str: return config_get(_LABEL).decode() +def get_language() -> str: + return config_get(_LANGUAGE).decode() or _DEFAULT_LANGUAGE + + def get_mnemonic() -> str: utils.ensure(is_initialized()) utils.ensure(not is_locked()) @@ -114,6 +118,10 @@ def load_mnemonic(mnemonic: str): config_set(_MNEMONIC, mnemonic.encode()) +_ALLOWED_LANGUAGES = ('english') +_DEFAULT_LANGUAGE = 'english' + + def load_settings(language: str=None, label: str=None, pin: str=None, @@ -121,8 +129,11 @@ def load_settings(language: str=None, utils.ensure(is_initialized()) utils.ensure(not is_locked()) - if language is not None: - config_set(_LANGUAGE, language.encode()) + if language is not None and language in _ALLOWED_LANGUAGES: + if language is _DEFAULT_LANGUAGE: + config_set(_LANGUAGE, b'') + else: + config_set(_LANGUAGE, language.encode()) if label is not None: config_set(_LABEL, label.encode()) if pin is not None: diff --git a/src/apps/homescreen/__init__.py b/src/apps/homescreen/__init__.py index e76f9c7ce0..7daba7a415 100644 --- a/src/apps/homescreen/__init__.py +++ b/src/apps/homescreen/__init__.py @@ -3,6 +3,7 @@ from trezor.utils import unimport from trezor.messages.wire_types import Initialize, GetFeatures, Ping +@unimport async def respond_Features(session_id, msg): from apps.common import storage, coins from trezor.messages.Features import Features @@ -18,6 +19,7 @@ async def respond_Features(session_id, msg): f.device_id = storage.get_device_id() f.label = storage.get_label() + f.language = storage.get_language() f.initialized = storage.is_initialized() f.pin_protection = storage.is_protected_by_pin() f.passphrase_protection = storage.is_protected_by_passphrase() @@ -25,6 +27,7 @@ async def respond_Features(session_id, msg): return f +@unimport async def respond_Pong(session_id, msg): from trezor.messages.Success import Success