Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/embed/firmware/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define ONEKEY_VERSION_MAJOR 4
#define ONEKEY_VERSION_MINOR 17
#define ONEKEY_VERSION_PATCH 0
#define ONEKEY_VERSION_PATCH 1
#define ONEKEY_VERSION_BUILD 0

// Minimum SE version required for firmware upgrade
Expand Down
130 changes: 111 additions & 19 deletions core/src/trezor/lvglui/scrs/homescreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
create_preview_container,
create_preview_image,
create_top_mask,
refresh_preview_device_labels,
)
from .widgets.style import StyleWrapper

Expand Down Expand Up @@ -400,9 +401,9 @@ def apply_lock_wallpaper(new_wallpaper: str | None) -> None:

def replace_wallpaper_if_in_use(
deleted_path: str | None, replacement_path: str | None = None
) -> None:
) -> bool:
if not deleted_path:
return
return False

replacement = replacement_path or utils.get_default_wallpaper()
base_name = deleted_path.split("/")[-1]
Expand All @@ -415,6 +416,7 @@ def replace_wallpaper_if_in_use(

current_home = storage_device.get_appdrawer_background()
current_lock = storage_device.get_homescreen()
replaced = False

def _matches(candidate: str | None) -> bool:
if not candidate:
Expand All @@ -427,8 +429,11 @@ def _matches(candidate: str | None) -> bool:

if _matches(current_home):
apply_home_wallpaper(replacement)
replaced = True
if _matches(current_lock):
apply_lock_wallpaper(replacement)
replaced = True
return replaced


def brightness2_percent_str(brightness: int) -> str:
Expand Down Expand Up @@ -882,7 +887,6 @@ def hidden(self):
self.add_flag(lv.obj.FLAG.HIDDEN)

class AppDrawer(lv.obj):
PAGE_SIZE = 2
PAGE_SLIDE_TIME = 300 # Animation time with ease_out for smooth feel

def __init__(self, parent):
Expand All @@ -897,6 +901,10 @@ def __init__(self, parent):

# Remove style and lazy loading related code to fix system freeze

# Calculate PAGE_SIZE dynamically
item_count = 7 if utils.BITCOIN_ONLY else 8
self.PAGE_SIZE = (item_count + 3) // 4

self.init_ui()
self.init_items() # Restore original immediate creation of all items
self._configure_image_cache()
Expand Down Expand Up @@ -1295,6 +1303,58 @@ def hide_to_mainscreen_fallback(self):
if hasattr(self.parent, "restore_main_content"):
self.parent.restore_main_content()

def bounce_page(self, direction):
if self.page_animating:
return

self.page_animating = True
current_wrap = self.page_wraps[self.current_page]

# If swiping LEFT (trying to go next), we move left (negative x) then back
# If swiping RIGHT (trying to go prev), we move right (positive x) then back
bounce_dist = 40
offset = -bounce_dist if direction == lv.DIR.LEFT else bounce_dist

original_x = self._page_wrap_origin_x
target_x = original_x + offset

anim_time = 150

def animate_x(target_obj, start_x, end_x, ready_cb=None):
anim = lv.anim_t()
anim.init()
anim.set_var(target_obj)
anim.set_values(start_x, end_x)
anim.set_time(anim_time)
anim.set_path_cb(lv.anim_t.path_ease_out)

def exec_cb(_anim, val, *, target=target_obj):
target.set_x(int(val))

anim.set_custom_exec_cb(exec_cb)
if ready_cb:
anim.set_ready_cb(ready_cb)
anim.set_repeat_count(1)
return anim

def on_bounce_back_ready(_anim):
self.page_animating = False
self._page_anim_refs = []
self._page_anim_handles = []

def on_bounce_out_ready(_anim):
anim_back = animate_x(
current_wrap, target_x, original_x, on_bounce_back_ready
)
self._page_anim_refs = [anim_back]
self._page_anim_handles = [lv.anim_t.start(anim_back)]

anim_out = animate_x(
current_wrap, original_x, target_x, on_bounce_out_ready
)
self._page_anim_refs = [anim_out]
self._page_anim_handles = [lv.anim_t.start(anim_out)]

def handle_page_gesture(self, _dir):
if _dir not in [lv.DIR.RIGHT, lv.DIR.LEFT]:
return
Expand All @@ -1309,9 +1369,13 @@ def handle_page_gesture(self, _dir):
return

if _dir == lv.DIR.LEFT:
target_page = (self.current_page + 1) % self.PAGE_SIZE
target_page = self.current_page + 1
else:
target_page = (self.current_page - 1 + self.PAGE_SIZE) % self.PAGE_SIZE
target_page = self.current_page - 1

if target_page < 0 or target_page >= self.PAGE_SIZE:
self.bounce_page(_dir)
return

if target_page == self.current_page:
return
Expand Down Expand Up @@ -1369,7 +1433,7 @@ def animate_page_transition(self, target_index: int, direction: int):
return

# Clean up memory before starting animation to prevent GC during animation
gc.collect()
# gc.collect() # Removed to improve start smoothness

self.page_animating = True
self._page_anim_target = target_index
Expand Down Expand Up @@ -1485,8 +1549,10 @@ def _on_page_anim_ready(
self._page_anim_handles = []

# Clean up immediately if forced, otherwise let normal GC handle it
if force:
gc.collect()
# if force:
# gc.collect()
# Always collect at the end of animation to keep memory clean for next time
gc.collect()

def force_cleanup(self):
self.finish_page_animation(force=True)
Expand Down Expand Up @@ -3860,11 +3926,7 @@ def __init__(
self.current_wallpaper_path = "A:/res/wallpaper-7.jpg"
self.lockscreen_preview.set_src("A:/res/wallpaper-7.jpg")

device_name = storage_device.get_label() or "OneKey Pro"
ble_name = storage_device.get_ble_name() or uart.get_ble_name()

self.device_name_label = lv.label(self.preview_container)
self.device_name_label.set_text(device_name)

self.device_name_label.add_style(
StyleWrapper()
Expand All @@ -3873,14 +3935,11 @@ def __init__(
.text_align(lv.TEXT_ALIGN.CENTER),
0,
)

# Stretch to container width so center alignment is accurate
self.device_name_label.set_width(self.preview_container.get_width())
self.device_name_label.align_to(self.preview_container, lv.ALIGN.TOP_MID, 0, 49)

self.bluetooth_label = lv.label(self.preview_container)
if ble_name and len(ble_name) >= 4:
self.bluetooth_label.set_text("Pro " + ble_name[-4:])
else:
self.bluetooth_label.set_text("Pro")

self.bluetooth_label.add_style(
StyleWrapper()
Expand All @@ -3889,10 +3948,12 @@ def __init__(
.text_align(lv.TEXT_ALIGN.CENTER),
0,
)

self.bluetooth_label.set_width(self.preview_container.get_width())
self.bluetooth_label.align_to(
self.device_name_label, lv.ALIGN.OUT_BOTTOM_MID, 0, 8
)
# Sync visibility/text with the Display setting (model name & Bluetooth ID)
refresh_preview_device_labels(self.device_name_label, self.bluetooth_label)

self.change_button_container = lv.obj(self.container)
self.change_button_container.set_size(120, 100)
Expand Down Expand Up @@ -4002,6 +4063,7 @@ def refresh_text(self):
self.container.invalidate()

self.invalidate()
refresh_preview_device_labels(self.device_name_label, self.bluetooth_label)

async def _first_frame_fix(self):
utime.sleep_ms(100)
Expand Down Expand Up @@ -4850,7 +4912,37 @@ def delete_marked_files(self):
self.__init__(self.prev_scr)

def replace_if_in_use(self, deleted_path):
replace_wallpaper_if_in_use(deleted_path, "A:/res/wallpaper-7.jpg")
replacement = "A:/res/wallpaper-7.jpg"
was_replaced = replace_wallpaper_if_in_use(deleted_path, replacement)

if not was_replaced:
return
Comment thread
guowei0105 marked this conversation as resolved.

prev = getattr(self, "prev_scr", None)
if not prev:
return

if prev.__class__.__name__ == "HomeScreenSetting":
prev.is_blur_active = False
prev.original_wallpaper_path = replacement
prev.current_wallpaper_path = replacement
if hasattr(prev, "_blur_cache"):
prev._blur_cache.clear()
if hasattr(prev, "homescreen_preview"):
prev.homescreen_preview.set_src(replacement)
if hasattr(prev, "_update_blur_button_state"):
prev._update_blur_button_state()

if prev.__class__.__name__ == "AppdrawerBackgroundSetting":
prev.selected_wallpaper = replacement
prev.current_wallpaper_path = replacement
if hasattr(prev, "lockscreen_preview"):
prev.lockscreen_preview.set_src(replacement)
if hasattr(prev, "refresh_text"):
prev.refresh_text()

if hasattr(prev, "invalidate"):
prev.invalidate()

def eventhandler(self, event_obj):
event = event_obj.code
Expand Down
22 changes: 12 additions & 10 deletions core/src/trezor/lvglui/scrs/nftmanager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import math
from typing import Callable

import storage.device as storage_device
from trezor import io as trezor_io, uart, utils, workflow
from trezor import io as trezor_io, utils, workflow
from trezor.lvglui.i18n import gettext as _, keys as i18n_keys
from trezor.lvglui.lv_colors import lv_colors

Expand All @@ -24,6 +23,7 @@
create_preview_container,
create_preview_image,
create_top_mask,
refresh_preview_device_labels,
)
from .widgets.style import StyleWrapper

Expand Down Expand Up @@ -577,11 +577,7 @@ def __init__(self, prev_scr, nft_path, nft_config):
self._create_preview_container(top_offset=118)
self.lockscreen_preview = self._create_preview_image(nft_path)

device_name = storage_device.get_label() or "OneKey Pro"
ble_name = storage_device.get_ble_name() or uart.get_ble_name()

self.device_name_label = lv.label(self.preview_container)
self.device_name_label.set_text(device_name)
self.device_name_label.add_style(
_cached_style(
_K2,
Expand All @@ -592,13 +588,11 @@ def __init__(self, prev_scr, nft_path, nft_config):
),
0,
)
# Full width to ensure center alignment within the preview frame
self.device_name_label.set_width(self.preview_container.get_width())
self.device_name_label.align_to(self.preview_container, lv.ALIGN.TOP_MID, 0, 49)

self.bluetooth_label = lv.label(self.preview_container)
if ble_name and len(ble_name) >= 4:
self.bluetooth_label.set_text("Pro " + ble_name[-4:])
else:
self.bluetooth_label.set_text("Pro")
self.bluetooth_label.add_style(
_cached_style(
_K3,
Expand All @@ -609,9 +603,13 @@ def __init__(self, prev_scr, nft_path, nft_config):
),
0,
)
self.bluetooth_label.set_width(self.preview_container.get_width())
self.bluetooth_label.align_to(
self.device_name_label, lv.ALIGN.OUT_BOTTOM_MID, 0, 8
)
refresh_preview_device_labels(
self.device_name_label, self.bluetooth_label, ble_prefix="Pro"
)

def eventhandler(self, event_obj):
event = event_obj.code
Expand All @@ -637,6 +635,10 @@ def eventhandler(self, event_obj):
)
self.load_screen(main_screen, destroy_self=True)
return
# Sync with current Display toggle if it changed while this screen is open
refresh_preview_device_labels(
self.device_name_label, self.bluetooth_label, ble_prefix="Pro"
)

def _mark_disposed(self):
if getattr(self, "_disposed", False):
Expand Down
43 changes: 43 additions & 0 deletions core/src/trezor/lvglui/scrs/preview_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import math

import storage.device as storage_device
from trezor import uart

from .common import lv


Expand Down Expand Up @@ -91,3 +94,43 @@ def create_preview_image(
image.set_src(src)

return image


def refresh_preview_device_labels(
device_name_label,
bluetooth_label=None,
*,
show_device_names=None,
ble_prefix="Pro",
):
"""Sync preview labels with the Display toggle (model name & BLE ID)."""
if not device_name_label:
return

show_setting = (
storage_device.is_device_name_display_enabled()
if show_device_names is None
else show_device_names
)

device_name = storage_device.get_label() or "OneKey Pro"
ble_name = storage_device.get_ble_name() or uart.get_ble_name()

if show_setting:
device_name_label.set_text(device_name)
device_name_label.clear_flag(lv.obj.FLAG.HIDDEN)

if bluetooth_label:
if ble_name and len(ble_name) >= 4:
# pylint: disable=consider-using-f-string
bluetooth_label.set_text("{} {}".format(ble_prefix, ble_name[-4:]))
else:
bluetooth_label.set_text(ble_prefix)
bluetooth_label.clear_flag(lv.obj.FLAG.HIDDEN)
else:
device_name_label.set_text("")
device_name_label.add_flag(lv.obj.FLAG.HIDDEN)

if bluetooth_label:
bluetooth_label.set_text("")
bluetooth_label.add_flag(lv.obj.FLAG.HIDDEN)
2 changes: 1 addition & 1 deletion core/src/trezor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def get_default_wallpaper():
elif _COLOR_FLAG == "B": # white shell
return "A:/res/wallpaper-2.jpg"
else:
return "A:/res/wallpaper-1.jpg"
return "A:/res/wallpaper-7.jpg"


def unimport_begin() -> set[str]:
Expand Down
Loading