From 03623ce6c011c1e85df7d91aed4458c098ff22ff Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 7 Feb 2019 22:05:33 +0100 Subject: Main.app: call graphicCapture directly --- src/Flameshot/Internal.hs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/Flameshot') diff --git a/src/Flameshot/Internal.hs b/src/Flameshot/Internal.hs index 28b33cf..56a35b4 100644 --- a/src/Flameshot/Internal.hs +++ b/src/Flameshot/Internal.hs @@ -9,11 +9,17 @@ import Blessings.Text import Control.Concurrent.Async (race) import Control.Concurrent.Extended import Control.Exception +import Data.ByteString (ByteString) +import qualified Data.ByteString as BS import qualified Data.Char as C import Data.Function (on) +import Data.Maybe (fromMaybe) +import Data.Time.Clock import Data.Time.Clock.System +import Data.Time.Format import Data.Time.ISO8601 import DBus +import DBus.Internal.Message import DBus.Socket import Data.Text (Text) import qualified Data.Text.Extended as T @@ -25,6 +31,14 @@ blessBusName = Plain . T.pack . formatBusName blessMemberName :: MemberName -> Blessings Text blessMemberName = Plain . T.pack . formatMemberName +blessMethodError :: MethodError -> Blessings Text +blessMethodError err@MethodError{..} = + red . Plain $ fromMaybe (T.show err) msg + where + msg = if length methodErrorBody > 0 + then fromVariant (methodErrorBody !! 0) + else Nothing + blessShow :: Show a => a -> Blessings Text blessShow = Plain . T.show @@ -94,3 +108,16 @@ showUnprintable = toEither p = map (\s -> if p (T.head s) then Right s else Left s) . T.groupBy ((==) `on` p) + + +saveImage :: FilePath -> ByteString -> IO () +saveImage cGuiPath rawImage = do + t <- formatISO8601Seconds . systemToUTCTime <$> getSystemTime + let path = cGuiPath <> "/" <> baseName + baseName = t <> "_flameshot.png" + BS.writeFile path rawImage + + +formatISO8601Seconds :: UTCTime -> String +formatISO8601Seconds = + formatTime defaultTimeLocale (iso8601DateFormat $ Just "%H:%M:%SZ") -- cgit v1.2.3