Skip to content

Commit

Permalink
correct memory management of firmware, login and tools imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeubas committed Sep 2, 2024
1 parent 6e6e75c commit 12212d2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion i18n/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def bake_translations():
with open(filepath, "w", encoding="utf8", newline="\n") as translations:
translations.write(file_header)
translations.write("translation_index = ")
translations.write(repr(translation_index))
translations.write(repr(tuple(translation_index)))
translations.write("\n\n")
print("Baked", filepath)

Expand Down
27 changes: 15 additions & 12 deletions src/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,41 @@ def draw_splash():

def check_for_updates():
"""Checks SD card, if a valid firmware is found asks if user wants to update the device"""
from krux import firmware
import krux.firmware

if firmware.upgrade():
if krux.firmware.upgrade():
power_manager.shutdown()

# Unimport firware
sys.modules.pop("krux.firmware")
del sys.modules["krux"].firmware
del firmware
del krux.firmware
del sys.modules["krux.firmware"]


def login(ctx_login):
"""Loads and run the Login page"""
from krux.pages.login import Login
import krux.pages.login

login_start_from = None
while True:
if not Login(ctx_login).run(login_start_from):
login = krux.pages.login.Login(ctx_login)
if not login.run(login_start_from):
break

if ctx_login.wallet is not None:
# Have a loaded wallet
del login
break

# Login closed due to change of locale at Settings
login_start_from = (
Login.SETTINGS_MENU_INDEX
krux.pages.login.Login.SETTINGS_MENU_INDEX
) # will start Login again from Settings index
del login


# Unimport Login the free memory
sys.modules.pop("krux.pages.login")
del sys.modules["krux"].pages.login
del Login
# Unimport login
del krux.pages.login
del sys.modules["krux.pages.login"]


def home(ctx_home):
Expand Down
10 changes: 6 additions & 4 deletions src/krux/pages/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,15 +754,17 @@ def load_key_from_tiny_seed_image(self, grid_type="Tiny Seed"):

def tools(self):
"""Handler for the 'Tools' menu item"""
from .tools import Tools
import krux.pages.tools

tools = krux.pages.tools.Tools(self.ctx)
while True:
if Tools(self.ctx).run() == MENU_EXIT:
if tools.run() == MENU_EXIT:
break

# Unimport tools
sys.modules.pop("krux.pages.tools")
del sys.modules["krux.pages"].tools
del tools
del krux.pages.tools
del sys.modules["krux.pages.tools"]

return MENU_CONTINUE

Expand Down
4 changes: 2 additions & 2 deletions src/krux/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

translation_index = [
translation_index = (
"de-DE",
"es-MX",
"fr-FR",
Expand All @@ -29,4 +29,4 @@
"ru-RU",
"tr-TR",
"vi-VN",
]
)

0 comments on commit 12212d2

Please sign in to comment.