From 5fb8b404dc2ab8d865f5dea084bdc741708fdb88 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 26 Jul 2022 23:17:20 -0400 Subject: [PATCH] FIX make program not puke if jmtpfs is not found (even when not needed) --- app/rofi-dev.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/rofi-dev.hs b/app/rofi-dev.hs index 2a268a4..4403a61 100644 --- a/app/rofi-dev.hs +++ b/app/rofi-dev.hs @@ -663,6 +663,9 @@ getRemovableActions = mountableToAction getRemovableDevices -------------------------------------------------------------------------------- -- | MTP devices +mtpExe :: String +mtpExe = "jmtpfs" + data MTPFS = MTPFS { mtpfsBus :: String , mtpfsDevice :: String @@ -675,7 +678,7 @@ instance Mountable MTPFS where mount MTPFS { mtpfsBus = b, mtpfsDevice = n, mtpfsMountpoint = m } False = do -- TODO add autodismount to options let dev = "-device=" ++ b ++ "," ++ n - withTmpMountDir m $ io $ runMount "jmtpfs" [dev, m] "" + withTmpMountDir m $ io $ runMount mtpExe [dev, m] "" mount MTPFS { mtpfsMountpoint = m } True = runAndRemoveDir m $ io $ runMount "umount" [m] "" @@ -692,10 +695,13 @@ instance Mountable MTPFS where -- | Return list of all available MTP devices getMTPDevices :: RofiMountIO [MTPFS] getMTPDevices = do - dir <- asks mountconfVolatilePath - res <- io $ readProcess "jmtpfs" ["-l"] "" - return $ fromLines (toDev dir) $ toDevList res + i <- io mtpExeInstalled + if i then go else return [] where + go = do + dir <- asks mountconfVolatilePath + res <- io $ readProcess mtpExe ["-l"] "" + return $ fromLines (toDev dir) $ toDevList res toDevList = reverse . takeWhile (not . isPrefixOf "Available devices") . reverse @@ -718,6 +724,9 @@ getMTPDevices = do getMTPActions :: RofiMountIO [(Header, ProtoAction [String])] getMTPActions = mountableToAction getMTPDevices +mtpExeInstalled :: IO Bool +mtpExeInstalled = isJust <$> findExecutable mtpExe + instance Actionable MTPFS where fmtEntry d = [getLabel d]