Skip to content

Commit

Permalink
Merge pull request #32 from n-st/nonblocking-viewer
Browse files Browse the repository at this point in the history
Launch viewer in background and discard output
  • Loading branch information
2mol authored Oct 25, 2019
2 parents 28caa73 + efa34ed commit cdb0424
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import qualified Path
import qualified Path.IO as Path
import qualified System.FilePath as F
import qualified System.Process as P
import qualified GHC.IO.Handle.Types as IOHT
import System.Directory (findExecutable)
import qualified Text.PDF.Info as PDFI

data FileInfo = FileInfo
Expand Down Expand Up @@ -175,15 +177,21 @@ fileFile conf newFileName file = do

openFile :: Path Abs File -> IO ()
openFile file = do
linuxOpen <- tryOpenWith file "xdg-open"
tryViewers ["xdg-open", "open"] file

if Either.isLeft linuxOpen
then do
_ <- tryOpenWith file "open"
pure ()
else pure ()

tryViewers :: [[Char]] -> Path Abs File -> IO ()
tryViewers [] file = do return ()
tryViewers (e:es) file = do
v <- findExecutable e
if Maybe.isNothing v
then tryViewers es file
else do
tryOpenWith file e
return ()

tryOpenWith :: Path Abs File -> FilePath -> IO (Either SomeException String)
tryOpenWith file cmd =
E.try (P.readProcess cmd [Path.fromAbsFile file] "")

tryOpenWith :: Path Abs File -> FilePath -> IO ()
tryOpenWith file cmd = do
_ <- P.createProcess (P.proc cmd [Path.fromAbsFile file]){ P.std_out = P.NoStream, P.std_err = P.NoStream }
return ()

0 comments on commit cdb0424

Please sign in to comment.