1
0
Fork 0

manager: Improve application registration

When an application is registered using a string that gives the class
name (e.g.  "apps.chrono.ChronoApp") when we automatically delete
the module from a couple of namespaces. This ensures the garbage
collector can do a deeper clean when the application is unregistered.

We also provide a means to directly register watch faces (e.g. to
replace the default clock).

Fixes: #214
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2021-06-03 19:57:09 +01:00
parent 0d385b8dc5
commit e76a4afd85

View file

@ -18,6 +18,7 @@ import gc
import machine import machine
import micropython import micropython
import steplogger import steplogger
import sys
import watch import watch
import widgets import widgets
@ -166,16 +167,21 @@ class Manager():
# an exception starting one of the apps... # an exception starting one of the apps...
pass pass
def register(self, app, quick_ring=False): def register(self, app, quick_ring=False, watch_face=False):
"""Register an application with the system. """Register an application with the system.
:param object app: The application to regsister :param object app: The application to regsister
""" """
if isinstance(app, str): if isinstance(app, str):
exec('import ' + app[:app.rindex('.')]) modname = app[:app.rindex('.')]
exec('import ' + modname)
app = eval(app + '()') app = eval(app + '()')
exec('del ' + modname)
exec('del sys.modules["' + modname + '"]')
if quick_ring == True: if watch_face:
self.quick_ring[0] = app
elif quick_ring:
self.quick_ring.append(app) self.quick_ring.append(app)
else: else:
self.launcher_ring.append(app) self.launcher_ring.append(app)