desktop-portal 0.2.0.0 → 0.2.1.0
raw patch · 5 files changed
+264/−1 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Desktop.Portal: OpenDirectoryOptions :: Word32 -> Maybe Text -> Maybe Text -> OpenDirectoryOptions
+ Desktop.Portal: OpenURIOptions :: URI -> Maybe Text -> Maybe Bool -> Maybe Bool -> Maybe Text -> OpenURIOptions
+ Desktop.Portal: [$sel:activationToken:OpenDirectoryOptions] :: OpenDirectoryOptions -> Maybe Text
+ Desktop.Portal: [$sel:activationToken:OpenURIOptions] :: OpenURIOptions -> Maybe Text
+ Desktop.Portal: [$sel:ask:OpenURIOptions] :: OpenURIOptions -> Maybe Bool
+ Desktop.Portal: [$sel:fd:OpenDirectoryOptions] :: OpenDirectoryOptions -> Word32
+ Desktop.Portal: [$sel:parentWindow:OpenDirectoryOptions] :: OpenDirectoryOptions -> Maybe Text
+ Desktop.Portal: [$sel:parentWindow:OpenURIOptions] :: OpenURIOptions -> Maybe Text
+ Desktop.Portal: [$sel:uri:OpenURIOptions] :: OpenURIOptions -> URI
+ Desktop.Portal: [$sel:writable:OpenURIOptions] :: OpenURIOptions -> Maybe Bool
+ Desktop.Portal: data OpenDirectoryOptions
+ Desktop.Portal: data OpenURIOptions
+ Desktop.Portal: openDirectory :: Client -> OpenDirectoryOptions -> IO (Request ())
+ Desktop.Portal: openDirectoryOptions :: Word32 -> OpenDirectoryOptions
+ Desktop.Portal: openURI :: Client -> OpenURIOptions -> IO (Request ())
+ Desktop.Portal: openURIOptions :: URI -> OpenURIOptions
+ Desktop.Portal.OpenURI: OpenDirectoryOptions :: Word32 -> Maybe Text -> Maybe Text -> OpenDirectoryOptions
+ Desktop.Portal.OpenURI: OpenFileOptions :: Word32 -> Maybe Text -> Maybe Bool -> Maybe Bool -> Maybe Text -> OpenFileOptions
+ Desktop.Portal.OpenURI: OpenURIOptions :: URI -> Maybe Text -> Maybe Bool -> Maybe Bool -> Maybe Text -> OpenURIOptions
+ Desktop.Portal.OpenURI: [$sel:activationToken:OpenDirectoryOptions] :: OpenDirectoryOptions -> Maybe Text
+ Desktop.Portal.OpenURI: [$sel:activationToken:OpenFileOptions] :: OpenFileOptions -> Maybe Text
+ Desktop.Portal.OpenURI: [$sel:activationToken:OpenURIOptions] :: OpenURIOptions -> Maybe Text
+ Desktop.Portal.OpenURI: [$sel:ask:OpenFileOptions] :: OpenFileOptions -> Maybe Bool
+ Desktop.Portal.OpenURI: [$sel:ask:OpenURIOptions] :: OpenURIOptions -> Maybe Bool
+ Desktop.Portal.OpenURI: [$sel:fd:OpenDirectoryOptions] :: OpenDirectoryOptions -> Word32
+ Desktop.Portal.OpenURI: [$sel:fd:OpenFileOptions] :: OpenFileOptions -> Word32
+ Desktop.Portal.OpenURI: [$sel:parentWindow:OpenDirectoryOptions] :: OpenDirectoryOptions -> Maybe Text
+ Desktop.Portal.OpenURI: [$sel:parentWindow:OpenFileOptions] :: OpenFileOptions -> Maybe Text
+ Desktop.Portal.OpenURI: [$sel:parentWindow:OpenURIOptions] :: OpenURIOptions -> Maybe Text
+ Desktop.Portal.OpenURI: [$sel:uri:OpenURIOptions] :: OpenURIOptions -> URI
+ Desktop.Portal.OpenURI: [$sel:writable:OpenFileOptions] :: OpenFileOptions -> Maybe Bool
+ Desktop.Portal.OpenURI: [$sel:writable:OpenURIOptions] :: OpenURIOptions -> Maybe Bool
+ Desktop.Portal.OpenURI: data OpenDirectoryOptions
+ Desktop.Portal.OpenURI: data OpenFileOptions
+ Desktop.Portal.OpenURI: data OpenURIOptions
+ Desktop.Portal.OpenURI: instance GHC.Classes.Eq Desktop.Portal.OpenURI.OpenDirectoryOptions
+ Desktop.Portal.OpenURI: instance GHC.Classes.Eq Desktop.Portal.OpenURI.OpenFileOptions
+ Desktop.Portal.OpenURI: instance GHC.Classes.Eq Desktop.Portal.OpenURI.OpenURIOptions
+ Desktop.Portal.OpenURI: instance GHC.Show.Show Desktop.Portal.OpenURI.OpenDirectoryOptions
+ Desktop.Portal.OpenURI: instance GHC.Show.Show Desktop.Portal.OpenURI.OpenFileOptions
+ Desktop.Portal.OpenURI: instance GHC.Show.Show Desktop.Portal.OpenURI.OpenURIOptions
+ Desktop.Portal.OpenURI: openDirectory :: Client -> OpenDirectoryOptions -> IO (Request ())
+ Desktop.Portal.OpenURI: openDirectoryOptions :: Word32 -> OpenDirectoryOptions
+ Desktop.Portal.OpenURI: openFile :: Client -> OpenFileOptions -> IO (Request ())
+ Desktop.Portal.OpenURI: openFileOptions :: Word32 -> OpenFileOptions
+ Desktop.Portal.OpenURI: openURI :: Client -> OpenURIOptions -> IO (Request ())
+ Desktop.Portal.OpenURI: openURIOptions :: URI -> OpenURIOptions
Files
- ChangeLog.md +4/−0
- desktop-portal.cabal +3/−1
- src/Desktop/Portal.hs +2/−0
- src/Desktop/Portal/OpenURI.hs +131/−0
- test/Desktop/Portal/OpenURISpec.hs +124/−0
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.2.1.0+### Added+- Add OpenURI portal support.+ ## 0.2.0.0 ### Changed - Functions now return FilePath instead of Text, where the value is always a file URI.
desktop-portal.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: desktop-portal-version: 0.2.0.0+version: 0.2.1.0 license: MIT license-file: LICENSE maintainer: garethdanielsmith@gmail.com@@ -24,6 +24,7 @@ Desktop.Portal.Account Desktop.Portal.FileChooser Desktop.Portal.Notification+ Desktop.Portal.OpenURI Desktop.Portal.Settings hs-source-dirs: src@@ -63,6 +64,7 @@ Desktop.Portal.AccountSpec Desktop.Portal.FileChooserSpec Desktop.Portal.NotificationSpec+ Desktop.Portal.OpenURISpec Desktop.Portal.SettingsSpec Desktop.Portal.TestUtil Paths_desktop_portal
src/Desktop/Portal.hs view
@@ -22,6 +22,7 @@ module Desktop.Portal.Account, module Desktop.Portal.FileChooser, module Desktop.Portal.Notification,+ module Desktop.Portal.OpenURI, ) where @@ -29,3 +30,4 @@ import Desktop.Portal.FileChooser import Desktop.Portal.Internal qualified as Internal import Desktop.Portal.Notification+import Desktop.Portal.OpenURI hiding (OpenFileOptions (..), openFile, openFileOptions) -- avoid conflict with FileChooser.openFile
+ src/Desktop/Portal/OpenURI.hs view
@@ -0,0 +1,131 @@+module Desktop.Portal.OpenURI+ ( --- * Open URI+ OpenURIOptions (..),+ openURIOptions,+ openURI,++ -- * Open File+ OpenFileOptions (..),+ openFileOptions,+ openFile,++ -- * Open Directory+ OpenDirectoryOptions (..),+ openDirectoryOptions,+ openDirectory,+ )+where++import DBus (InterfaceName, IsVariant (toVariant))+import Data.Map.Strict qualified as Map+import Data.Maybe (catMaybes, fromMaybe)+import Data.Text (Text)+import Data.Word (Word32)+import Desktop.Portal.Internal (Client, Request, sendRequest)+import Desktop.Portal.Util (toVariantPair)+import Text.URI (URI)+import Text.URI qualified as URI++data OpenURIOptions = OpenURIOptions+ { uri :: URI,+ parentWindow :: Maybe Text,+ writable :: Maybe Bool,+ ask :: Maybe Bool,+ activationToken :: Maybe Text+ }+ deriving (Eq, Show)++data OpenFileOptions = OpenFileOptions+ { fd :: Word32,+ parentWindow :: Maybe Text,+ writable :: Maybe Bool,+ ask :: Maybe Bool,+ activationToken :: Maybe Text+ }+ deriving (Eq, Show)++data OpenDirectoryOptions = OpenDirectoryOptions+ { fd :: Word32,+ parentWindow :: Maybe Text,+ activationToken :: Maybe Text+ }+ deriving (Eq, Show)++openURIOptions ::+ -- | The URI to open.+ URI ->+ OpenURIOptions+openURIOptions uri =+ OpenURIOptions+ { uri,+ parentWindow = Nothing,+ writable = Nothing,+ ask = Nothing,+ activationToken = Nothing+ }++openFileOptions ::+ -- | The file descriptor to open.+ Word32 ->+ OpenFileOptions+openFileOptions fd =+ OpenFileOptions+ { fd,+ parentWindow = Nothing,+ writable = Nothing,+ ask = Nothing,+ activationToken = Nothing+ }++openDirectoryOptions ::+ -- | The file descriptor to open.+ Word32 ->+ OpenDirectoryOptions+openDirectoryOptions fd =+ OpenDirectoryOptions+ { fd,+ parentWindow = Nothing,+ activationToken = Nothing+ }++openURIInterface :: InterfaceName+openURIInterface = "org.freedesktop.portal.OpenURI"++openURI :: Client -> OpenURIOptions -> IO (Request ())+openURI client options =+ sendRequest client openURIInterface "OpenURI" args optionsArg parseUnitResponse+ where+ args = [DBus.toVariant parentWindow, DBus.toVariant (URI.render options.uri)]+ parentWindow = fromMaybe "" options.parentWindow+ optionsArg =+ Map.fromList . catMaybes $+ [ toVariantPair "writable" options.writable,+ toVariantPair "ask" options.ask,+ toVariantPair "activation_token" options.activationToken+ ]++openFile :: Client -> OpenFileOptions -> IO (Request ())+openFile client options =+ sendRequest client openURIInterface "OpenFile" args optionsArg parseUnitResponse+ where+ args = [DBus.toVariant parentWindow, DBus.toVariant options.fd]+ parentWindow = fromMaybe "" options.parentWindow+ optionsArg =+ Map.fromList . catMaybes $+ [ toVariantPair "writable" options.writable,+ toVariantPair "ask" options.ask,+ toVariantPair "activation_token" options.activationToken+ ]++openDirectory :: Client -> OpenDirectoryOptions -> IO (Request ())+openDirectory client options =+ sendRequest client openURIInterface "OpenDirectory" args optionsArg parseUnitResponse+ where+ args = [DBus.toVariant parentWindow, DBus.toVariant options.fd]+ parentWindow = fromMaybe "" options.parentWindow+ optionsArg =+ Map.fromList . catMaybes $+ [toVariantPair "activation_token" options.activationToken]++parseUnitResponse :: a -> IO ()+parseUnitResponse = const (pure ())
+ test/Desktop/Portal/OpenURISpec.hs view
@@ -0,0 +1,124 @@+{-# LANGUAGE QuasiQuotes #-}++module Desktop.Portal.OpenURISpec (spec) where++import Control.Monad (void)+import DBus (InterfaceName, IsVariant (toVariant))+import Data.Word (Word32)+import Desktop.Portal qualified as Portal+import Desktop.Portal.OpenURI (OpenDirectoryOptions (..), OpenFileOptions (..), OpenURIOptions (..))+import Desktop.Portal.OpenURI qualified as OpenURI+import Desktop.Portal.TestUtil+import Test.Hspec (Spec, around, describe, it, shouldBe, shouldReturn)+import Text.URI.QQ (uri)++openURIInterface :: InterfaceName+openURIInterface = "org.freedesktop.portal.OpenURI"++spec :: Spec+spec = do+ around withTestBus $ do+ describe "openURI" $ do+ it "should encode request with all Nothings" $ \handle -> do+ body <- savingRequestArguments handle openURIInterface "OpenURI" $ do+ void (Portal.openURI (client handle) (Portal.openURIOptions [uri|https://example.com|]))+ body+ `shouldBe` [ toVariantText "",+ toVariantText "https://example.com",+ toVariantMap []+ ]++ it "should encode request with all Justs" $ \handle -> do+ body <- savingRequestArguments handle openURIInterface "OpenURI" $ do+ void . Portal.openURI (client handle) $+ OpenURIOptions+ { uri = [uri|https://example.com|],+ parentWindow = Just "_window",+ writable = Just True,+ ask = Just True,+ activationToken = Just "_token"+ }+ body+ `shouldBe` [ toVariantText "_window",+ toVariantText "https://example.com",+ toVariantMap+ [ ("writable", toVariant True),+ ("ask", toVariant True),+ ("activation_token", toVariantText "_token")+ ]+ ]++ it "should decode response" $ \handle -> do+ withRequestResponse handle openURIInterface "OpenURI" (successResponse []) $ do+ (Portal.openURI (client handle) (Portal.openURIOptions [uri|https://example.com|]) >>= Portal.await)+ `shouldReturn` Just ()++ describe "openFile" $ do+ it "should encode request with all Nothings" $ \handle -> do+ body <- savingRequestArguments handle openURIInterface "OpenFile" $ do+ void (OpenURI.openFile (client handle) (OpenURI.openFileOptions 42))+ body+ `shouldBe` [ toVariantText "",+ toVariant (42 :: Word32),+ toVariantMap []+ ]+ it "should encode request with all Justs" $ \handle -> do+ body <- savingRequestArguments handle openURIInterface "OpenFile" $ do+ void+ ( OpenURI.openFile+ (client handle)+ ( OpenFileOptions+ { fd = 43,+ parentWindow = Just "_window",+ writable = Just True,+ ask = Just True,+ activationToken = Just "_token"+ }+ )+ )+ body+ `shouldBe` [ toVariantText "_window",+ toVariant (43 :: Word32),+ toVariantMap+ [ ("writable", toVariant True),+ ("ask", toVariant True),+ ("activation_token", toVariantText "_token")+ ]+ ]++ it "should decode response" $ \handle -> do+ withRequestResponse handle openURIInterface "OpenFile" (successResponse []) $ do+ (OpenURI.openFile (client handle) (OpenURI.openFileOptions 44) >>= Portal.await)+ `shouldReturn` Just ()++ describe "openDirectory" $ do+ it "should encode request with all Nothings" $ \handle -> do+ body <- savingRequestArguments handle openURIInterface "OpenDirectory" $ do+ void (Portal.openDirectory (client handle) (Portal.openDirectoryOptions 42))+ body+ `shouldBe` [ toVariantText "",+ toVariant (42 :: Word32),+ toVariantMap []+ ]+ it "should encode request with all Justs" $ \handle -> do+ body <- savingRequestArguments handle openURIInterface "OpenDirectory" $ do+ void+ ( Portal.openDirectory+ (client handle)+ ( OpenDirectoryOptions+ { fd = 43,+ parentWindow = Just "_window",+ activationToken = Just "_token"+ }+ )+ )+ body+ `shouldBe` [ toVariantText "_window",+ toVariant (43 :: Word32),+ toVariantMap [("activation_token", toVariantText "_token")]+ ]++ it "should decode response" $ \handle -> do+ withRequestResponse handle openURIInterface "OpenDirectory" (successResponse []) $ do+ (Portal.openDirectory (client handle) (Portal.openDirectoryOptions 44) >>= Portal.await)+ `shouldReturn` Just ()