mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00:00
DisplaySettings: Handle errors when loading wallpaper bitmap
Prior this change, the app crashed if the first file in alphabetical order in /res/wallpapers couldn't be decoded.
This commit is contained in:
parent
ac65fb40d9
commit
e38b3f526e
1 changed files with 9 additions and 10 deletions
|
@ -30,23 +30,22 @@ bool MonitorWidget::set_wallpaper(String path)
|
||||||
if (!is_different_to_current_wallpaper_path(path))
|
if (!is_different_to_current_wallpaper_path(path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Threading::BackgroundAction<RefPtr<Gfx::Bitmap>>::construct(
|
Threading::BackgroundAction<ErrorOr<NonnullRefPtr<Gfx::Bitmap>>>::construct(
|
||||||
[path](auto&) {
|
[path](auto&) -> ErrorOr<NonnullRefPtr<Gfx::Bitmap>> {
|
||||||
RefPtr<Gfx::Bitmap> bmp;
|
if (path.is_empty())
|
||||||
if (!path.is_empty())
|
return Error::from_errno(ENOENT);
|
||||||
bmp = Gfx::Bitmap::try_load_from_file(path).release_value_but_fixme_should_propagate_errors();
|
return Gfx::Bitmap::try_load_from_file(path);
|
||||||
return bmp;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
[this, path](RefPtr<Gfx::Bitmap> bitmap) {
|
[this, path](ErrorOr<NonnullRefPtr<Gfx::Bitmap>> bitmap_or_error) {
|
||||||
// If we've been requested to change while we were loading the bitmap, don't bother spending the cost to
|
// If we've been requested to change while we were loading the bitmap, don't bother spending the cost to
|
||||||
// move and render the now stale bitmap.
|
// move and render the now stale bitmap.
|
||||||
if (is_different_to_current_wallpaper_path(path))
|
if (is_different_to_current_wallpaper_path(path))
|
||||||
return;
|
return;
|
||||||
if (!bitmap.is_null())
|
if (bitmap_or_error.is_error())
|
||||||
m_wallpaper_bitmap = move(bitmap);
|
|
||||||
else
|
|
||||||
m_wallpaper_bitmap = nullptr;
|
m_wallpaper_bitmap = nullptr;
|
||||||
|
else
|
||||||
|
m_wallpaper_bitmap = bitmap_or_error.release_value();
|
||||||
m_desktop_dirty = true;
|
m_desktop_dirty = true;
|
||||||
update();
|
update();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue