Skip to content

Commit 7cf992f

Browse files
committed
Protect against launching apps with import-time errors crashing launcher
1 parent 0f3c8aa commit 7cf992f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

modules/system/launcher/app.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
RequestStartAppEvent,
1313
RequestStopAppEvent,
1414
)
15+
from system.notification.events import ShowNotificationEvent
1516

1617
APP_DIR = "/apps"
1718

19+
1820
class InstallNotificationEvent(Event):
1921
pass
2022

23+
2124
def path_isfile(path):
2225
# Wow totally an elegant way to do os.path.isfile...
2326
try:
@@ -86,8 +89,10 @@ def __init__(self):
8689
self.update_menu()
8790
self._apps = {}
8891
eventbus.on_async(RequestStopAppEvent, self._handle_stop_app, self)
89-
eventbus.on_async(InstallNotificationEvent, self._handle_refresh_notifications, self)
90-
92+
eventbus.on_async(
93+
InstallNotificationEvent, self._handle_refresh_notifications, self
94+
)
95+
9196
async def _handle_refresh_notifications(self, _):
9297
self.update_menu()
9398

@@ -146,8 +151,14 @@ def launch(self, item):
146151
print(self._apps)
147152
if app is None:
148153
print(f"Creating app {app_id}...")
149-
module = __import__(module_name, None, None, (fn,))
150-
app = getattr(module, fn)()
154+
try:
155+
module = __import__(module_name, None, None, (fn,))
156+
app = getattr(module, fn)()
157+
except Exception:
158+
eventbus.emit(
159+
ShowNotificationEvent(message=f"{item["name"]} has crashed")
160+
)
161+
return
151162
self._apps[app_id] = app
152163
eventbus.emit(RequestStartAppEvent(app, foreground=True))
153164
else:

0 commit comments

Comments
 (0)