summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--shell.nix1
-rw-r--r--src/main.hs15
2 files changed, 16 insertions, 0 deletions
diff --git a/shell.nix b/shell.nix
index d2e8d51..33fa1ec 100644
--- a/shell.nix
+++ b/shell.nix
@@ -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 ())