From 7cf992f7ed9ed93a496fc1755308a479e4230859 Mon Sep 17 00:00:00 2001 From: Matthew Wilkes Date: Fri, 31 May 2024 16:38:41 +0100 Subject: [PATCH] Protect against launching apps with import-time errors crashing launcher --- modules/system/launcher/app.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/system/launcher/app.py b/modules/system/launcher/app.py index e5e2b2c..b03743f 100644 --- a/modules/system/launcher/app.py +++ b/modules/system/launcher/app.py @@ -12,12 +12,15 @@ RequestStartAppEvent, RequestStopAppEvent, ) +from system.notification.events import ShowNotificationEvent APP_DIR = "/apps" + class InstallNotificationEvent(Event): pass + def path_isfile(path): # Wow totally an elegant way to do os.path.isfile... try: @@ -86,8 +89,10 @@ def __init__(self): self.update_menu() self._apps = {} eventbus.on_async(RequestStopAppEvent, self._handle_stop_app, self) - eventbus.on_async(InstallNotificationEvent, self._handle_refresh_notifications, self) - + eventbus.on_async( + InstallNotificationEvent, self._handle_refresh_notifications, self + ) + async def _handle_refresh_notifications(self, _): self.update_menu() @@ -146,8 +151,14 @@ def launch(self, item): print(self._apps) if app is None: print(f"Creating app {app_id}...") - module = __import__(module_name, None, None, (fn,)) - app = getattr(module, fn)() + try: + module = __import__(module_name, None, None, (fn,)) + app = getattr(module, fn)() + except Exception: + eventbus.emit( + ShowNotificationEvent(message=f"{item["name"]} has crashed") + ) + return self._apps[app_id] = app eventbus.emit(RequestStartAppEvent(app, foreground=True)) else: