summaryrefslogtreecommitdiffstats
path: root/src/Flameshot/Internal.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Flameshot/Internal.hs')
-rw-r--r--src/Flameshot/Internal.hs27
1 files changed, 27 insertions, 0 deletions
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")