You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
firstrun: handle auto start
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
from mpos import Activity
|
||||
from mpos import Activity, SharedPreferences
|
||||
|
||||
class FirstRun(Activity):
|
||||
|
||||
appname = "com.micropythonos.firstrun"
|
||||
|
||||
dontshow_checkbox = None
|
||||
prefs = None
|
||||
autostart_enabled = None
|
||||
|
||||
def onCreate(self):
|
||||
screen = lv.obj()
|
||||
@@ -33,7 +37,22 @@ If you've got 2 buttons, one is PREVIOUS, the other is NEXT. To ENTER, press bot
|
||||
|
||||
self.setContentView(screen)
|
||||
|
||||
def onResume(self, screen):
|
||||
# Autostart can only be disabled if nothing was enabled or if this app was enabled
|
||||
self.prefs = SharedPreferences("com.micropythonos.settings")
|
||||
auto_start_app_early = self.prefs.get_string("auto_start_app_early")
|
||||
print(f"auto_start_app_early: {auto_start_app_early}")
|
||||
if auto_start_app_early is None or auto_start_app_early == self.appname: # empty also means autostart because then it's the default
|
||||
self.dontshow_checkbox.remove_state(lv.STATE.CHECKED)
|
||||
else:
|
||||
self.dontshow_checkbox.add_state(lv.STATE.CHECKED)
|
||||
|
||||
def onPause(self, screen):
|
||||
checked = self.dontshow_checkbox.get_state() & lv.STATE.CHECKED
|
||||
print("Removing this app from autostart")
|
||||
editor = self.prefs.edit()
|
||||
if checked:
|
||||
print("TODO: make sure this doesn't appear again")
|
||||
editor.put_string("auto_start_app_early", "") # None might result in the OS starting it, empty string means explictly don't start it
|
||||
else:
|
||||
editor.put_string("auto_start_app_early", self.appname)
|
||||
editor.commit()
|
||||
|
||||
@@ -161,7 +161,7 @@ except Exception as e:
|
||||
# This will throw an exception if there is already a "/builtin" folder present
|
||||
print("main.py: WARNING: could not import/run freezefs_mount_builtin: ", e)
|
||||
|
||||
prefs = SharedPreferences("com.micropythonos.settings", defaults={"auto_start_app": "com.micropythonos.firstrun"}) # if not value is set, it will start the FirstRun app
|
||||
prefs = SharedPreferences("com.micropythonos.settings", defaults={"auto_start_app_early": "com.micropythonos.firstrun"}) # if not value is set, it will start the FirstRun app
|
||||
|
||||
AppearanceManager.init(prefs)
|
||||
init_rootscreen() # shows the boot logo
|
||||
@@ -208,12 +208,18 @@ except Exception as e:
|
||||
# Start launcher first so it's always at bottom of stack
|
||||
launcher_app = AppManager.get_launcher()
|
||||
started_launcher = AppManager.start_app(launcher_app.fullname)
|
||||
# Then start auto_start_app if configured
|
||||
auto_start_app = prefs.get_string("auto_start_app", None)
|
||||
if auto_start_app and launcher_app.fullname != auto_start_app:
|
||||
result = AppManager.start_app(auto_start_app)
|
||||
# Then start auto_start_app_early if configured
|
||||
auto_start_app_early = prefs.get_string("auto_start_app_early", "com.micropythonos.firstrun")
|
||||
if auto_start_app_early and launcher_app.fullname != auto_start_app_early:
|
||||
result = AppManager.start_app(auto_start_app_early)
|
||||
if result is not True:
|
||||
print(f"WARNING: could not run {auto_start_app} app")
|
||||
print(f"WARNING: could not run {auto_start_app_early} app")
|
||||
else: # if no auto_start_app_early was configured (this could be improved to start it *after* auto_start_app_early finishes)
|
||||
auto_start_app = prefs.get_string("auto_start_app", None)
|
||||
if auto_start_app and launcher_app.fullname != auto_start_app and auto_start_app_early != auto_start_app:
|
||||
result = AppManager.start_app(auto_start_app)
|
||||
if result is not True:
|
||||
print(f"WARNING: could not run {auto_start_app} app")
|
||||
|
||||
# Create limited aiorepl because it's better than nothing:
|
||||
import aiorepl
|
||||
|
||||
Reference in New Issue
Block a user