diff --git a/home/taskwarrior.nix b/home/taskwarrior.nix index 631674b0..ef7f76a1 100644 --- a/home/taskwarrior.nix +++ b/home/taskwarrior.nix @@ -36,6 +36,7 @@ ]; imports = [ "DBus.Notify" + "DBus.Client (clientErrorMessage)" "System.IO" "Data.Aeson" "Control.Monad" @@ -64,8 +65,11 @@ String description <- HM.lookup "description" task2 pure (description, printMap diff) Control.Monad.forM_ description $ \(d,b) -> do - client <- connectSession - notify client blankNote { summary = [i|Modified task #{d}|], body = Just $ Text b, expiry = Milliseconds 15000 } + client <- try connectSession + either + (BS.hPut stderr . encodeUtf8 . clientErrorMessage) + (\c -> void $ notify c blankNote { summary = [i|Modified task #{d}|], body = Just $ Text b, expiry = Milliseconds 15000 }) + client BS.hPut stdout input2 ''; on-add = writeHaskellScript { @@ -78,9 +82,12 @@ let description = do Object task <- decode $ toLazy input :: Maybe Value pure . printMap . fmap That $ task - Control.Monad.forM_ description $ \d -> do - client <- connectSession - notify client blankNote { summary = "New Task", body = Just $ Text d, expiry = Milliseconds 15000 } + whenJust description $ \d -> do + client <- try connectSession + either + (BS.hPut stderr . encodeUtf8 . clientErrorMessage) + (\c -> void $ notify c blankNote { summary = "New Task", body = Just $ Text d, expiry = Milliseconds 15000 }) + client BS.hPut stdout input ''; in { @@ -92,6 +99,22 @@ target = ".task/hooks/on-modify.notification"; source = "${on-modify}/bin/on-modify"; }; + "add-kassandra-notification" = { + target = ".task/hooks/on-add.kassandra-notification"; + executable = true; + text = '' + #!${pkgs.bash}/bin/bash + tee >(nc 127.0.0.1 6545) + ''; + }; + "modify-kassandra-notification" = { + target = ".task/hooks/on-modify.kassandra-notification"; + executable = true; + text = '' + #!${pkgs.bash}/bin/bash + tail -n 1 | tee >(nc 127.0.0.1 6545) + ''; + }; }; programs.taskwarrior = let cfg = config.m-0.private.taskwarrior; in { diff --git a/lib/default.nix b/lib/default.nix index af190edf..0da8378a 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -67,7 +67,7 @@ rec { import qualified Data.ByteString as BS import qualified Data.Text as Text import System.Environment (getArgs) - import Control.Exception (bracket) + import Control.Exception (bracket, try) import Data.String.Interpolate (i) ${builtins.concatStringsSep "\n" (map (x: "import ${x}") imports)}