Files
MicroPythonOS/internal_filesystem/main.py
T

76 lines
2.8 KiB
Python
Raw Normal View History

import task_handler
2025-06-13 09:02:30 +02:00
import _thread
2025-06-19 19:57:29 +02:00
import lvgl as lv
# Allow LVGL M:/path/to/file or M:relative/path/to/file to work for image set_src etc
2025-07-05 02:26:59 +02:00
import mpos.fs_driver
fs_drv = lv.fs_drv_t()
2025-07-05 02:26:59 +02:00
mpos.fs_driver.fs_register(fs_drv, 'M')
2025-06-13 14:50:03 +02:00
import mpos.apps
2025-06-17 10:45:29 +02:00
import mpos.config
import mpos.ui
2025-07-04 15:50:51 +02:00
import mpos.ui.topmenu
2025-10-30 20:31:02 +01:00
from mpos.ui.display import init_rootscreen
2025-11-12 11:56:16 +01:00
from mpos.content.package_manager import PackageManager
2025-06-06 10:58:27 +02:00
2025-06-17 10:45:29 +02:00
prefs = mpos.config.SharedPreferences("com.micropythonos.settings")
mpos.ui.set_theme(prefs)
2025-10-30 20:31:02 +01:00
init_rootscreen()
2025-07-04 15:50:51 +02:00
mpos.ui.topmenu.create_notification_bar()
mpos.ui.topmenu.create_drawer(mpos.ui.display)
2025-05-25 11:36:49 +02:00
mpos.ui.handle_back_swipe()
mpos.ui.handle_top_swipe()
2025-10-30 21:22:37 +01:00
# 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
2025-10-30 21:22:37 +01:00
2025-11-07 11:58:53 +01:00
# Can be passed to TaskHandler, currently unused:
def custom_exception_handler(e):
print(f"custom_exception_handler called: {e}")
mpos.ui.task_handler.deinit()
2025-11-07 11:58:53 +01:00
# otherwise it does focus_next and then crashes while doing lv.deinit()
focusgroup.remove_all_objs()
focusgroup.delete()
lv.deinit()
2025-11-07 11:58:53 +01:00
import sys
if sys.platform == "esp32":
mpos.ui.task_handler = task_handler.TaskHandler(duration=5) # 1ms gives highest framerate on esp32-s3's but might have side effects?
else:
mpos.ui.task_handler = task_handler.TaskHandler(duration=5) # 5ms is recommended for MicroPython+LVGL on desktop (less results in lower framerate)
2025-04-21 11:37:30 +02:00
try:
2025-04-30 13:49:42 +02:00
import freezefs_mount_builtin
except Exception as e:
2025-06-13 14:50:03 +02:00
# This will throw an exception if there is already a "/builtin" folder present
2025-05-10 17:27:16 +02:00
print("main.py: WARNING: could not import/run freezefs_mount_builtin: ", e)
2025-06-13 09:02:30 +02:00
try:
from mpos.net.wifi_service import WifiService
2025-06-13 09:02:30 +02:00
_thread.stack_size(mpos.apps.good_stack_size())
_thread.start_new_thread(WifiService.auto_connect, ())
2025-06-13 09:02:30 +02:00
except Exception as e:
print(f"Couldn't start WifiService.auto_connect thread because: {e}")
2025-05-20 21:29:24 +02:00
2025-11-12 11:56:16 +01:00
# Start launcher so it's always at bottom of stack
launcher_app = PackageManager.get_launcher()
started_launcher = mpos.apps.start_app(launcher_app.fullname)
2025-11-12 12:24:36 +01:00
# Then start auto_start_app if configured
2025-11-12 11:56:16 +01:00
auto_start_app = prefs.get_string("auto_start_app", None)
if auto_start_app and launcher_app.fullname != auto_start_app:
mpos.apps.start_app(auto_start_app)
2025-05-01 15:44:12 +02:00
if not started_launcher:
print("WARNING: launcher {launcher_app} failed to start, not cancelling OTA update rollback")
else:
try:
import ota.rollback
ota.rollback.cancel()
except Exception as e:
print("main.py: warning: could not mark this update as valid:", e)