diff --git a/internal_filesystem/lib/mpos/ui/__init__.py b/internal_filesystem/lib/mpos/ui/__init__.py index 7dfb4392..1b8c62c6 100644 --- a/internal_filesystem/lib/mpos/ui/__init__.py +++ b/internal_filesystem/lib/mpos/ui/__init__.py @@ -1,7 +1,7 @@ # lib/mpos/ui/__init__.py from .view import ( setContentView, back_screen, empty_screen_stack, - screen_stack + screen_stack, remove_and_stop_current_activity ) from .widget import handle_back_swipe, handle_top_swipe from .topmenu import open_bar, close_bar, open_drawer, drawer_open, NOTIFICATION_BAR_HEIGHT @@ -16,7 +16,7 @@ from .event import get_event_name, print_event from .util import shutdown, set_foreground_app, get_foreground_app, show_launcher __all__ = [ - "setContentView", "back_screen", "empty_screen_stack", + "setContentView", "back_screen", "empty_screen_stack", "remove_and_stop_current_activity" "handle_back_swipe", "handle_top_swipe", "open_bar", "close_bar", "open_drawer", "drawer_open", "NOTIFICATION_BAR_HEIGHT", "save_and_clear_current_focusgroup", diff --git a/internal_filesystem/lib/mpos/ui/topmenu.py b/internal_filesystem/lib/mpos/ui/topmenu.py index 071ae870..b509f1e8 100644 --- a/internal_filesystem/lib/mpos/ui/topmenu.py +++ b/internal_filesystem/lib/mpos/ui/topmenu.py @@ -305,12 +305,13 @@ def create_drawer(display=None): restart_label.set_text(lv.SYMBOL.REFRESH+" Reset") restart_label.center() def reset_cb(e): - mpos.ui.remove_and_stop_current_activity() # make sure current app, like camera, does cleanup, saves progress, stops hardware etc. + from .view import remove_and_stop_current_activity + remove_and_stop_current_activity() # make sure current app, like camera, does cleanup, saves progress, stops hardware etc. import machine if hasattr(machine, 'reset'): machine.reset() elif hasattr(machine, 'soft_reset'): - machine.soft_reset() + machine.soft_reset() # this causes a SystemExit exception on desktop else: print("Warning: machine has no reset or soft_reset method available") restart_btn.add_event_cb(reset_cb,lv.EVENT.CLICKED,None) @@ -322,7 +323,8 @@ def create_drawer(display=None): poweroff_label.center() def poweroff_cb(e): print("Power off action...") - mpos.ui.remove_and_stop_current_activity() # make sure current app, like camera, does cleanup, saves progress, stops hardware etc. + from .view import remove_and_stop_current_activity + remove_and_stop_current_activity() # make sure current app, like camera, does cleanup, saves progress, stops hardware etc. import sys if sys.platform == "esp32": #On ESP32, there's no power off but there is a forever sleep @@ -335,7 +337,7 @@ def create_drawer(display=None): print("Entering deep sleep. Press BOOT button to wake up.") machine.deepsleep() # sleep forever else: # assume unix: - lv.deinit() # Deinitialize LVGL (if supported) + lv.deinit() # Deinitialize LVGL (if supported) sys.exit(0) poweroff_btn.add_event_cb(poweroff_cb,lv.EVENT.CLICKED,None) # Add invisible padding at the bottom to make the drawer scrollable diff --git a/internal_filesystem/lib/mpos/ui/view.py b/internal_filesystem/lib/mpos/ui/view.py index 4cf2e6c4..a86ab567 100644 --- a/internal_filesystem/lib/mpos/ui/view.py +++ b/internal_filesystem/lib/mpos/ui/view.py @@ -28,6 +28,15 @@ def setContentView(new_activity, new_screen): if new_activity: new_activity.onResume(new_screen) +def remove_and_stop_current_activity(): + current_activity, current_screen, current_focusgroup, _ = screen_stack.pop() + if current_activity: + current_activity.onPause(current_screen) + current_activity.onStop(current_screen) + current_activity.onDestroy(current_screen) + if current_screen: + current_screen.clean() + def back_screen(): global screen_stack if len(screen_stack) <= 1: @@ -37,14 +46,7 @@ def back_screen(): from .util import close_top_layer_msgboxes close_top_layer_msgboxes() - # Pop current - current_activity, current_screen, current_focusgroup, _ = screen_stack.pop() - if current_activity: - current_activity.onPause(current_screen) - current_activity.onStop(current_screen) - current_activity.onDestroy(current_screen) - if current_screen: - current_screen.clean() + remove_and_stop_current_activity() # Load previous prev_activity, prev_screen, prev_focusgroup, prev_focused = screen_stack[-1] diff --git a/internal_filesystem/main.py b/internal_filesystem/main.py index 469a25ff..bb46f1ce 100644 --- a/internal_filesystem/main.py +++ b/internal_filesystem/main.py @@ -37,11 +37,13 @@ mpos.ui.topmenu.create_notification_bar() mpos.ui.topmenu.create_drawer(display) mpos.ui.handle_back_swipe() mpos.ui.handle_top_swipe() + # Clear top menu, notification bar, swipe back and swipe down buttons # Ideally, these would be stored in a different focusgroup that is used when the user opens the drawer focusgroup = lv.group_get_default() if focusgroup: # on esp32 this may not be set focusgroup.remove_all_objs() # might be better to save and restore the group for "back" actions + mpos.ui.th = task_handler.TaskHandler(duration=5) # 5ms is recommended for MicroPython+LVGL on desktop try: