FIX make program not puke if jmtpfs is not found (even when not needed)
This commit is contained in:
parent
2bd8decb52
commit
5fb8b404dc
|
@ -663,6 +663,9 @@ getRemovableActions = mountableToAction getRemovableDevices
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- | MTP devices
|
-- | MTP devices
|
||||||
|
|
||||||
|
mtpExe :: String
|
||||||
|
mtpExe = "jmtpfs"
|
||||||
|
|
||||||
data MTPFS = MTPFS
|
data MTPFS = MTPFS
|
||||||
{ mtpfsBus :: String
|
{ mtpfsBus :: String
|
||||||
, mtpfsDevice :: String
|
, mtpfsDevice :: String
|
||||||
|
@ -675,7 +678,7 @@ instance Mountable MTPFS where
|
||||||
mount MTPFS { mtpfsBus = b, mtpfsDevice = n, mtpfsMountpoint = m } False = do
|
mount MTPFS { mtpfsBus = b, mtpfsDevice = n, mtpfsMountpoint = m } False = do
|
||||||
-- TODO add autodismount to options
|
-- TODO add autodismount to options
|
||||||
let dev = "-device=" ++ b ++ "," ++ n
|
let dev = "-device=" ++ b ++ "," ++ n
|
||||||
withTmpMountDir m $ io $ runMount "jmtpfs" [dev, m] ""
|
withTmpMountDir m $ io $ runMount mtpExe [dev, m] ""
|
||||||
|
|
||||||
mount MTPFS { mtpfsMountpoint = m } True =
|
mount MTPFS { mtpfsMountpoint = m } True =
|
||||||
runAndRemoveDir m $ io $ runMount "umount" [m] ""
|
runAndRemoveDir m $ io $ runMount "umount" [m] ""
|
||||||
|
@ -692,10 +695,13 @@ instance Mountable MTPFS where
|
||||||
-- | Return list of all available MTP devices
|
-- | Return list of all available MTP devices
|
||||||
getMTPDevices :: RofiMountIO [MTPFS]
|
getMTPDevices :: RofiMountIO [MTPFS]
|
||||||
getMTPDevices = do
|
getMTPDevices = do
|
||||||
dir <- asks mountconfVolatilePath
|
i <- io mtpExeInstalled
|
||||||
res <- io $ readProcess "jmtpfs" ["-l"] ""
|
if i then go else return []
|
||||||
return $ fromLines (toDev dir) $ toDevList res
|
|
||||||
where
|
where
|
||||||
|
go = do
|
||||||
|
dir <- asks mountconfVolatilePath
|
||||||
|
res <- io $ readProcess mtpExe ["-l"] ""
|
||||||
|
return $ fromLines (toDev dir) $ toDevList res
|
||||||
toDevList = reverse
|
toDevList = reverse
|
||||||
. takeWhile (not . isPrefixOf "Available devices")
|
. takeWhile (not . isPrefixOf "Available devices")
|
||||||
. reverse
|
. reverse
|
||||||
|
@ -718,6 +724,9 @@ getMTPDevices = do
|
||||||
getMTPActions :: RofiMountIO [(Header, ProtoAction [String])]
|
getMTPActions :: RofiMountIO [(Header, ProtoAction [String])]
|
||||||
getMTPActions = mountableToAction getMTPDevices
|
getMTPActions = mountableToAction getMTPDevices
|
||||||
|
|
||||||
|
mtpExeInstalled :: IO Bool
|
||||||
|
mtpExeInstalled = isJust <$> findExecutable mtpExe
|
||||||
|
|
||||||
instance Actionable MTPFS where
|
instance Actionable MTPFS where
|
||||||
fmtEntry d = [getLabel d]
|
fmtEntry d = [getLabel d]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue