Skip to content

Commit 81983d5

Browse files
Improvements to background functionality reliability (#233)
* Prevent crashes in background draws from crashing the launcher * Repopulate backgrounds in settings app on foreground push, so new installs don't need a restart
1 parent e4413e6 commit 81983d5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

modules/app_components/background.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ def update(self, delta):
4949
def draw(self, ctx):
5050
if self.runner:
5151
ctx.save()
52-
self.runner.draw(ctx)
52+
try:
53+
self.runner.draw(ctx)
54+
except Exception as e:
55+
print(f"Error creating background: {e}")
56+
eventbus.emit(
57+
ShowNotificationEvent(
58+
message=f"Background {self.selection[0]} has crashed"
59+
)
60+
)
61+
self.runner = None
5362
ctx.restore()
5463
else:
5564
clear_background(ctx)

modules/firmware_apps/settings_app.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from system.patterndisplay.events import PatternReload
99
from app_components.background import Background as bg
1010
from system.launcher.app import load_info
11+
from system.scheduler.events import RequestForegroundPushEvent
1112

1213
BG_DIR = "/backgrounds"
1314

@@ -56,6 +57,12 @@ def __init__(self):
5657
self.layout = layout.LinearLayout(items=[layout.DefinitionDisplay("", "")])
5758
self.overlays = []
5859
self.dialog = None
60+
self.load_background_options()
61+
self.ctx = None
62+
eventbus.on_async(ButtonDownEvent, self._button_handler, self)
63+
eventbus.on(RequestForegroundPushEvent, self.load_background_options, self)
64+
65+
def load_background_options(self, event=None):
5966
self.backgrounds = [("None", None), ("hexagons", None), ("emf logo", None)]
6067
try:
6168
contents = os.listdir(BG_DIR)
@@ -72,9 +79,6 @@ def __init__(self):
7279
if "name" in metadata:
7380
name = metadata["name"]
7481
self.backgrounds.append((name, path))
75-
self.ctx = None
76-
eventbus.on_async(ButtonDownEvent, self._button_handler, self)
77-
# eventbus.on(RequestForegroundPushEvent, self.make_layout_children, self)
7882

7983
async def string_editor(self, label, id, render_update):
8084
self.dialog = TextDialog(label, self)

0 commit comments

Comments
 (0)