Skip to content

Commit eeabe1b

Browse files
Make "Power Off" button on desktop exit completely
1 parent 304fa1a commit eeabe1b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

internal_filesystem/lib/mpos/ui/topmenu.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,18 @@ def poweroff_cb(e):
350350
print("Entering deep sleep...")
351351
machine.deepsleep() # sleep forever
352352
else: # assume unix:
353-
lv.deinit() # Deinitialize LVGL (if supported)
354-
sys.exit(0)
353+
import mpos ; mpos.TaskManager.stop() # fallback to a regular (non aiorepl) REPL shell
354+
lv.deinit() # Deinitialize LVGL (if supported) so the window closes instead of hanging because of LvReferenceError
355+
# On linux, and hopefully on macOS too, this seems to be the only way to kill the process, as sys.exit(0) just throws an exception:
356+
import os
357+
os.system("kill $PPID") # environment variable PPID seems to contain the process ID
358+
return
359+
# This is disable because it doesn't work - just throws an exception:
360+
try:
361+
print("Doing sys.exit(0)")
362+
sys.exit(0) # throws "SystemExit: 0" exception
363+
except Exception as e:
364+
print(f"sys.exit(0) threw exception: {e}") # can't seem to catch it
355365
poweroff_btn.add_event_cb(poweroff_cb,lv.EVENT.CLICKED,None)
356366
# Add invisible padding at the bottom to make the drawer scrollable
357367
l2 = lv.label(drawer)

0 commit comments

Comments
 (0)