Fix reset and shutdown actions

This commit is contained in:
Thomas Farstrike
2025-10-30 21:22:37 +01:00
parent c15bd6c263
commit f5390ccbe0
4 changed files with 20 additions and 14 deletions
+2 -2
View File
@@ -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",
+6 -4
View File
@@ -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
+10 -8
View File
@@ -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]
+2
View File
@@ -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: