ENH check for udisks before enabling epic super mario sounds

This commit is contained in:
Nathan Dwarshuis 2021-06-22 00:14:21 -04:00
parent 93215d199d
commit 7981533664
1 changed files with 17 additions and 9 deletions

View File

@ -1,5 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- | Module for monitoring removable drive events -- | Module for monitoring removable drive events
-- --
@ -11,24 +9,28 @@ module XMonad.Internal.Concurrent.Removable (runRemovableMon) where
import Control.Concurrent import Control.Concurrent
import Control.Monad import Control.Monad
import Data.Map.Lazy (Map, member) import Data.Map.Lazy (Map, member)
import DBus import DBus
import DBus.Client import DBus.Client
import XMonad.Internal.DBus.Control (pathExists)
import XMonad.Internal.Shell import XMonad.Internal.Shell
bus :: BusName
bus = busName_ "org.freedesktop.UDisks2"
path :: ObjectPath path :: ObjectPath
path = "/org/freedesktop/UDisks2" path = objectPath_ "/org/freedesktop/UDisks2"
interface :: InterfaceName interface :: InterfaceName
interface = "org.freedesktop.DBus.ObjectManager" interface = interfaceName_ "org.freedesktop.DBus.ObjectManager"
memAdded :: MemberName memAdded :: MemberName
memAdded = "InterfacesAdded" memAdded = memberName_ "InterfacesAdded"
memRemoved :: MemberName memRemoved :: MemberName
memRemoved = "InterfacesRemoved" memRemoved = memberName_ "InterfacesRemoved"
driveInsertedSound :: FilePath driveInsertedSound :: FilePath
driveInsertedSound = "smb_powerup.wav" driveInsertedSound = "smb_powerup.wav"
@ -62,8 +64,8 @@ playSoundMaybe p b = when b $ playSound p
-- If it not already, we won't see any signals from the dbus until it is -- If it not already, we won't see any signals from the dbus until it is
-- started (it will work after it is started however). It seems safe to simply -- started (it will work after it is started however). It seems safe to simply
-- enable the udisks2 service at boot; however this is not default behavior. -- enable the udisks2 service at boot; however this is not default behavior.
runRemovableMon :: IO () listenDevices :: IO ()
runRemovableMon = do listenDevices = do
client <- connectSystem client <- connectSystem
_ <- addMatch' client memAdded driveInsertedSound addedHasDrive _ <- addMatch' client memAdded driveInsertedSound addedHasDrive
_ <- addMatch' client memRemoved driveRemovedSound removedHasDrive _ <- addMatch' client memRemoved driveRemovedSound removedHasDrive
@ -71,3 +73,9 @@ runRemovableMon = do
where where
addMatch' client m p f = addMatch client ruleUdisks { matchMember = Just m } addMatch' client m p f = addMatch client ruleUdisks { matchMember = Just m }
$ playSoundMaybe p . f . signalBody $ playSoundMaybe p . f . signalBody
runRemovableMon :: IO ()
runRemovableMon = do
e <- pathExists True bus path
if e then listenDevices else
putStrLn "WARNING: udisks not running. Super Mario disk sounds disabled."