From 6f2fbd8ce9393f4f2d0976b6a6f28ad44858ec90 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Fri, 25 Oct 2024 05:26:51 -0700 Subject: [PATCH] Improve openFileExplorerFolderPortable on windows --- .../Sandwich/Formatters/TerminalUI/CrossPlatform.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sandwich/src/Test/Sandwich/Formatters/TerminalUI/CrossPlatform.hs b/sandwich/src/Test/Sandwich/Formatters/TerminalUI/CrossPlatform.hs index 58465168..5ddb05d7 100644 --- a/sandwich/src/Test/Sandwich/Formatters/TerminalUI/CrossPlatform.hs +++ b/sandwich/src/Test/Sandwich/Formatters/TerminalUI/CrossPlatform.hs @@ -1,13 +1,23 @@ --- | +{-# LANGUAGE CPP #-} +{-# LANGUAGE QuasiQuotes #-} module Test.Sandwich.Formatters.TerminalUI.CrossPlatform ( openFileExplorerFolderPortable ) where import Control.Monad +import System.Directory import System.Process + -- | TODO: report exceptions here openFileExplorerFolderPortable :: String -> IO () +#ifdef mingw32_HOST_OS openFileExplorerFolderPortable folder = do + findExecutable "explorer.exe" >>= \case + Just p -> void $ readCreateProcessWithExitCode (proc p [folder]) "" + Nothing -> return () +#else +openFileExplorerFolderPortable folder = void $ readCreateProcessWithExitCode (proc "xdg-open" [folder]) "" +#endif