From 209816bcb2d2e84dd29cf5baf08f4ba708d483aa Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 4 Apr 2015 22:00:51 +0900 Subject: posix notifications library complete --- src/Utility/Notify/Posix.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Utility/Notify/Posix.hs b/src/Utility/Notify/Posix.hs index 16b42ed..b802356 100644 --- a/src/Utility/Notify/Posix.hs +++ b/src/Utility/Notify/Posix.hs @@ -44,11 +44,11 @@ import Data.List.Split (splitOn) import Types.Reminder sendNotifications :: [Reminder] -> IO () -sendNotifications rems = do - maybeClient <- getDBusUserAddress - let client = undefined - - mapM_ (sendNotification client) rems +sendNotifications rems = + getDBusUserAddress >>= + maybe (return ()) (\address -> do + client <- connect address + mapM_ (sendNotification client) rems) sendNotification :: Client -> Reminder -> IO Notification sendNotification c rem = do @@ -70,8 +70,11 @@ getDBusUserAddress = do -- socketFile <- return realContents -- >>= mapM (return . ((dir ++ "/") ++)) -- >>= newestFile - addr <- readFile socketFile + addr <- dropWhile (/= 'u') . head . filter findSocketLine . lines + <$> readFile socketFile return (return addr >>= parseAddress) + where + findSocketLine line = takeWhile (/= '=') line == "DBUS_SESSION_BUS_ADDRESS" -- | Return the full path to the newest file in a directory, or the -- empty string if passed a file or empty directory or a path that -- cgit v1.2.3