Skip to content
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
8 changes: 6 additions & 2 deletions src/Client/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module Client.Configuration
, configJumpModifier
, configDigraphs
, configNotifications
, configNotifyWhile

, configNetworkPalette
, extensionPath
Expand Down Expand Up @@ -76,7 +77,7 @@ import Client.Commands.Interpolation (Macro)
import Client.Commands.Recognizer (Recognizer)
import Client.Configuration.Colors (attrSpec)
import Client.Configuration.Macros (macroMapSpec)
import Client.Configuration.Notifications (NotifyWith, notifySpec, notifyWithDefault)
import Client.Configuration.Notifications (NotifyWith, NotifyWhile(NotifyWhileUnfocused), notifySpec, notifyWithDefault, notifyWhileSpec)
import Client.Configuration.ServerSettings
import Client.EventLoop.Actions
import Client.Image.Palette
Expand Down Expand Up @@ -128,6 +129,7 @@ data Configuration = Configuration
, _configJumpModifier :: [Modifier] -- ^ Modifier used for jumping windows
, _configDigraphs :: Map Digraph Text -- ^ Extra digraphs
, _configNotifications :: NotifyWith
, _configNotifyWhile :: NotifyWhile
}
deriving Show

Expand Down Expand Up @@ -298,7 +300,9 @@ configurationSpec = sectionsSpec "config-file" $
_configDigraphs <- sec' mempty "extra-digraphs" (Map.fromList <$> listSpec digraphSpec)
"Extra digraphs"
_configNotifications <- sec' notifyWithDefault "notifications" notifySpec
"Whether and how to show desktop notifications"
"Whether and how to show notifications. Notification data is passed as arguments to custom commands."
_configNotifyWhile <- sec' NotifyWhileUnfocused "notify-while" notifyWhileSpec
"When notifications (if enabled) may be displayed"
return (\def ->
let _configDefaults = snd ssDefUpdate def
_configServers = buildServerMap _configDefaults ssUpdates
Expand Down
14 changes: 13 additions & 1 deletion src/Client/Configuration/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Copyright : (c) TheDaemoness, 2023
License : ISC
Maintainer : emertens@gmail.com
-}
module Client.Configuration.Notifications ( NotifyWith(..), notifyCmd, notifySpec, notifyWithDefault ) where
module Client.Configuration.Notifications ( NotifyWith(..), NotifyWhile(..), notifyCmd, notifySpec, notifyWithDefault, notifyWhileSpec ) where

import Config.Schema (ValueSpec, atomSpec, nonemptySpec, stringSpec, (<!>))
import qualified Data.Text.Lazy as LText
Expand All @@ -21,6 +21,12 @@ data NotifyWith
| NotifyWithTerminalNotifier
deriving Show

data NotifyWhile
= NotifyWhileUnfocused
| NotifyWhileFocused
| NotifyWhileAlways
deriving Show

notifyCmd :: NotifyWith -> Maybe ((LText.Text, LText.Text) -> ProcessConfig () () ())
notifyCmd (NotifyWithCustom (cmd:args)) = Just $ \(header, body) ->
proc cmd (args ++ [LText.unpack header, LText.unpack body])
Expand Down Expand Up @@ -49,3 +55,9 @@ notifySpec =
NotifyWithOsaScript <$ atomSpec "osascript" <!>
NotifyWithTerminalNotifier <$ atomSpec "terminal-notifier" <!>
NotifyWithCustom . NonEmpty.toList <$> nonemptySpec stringSpec

notifyWhileSpec :: ValueSpec NotifyWhile
notifyWhileSpec =
NotifyWhileUnfocused <$ atomSpec "unfocused" <!>
NotifyWhileFocused <$ atomSpec "focused" <!>
NotifyWhileAlways <$ atomSpec "always"
2 changes: 1 addition & 1 deletion src/Client/EventLoop.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ processLogEntries =
processNotifications :: ClientState -> IO ()
processNotifications st =
case notifyCmd (view (clientConfig . configNotifications) st) of
Just cmd | not (view clientUiFocused st) -> traverse_ (spawn cmd) (view clientNotifications st)
Just cmd | clientMayNotify st -> traverse_ (spawn cmd) (view clientNotifications st)
_ -> return ()
where
-- TODO: May be a nicer way to handle notification failure than just silently squashing the exception
Expand Down
9 changes: 9 additions & 0 deletions src/Client/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module Client.State
, buildMatcher
, clientToggleHideMeta
, channelUserList
, clientMayNotify

, consumeInput
, currentCompletionList
Expand Down Expand Up @@ -115,6 +116,7 @@ module Client.State
import Client.CApi
import Client.Commands.WordCompletion
import Client.Configuration
import Client.Configuration.Notifications (NotifyWhile(..))
import Client.Configuration.ServerSettings
import Client.Configuration.Sts
import Client.Image.Message
Expand Down Expand Up @@ -672,6 +674,13 @@ addNotify True focus wl st
focusText (NetworkFocus net) = LText.fromChunks ["Notice from ", net]
focusText (ChannelFocus net chan) = LText.fromChunks ["Activity on ", net, ":", idText chan]

clientMayNotify :: ClientState -> Bool
clientMayNotify st = case view (clientConfig . configNotifyWhile) st of
NotifyWhileUnfocused -> not $ _clientUiFocused st
NotifyWhileFocused -> _clientUiFocused st
NotifyWhileAlways -> True


toWindowLine :: MessageRendererParams -> WindowLineImportance -> ClientMessage -> WindowLine
toWindowLine params importance msg = WindowLine
{ _wlSummary = msgSummary (view msgBody msg)
Expand Down