Skip to content

Commit

Permalink
Protect against launching apps with import-time errors crashing launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewWilkes committed May 31, 2024
1 parent 0f3c8aa commit 7cf992f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions modules/system/launcher/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 7cf992f

Please sign in to comment.