From c42e88217a040080be8152bf419172b4642e4744 Mon Sep 17 00:00:00 2001 From: Corey Halpin Date: Wed, 22 Mar 2023 13:02:08 -0500 Subject: Handle SocketError when attempting to connect to dbus Extends the solution from 8a53271cd6 to also handle SocketError, so that the process will not terminate. See also issue #537. --- src/Xmobar/System/DBus.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Xmobar/System/DBus.hs b/src/Xmobar/System/DBus.hs index 103a5a9..90bee2a 100644 --- a/src/Xmobar/System/DBus.hs +++ b/src/Xmobar/System/DBus.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE ScopedTypeVariables #-} ----------------------------------------------------------------------------- -- | -- Module : DBus @@ -17,9 +18,10 @@ module Xmobar.System.DBus (runIPC) where import DBus import DBus.Client hiding (interfaceName) import qualified DBus.Client as DC +import DBus.Socket import Data.Maybe (isNothing) import Control.Concurrent.STM -import Control.Exception (handle) +import Control.Exception import System.IO (stderr, hPutStrLn) import Control.Monad.IO.Class (liftIO) @@ -35,10 +37,10 @@ interfaceName :: InterfaceName interfaceName = interfaceName_ "org.Xmobar.Control" runIPC :: TMVar SignalType -> IO () -runIPC mvst = handle printException exportConnection +runIPC mvst = exportConnection `catches` [ + Handler(\ (ex :: ClientError) -> hPutStrLn stderr (clientErrorMessage ex)), + Handler(\ (ex :: SocketError) -> hPutStrLn stderr (socketErrorMessage ex))] where - printException :: ClientError -> IO () - printException = hPutStrLn stderr . clientErrorMessage exportConnection = do client <- connectSession requestName client busName [ nameDoNotQueue ] -- cgit v1.2.3