diff options
author | tv <tv@krebsco.de> | 2020-05-01 10:53:58 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2020-05-01 10:56:18 +0200 |
commit | ad60783034d4e3f5433d4412af03d626e356d117 (patch) | |
tree | d7de1e9220b48576c3d826baae57df180a102987 | |
parent | 63a96ce79d029bfba36660d7e258769f7d74a9ef (diff) |
Main.app: support upload to Imgur
-rw-r--r-- | shell.nix | 1 | ||||
-rw-r--r-- | src/main.hs | 15 |
2 files changed, 16 insertions, 0 deletions
@@ -17,6 +17,7 @@ in buildInputs = [ pkgs.flameshot + pkgs.xwaitforwindow ]; shellHook = '' diff --git a/src/main.hs b/src/main.hs index a08228b..5932976 100644 --- a/src/main.hs +++ b/src/main.hs @@ -10,6 +10,7 @@ import Control.Concurrent.Extended import Control.Exception import Control.Monad import Data.Int (Int32) +import qualified Data.Text as T import qualified Data.Text.IO as T import Data.Maybe (fromMaybe) import Data.Word (Word32) @@ -118,6 +119,16 @@ app client = do } runLogPrinter = forever $ takeLog >>= T.hPutStrLn stderr . pp + runWindowWaiter name onQuit = do + P.run "xwaitforwindow" ["-name", name] Nothing Nothing "" Nothing $ + logger putLog ("xwaitforwindow(name=" <> T.pack (show name) <> ")") <> + mempty + { P.onError = \_ _ -> onQuit + , P.onExit = \_ _ -> onQuit + } + waitForWindow name = do + (waiterStop, awaitWaiterStop) <- newSemaphore + withThread_ (runWindowWaiter name waiterStop) awaitWaiterStop let withTimeout time f s v io = @@ -149,6 +160,10 @@ app client = do Left err -> putLog $ "capture failed: " <> blessMethodError err + -- sleep in order give the upload window a chance to appear + threadDelay cTimeout + waitForWindow "Upload to Imgur" + killThread daemonThread withTimeout_ cTimeout awaitDaemonPart "daemon" "part" (return ()) |