Skip to content

Commit

Permalink
Remove applescript and notify-send effects
Browse files Browse the repository at this point in the history
To be clear, the applescript and notify-send notification functionality
still exists. We just remove the typeclasses, which were unnecessary.
  • Loading branch information
tbidne committed Nov 3, 2024
1 parent 89e521a commit 276ce3a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 75 deletions.
6 changes: 3 additions & 3 deletions shrun.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ library
Shrun.Logging.Types
Shrun.Logging.Types.Internal
Shrun.Notify
Shrun.Notify.MonadAppleScript
Shrun.Notify.MonadDBus
Shrun.Notify.AppleScript
Shrun.Notify.DBus
Shrun.Notify.MonadNotify
Shrun.Notify.MonadNotifySend
Shrun.Notify.NotifySend
Shrun.Prelude
Shrun.ShellT
Shrun.Utils
Expand Down
2 changes: 1 addition & 1 deletion src/Shrun/Configuration/Data/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Shrun.Configuration.Data.Notify qualified as Notify
import Shrun.Configuration.Data.WithDisabled ((<?>?))
import Shrun.Configuration.Default (Default (def))
import Shrun.Data.Command (CommandP1)
import Shrun.Notify.MonadDBus (MonadDBus)
import Shrun.Notify.DBus (MonadDBus)
import Shrun.Prelude

-- | For types that are only guaranteed to exist for Args. Generally this
Expand Down
2 changes: 1 addition & 1 deletion src/Shrun/Configuration/Data/Notify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import Shrun.Configuration.Data.WithDisabled
)
import Shrun.Configuration.Data.WithDisabled qualified as WD
import Shrun.Configuration.Default (Default, def)
import Shrun.Notify.MonadDBus (MonadDBus (connectSession))
import Shrun.Notify.DBus (MonadDBus (connectSession))
import Shrun.Prelude

-- See NOTE: [Args vs. Toml mandatory fields]
Expand Down
6 changes: 1 addition & 5 deletions src/Shrun/Configuration/Env.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ import Shrun.Configuration.Env.Types
HasConsoleLogging,
)
import Shrun.Logging.MonadRegionLogger (MonadRegionLogger (Region))
import Shrun.Notify.MonadAppleScript (MonadAppleScript)
import Shrun.Notify.MonadDBus (MonadDBus)
import Shrun.Notify.MonadNotifySend (MonadNotifySend)
import Shrun.Notify.DBus (MonadDBus)
import Shrun.Prelude
import Shrun.ShellT (ShellT)

Expand All @@ -48,15 +46,13 @@ makeEnvAndShrun ::
forall m r.
( HasCallStack,
HasConsoleLogging (Env r) (Region (ShellT (Env r) m)),
MonadAppleScript m,
MonadAsync m,
MonadDBus m,
MonadFileReader m,
MonadFileWriter m,
MonadHandleReader m,
MonadHandleWriter m,
MonadIORef m,
MonadNotifySend m,
MonadOptparse m,
MonadPathReader m,
MonadPathWriter m,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-- | Effect for AppleScript.
module Shrun.Notify.MonadAppleScript
( MonadAppleScript (..),
notifyAppleScript,
module Shrun.Notify.AppleScript
( notifyAppleScript,
)
where

Expand All @@ -15,32 +14,22 @@ import Shrun.Notify.MonadNotify
)
import Shrun.Prelude

-- | Effect for apple script.
class (Monad m) => MonadAppleScript m where
-- | Sends a notification via apple script.
notify :: (HasCallStack) => Text -> m (Maybe ByteString)

instance MonadAppleScript IO where
notify =
fmap exitFailureToStderr
. P.readProcessStderr
. P.shell
. T.unpack
{-# INLINEABLE notify #-}

instance (MonadAppleScript m) => MonadAppleScript (ReaderT env m) where
notify = lift . notify
{-# INLINEABLE notify #-}

notifyAppleScript ::
( HasCallStack,
MonadAppleScript m
MonadTypedProcess m
) =>
ShrunNote ->
m (Maybe NotifyException)
notifyAppleScript note =
notify (shrunToAppleScript note) <<&>> \stderr ->
MkNotifyException note AppleScript (decodeUtf8Lenient stderr)
where
notify :: (HasCallStack, MonadTypedProcess m) => Text -> m (Maybe ByteString)
notify =
fmap exitFailureToStderr
. P.readProcessStderr
. P.shell
. T.unpack
{-# INLINEABLE notifyAppleScript #-}

shrunToAppleScript :: ShrunNote -> Text
Expand Down
2 changes: 1 addition & 1 deletion src/Shrun/Notify/MonadDBus.hs → src/Shrun/Notify/DBus.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- | Effect for DBus.
module Shrun.Notify.MonadDBus
module Shrun.Notify.DBus
( MonadDBus (..),
notifyDBus,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-- | Effect for NotifySend.
module Shrun.Notify.MonadNotifySend
( MonadNotifySend (..),
notifyNotifySend,
module Shrun.Notify.NotifySend
( notifyNotifySend,
)
where

Expand All @@ -23,32 +22,22 @@ import Shrun.Notify.MonadNotify
import Shrun.Prelude
import Shrun.Utils qualified as Utils

-- | Effect for notify-send.
class (Monad m) => MonadNotifySend m where
-- | Sends a notification via notify-send.
notify :: (HasCallStack) => Text -> m (Maybe ByteString)

instance MonadNotifySend IO where
notify =
fmap exitFailureToStderr
. P.readProcessStderr
. P.shell
. T.unpack
{-# INLINEABLE notify #-}

instance (MonadNotifySend m) => MonadNotifySend (ReaderT env m) where
notify = lift . notify
{-# INLINEABLE notify #-}

notifyNotifySend ::
( HasCallStack,
MonadNotifySend m
MonadTypedProcess m
) =>
ShrunNote ->
m (Maybe NotifyException)
notifyNotifySend note =
notify (shrunToNotifySend note) <<&>> \stderr ->
MkNotifyException note NotifySend (decodeUtf8Lenient stderr)
where
notify :: (HasCallStack, MonadTypedProcess m) => Text -> m (Maybe ByteString)
notify =
fmap exitFailureToStderr
. P.readProcessStderr
. P.shell
. T.unpack
{-# INLINEABLE notifyNotifySend #-}

shrunToNotifySend :: ShrunNote -> Text
Expand Down
23 changes: 9 additions & 14 deletions src/Shrun/ShellT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import Shrun.Configuration.Data.Notify.System
)
import Shrun.Configuration.Env.Types (Env)
import Shrun.Logging.MonadRegionLogger (MonadRegionLogger)
import Shrun.Notify.MonadAppleScript (MonadAppleScript)
import Shrun.Notify.MonadAppleScript qualified as MonadAppleScript
import Shrun.Notify.MonadDBus (MonadDBus)
import Shrun.Notify.MonadDBus qualified as MonadDBus
import Shrun.Notify.AppleScript qualified as AppleScript
import Shrun.Notify.DBus (MonadDBus)
import Shrun.Notify.DBus qualified as DBus
import Shrun.Notify.MonadNotify (MonadNotify (notify))
import Shrun.Notify.MonadNotifySend (MonadNotifySend)
import Shrun.Notify.MonadNotifySend qualified as MonadNotifySend
import Shrun.Notify.NotifySend qualified as NotifySend
import Shrun.Prelude

-- | `ShellT` is the main application type that runs shell commands.
Expand All @@ -28,7 +26,6 @@ newtype ShellT env m a = MkShellT (ReaderT env m a)
( Functor,
Applicative,
Monad,
MonadAppleScript,
MonadAsync,
MonadDBus,
MonadCatch,
Expand All @@ -39,7 +36,6 @@ newtype ShellT env m a = MkShellT (ReaderT env m a)
MonadIO,
MonadIORef,
MonadMask,
MonadNotifySend,
MonadPathWriter,
MonadTypedProcess,
MonadReader env,
Expand All @@ -64,9 +60,8 @@ runShellT (MkShellT rdr) = runReaderT rdr
deriving newtype instance (MonadRegionLogger m) => MonadRegionLogger (ShellT (Env r) m)

instance
( MonadAppleScript m,
MonadDBus m,
MonadNotifySend m
( MonadDBus m,
MonadTypedProcess m
) =>
MonadNotify (ShellT (Env r) m)
where
Expand All @@ -75,7 +70,7 @@ instance
Nothing -> pure Nothing
Just nenv -> sendNote nenv
where
sendNote (DBus client) = MonadDBus.notifyDBus client note
sendNote NotifySend = MonadNotifySend.notifyNotifySend note
sendNote AppleScript = MonadAppleScript.notifyAppleScript note
sendNote (DBus client) = DBus.notifyDBus client note
sendNote NotifySend = NotifySend.notifyNotifySend note
sendNote AppleScript = AppleScript.notifyAppleScript note
{-# INLINEABLE notify #-}
10 changes: 2 additions & 8 deletions test/integration/Integration/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ import Shrun.Configuration.Data.MergedConfig (MergedConfig, defaultMergedConfig)
import Shrun.Configuration.Data.Notify.System (NotifySystemMerged)
import Shrun.Configuration.Data.Notify.System qualified as Notify.System
import Shrun.Configuration.Env qualified as Env
import Shrun.Notify.MonadDBus (MonadDBus (connectSession, notify))
import Shrun.Notify.MonadNotifySend (MonadNotifySend (notify))
import Shrun.Notify.DBus (MonadDBus (connectSession, notify))

-- IO that has a default config file specified at test/unit/Unit/toml/config.toml
newtype ConfigIO a = MkConfigIO (ReaderT (IORef [Text]) IO a)
Expand Down Expand Up @@ -120,9 +119,6 @@ instance MonadDBus ConfigIO where
}
notify = error "notify: unimplemented"

instance MonadNotifySend ConfigIO where
notify = error "notify: unimplemented"

-- IO with no default config file
newtype NoConfigIO a = MkNoConfigIO (ReaderT (IORef [Text]) IO a)
deriving
Expand All @@ -142,9 +138,7 @@ newtype NoConfigIO a = MkNoConfigIO (ReaderT (IORef [Text]) IO a)
MonadThrow
)
via (ReaderT (IORef [Text])) IO
deriving
(MonadDBus, MonadNotifySend)
via ConfigIO
deriving (MonadDBus) via ConfigIO

runNoConfigIO :: NoConfigIO a -> IORef [Text] -> IO a
runNoConfigIO (MkNoConfigIO rdr) = runReaderT rdr
Expand Down

0 comments on commit 276ce3a

Please sign in to comment.