Skip to content

Make the app work even if it fails to load the logo (fixes #95) #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GUI/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ initApp = do
menuBar <- Gtk.menuBarNew
OSX.applicationSetMenuBar app menuBar
logo <- $loadLogo
OSX.applicationSetDockIconPixbuf app (Just logo)
OSX.applicationSetDockIconPixbuf app logo
OSX.applicationReady app

#else
Expand Down
12 changes: 10 additions & 2 deletions GUI/DataFiles.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module GUI.DataFiles
( ui
, loadLogo
) where
import Control.Exception (IOException, Handler(..), catches)
import System.IO

import Data.FileEmbed
import Graphics.UI.Gtk (Pixbuf, pixbufNewFromFile)
import Language.Haskell.TH
import System.Glib (GError)
import System.IO.Temp
import qualified Data.ByteString as B
import qualified Data.Text.Encoding as TE
Expand All @@ -22,12 +25,17 @@ logoFile = "threadscope.png"
ui :: Q Exp
ui = [| TE.decodeUtf8 $(makeRelativeToProject uiFile >>= embedFile) |]

renderLogo :: B.ByteString -> IO Pixbuf
renderLogo :: B.ByteString -> IO (Maybe Pixbuf)
renderLogo bytes =
withSystemTempFile logoFile $ \path h -> do
B.hPut h bytes
hClose h
pixbufNewFromFile path
Just <$> pixbufNewFromFile path
`catches`
-- in case of a failure in the file IO or pixbufNewFromFile, return Nothing
[ Handler $ \(_ :: IOException) -> return Nothing
, Handler $ \(_ :: GError) -> return Nothing
]

-- | Load the logo file as a 'Pixbuf'.
loadLogo :: Q Exp
Expand Down
2 changes: 1 addition & 1 deletion GUI/Dialogs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ aboutDialog parent
"Mikolaj Konarski <[email protected]>",
"Nicolas Wu <[email protected]>",
"Eric Kow <[email protected]>"],
aboutDialogLogo := Just logo,
aboutDialogLogo := logo,
aboutDialogWebsite := "http://www.haskell.org/haskellwiki/ThreadScope",
windowTransientFor := toWindow parent
]
Expand Down
2 changes: 1 addition & 1 deletion GUI/MainWindow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mainWindowNew builder actions = do
------------------------------------------------------------------------

logo <- $loadLogo
set mainWindow [ windowIcon := Just logo ]
set mainWindow [ windowIcon := logo ]

------------------------------------------------------------------------
-- Status bar functionality
Expand Down