Skip to content

Commit

Permalink
Fixes crashes on non-existing image
Browse files Browse the repository at this point in the history
  • Loading branch information
phuhl committed Feb 28, 2020
1 parent 99e3729 commit 86936cb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/NotificationCenter/Notifications/AbstractNotification.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ import GI.Gtk (widgetShowAll, widgetHide, windowMove, widgetDestroy
, labelSetXalign, widgetGetPreferredHeightForWidth
, onWidgetButtonPressEvent, imageSetFromPixbuf
, imageSetFromIconName, setWidgetWidthRequest
, setImagePixelSize, widgetSetMarginStart, widgetSetMarginEnd)
, setImagePixelSize, widgetSetMarginStart, widgetSetMarginEnd
, catchGErrorJustDomain, GErrorMessage(..))
import GI.GLib (FileError(..))
import GI.GdkPixbuf (pixbufScaleSimple, pixbufGetHeight, pixbufGetWidth
, Pixbuf(..), pixbufNewFromFileAtScale
, InterpType(..))
, InterpType(..), PixbufError(..))
import qualified GI.Gtk as Gtk
(IsWidget, Box(..), Label(..), Button(..), Window(..), Image(..)
, Builder(..), containerAdd, containerRemove, containerGetChildren)
Expand Down Expand Up @@ -138,8 +140,16 @@ setImage image imageSize widget = do
widgetSetMarginStart widget 0
widgetSetMarginEnd widget 0
(ImagePath path) -> do
pb <- pixbufNewFromFileAtScale path imageSize imageSize True
imageSetFromPixbuf widget (Just pb)
pb <- catchGErrorJustDomain
(catchGErrorJustDomain
(Just <$> pixbufNewFromFileAtScale path imageSize imageSize True)
((\err message -> return Nothing)
:: PixbufError -> GErrorMessage -> IO (Maybe Pixbuf)))
((\err message -> return Nothing)
:: FileError -> GErrorMessage -> IO (Maybe Pixbuf))
case pb of
(Just pb') -> imageSetFromPixbuf widget (Just pb')
Nothing -> return ()
(NamedIcon name) -> do
imageSetFromIconName widget
(Just $ pack name) imageSize
Expand Down

0 comments on commit 86936cb

Please sign in to comment.