ENH don't ignore ethenet interfaces

This commit is contained in:
Nathan Dwarshuis 2024-01-21 17:02:47 -05:00
parent 8064b01c90
commit 3ab6ccf45b
1 changed files with 18 additions and 9 deletions

View File

@ -468,6 +468,8 @@ data XPFeatures = XPFeatures
, xpfIntelBacklight :: Bool
, xpfClevoBacklight :: Bool
, xpfBattery :: Bool
, xpfEthPrefix :: Maybe Text
, xpfWifiPrefix :: Maybe Text
}
instance FromJSON XPFeatures where
@ -493,6 +495,10 @@ instance FromJSON XPFeatures where
.:+ "clevo_backlight"
<*> o
.:+ "battery"
<*> o
.:? "ethPrefix"
<*> o
.:? "wifiPrefix"
defParams :: XParams
defParams =
@ -515,6 +521,8 @@ defXPFeatures =
, xpfIntelBacklight = False
, xpfClevoBacklight = False
, xpfBattery = False
, xpfEthPrefix = Nothing
, xpfWifiPrefix = Nothing
}
type XPQuery = XPFeatures -> Bool
@ -825,16 +833,16 @@ testFont fam = maybe pass (Left . (: [])) <$> shellTest "fc-list" args msg
-- start with "en" and wireless interfaces always start with "wl"
readEthernet :: IODependency T.Text
readEthernet = readInterface "get ethernet interface" isEthernet
readEthernet = readInterface "get ethernet interface" (fromMaybe "en" . xpfEthPrefix)
readWireless :: IODependency T.Text
readWireless = readInterface "get wireless interface" isWireless
readWireless = readInterface "get wireless interface" (fromMaybe "wl" . xpfWifiPrefix)
isWireless :: T.Text -> Bool
isWireless = T.isPrefixOf "wl"
-- isWireless :: T.Text -> Bool
-- isWireless = T.isPrefixOf "wl"
isEthernet :: T.Text -> Bool
isEthernet = T.isPrefixOf "en"
-- isEthernet :: T.Text -> Bool
-- isEthernet = T.isPrefixOf "en"
listInterfaces :: MonadUnliftIO m => m [T.Text]
listInterfaces =
@ -846,11 +854,12 @@ sysfsNet = "/sys/class/net"
-- ASSUME there are no (non-base) packages required to make these interfaces
-- work (all at the kernel level)
readInterface :: T.Text -> (T.Text -> Bool) -> IODependency T.Text
readInterface :: T.Text -> (XPFeatures -> Text) -> IODependency T.Text
readInterface n f = IORead n [] go
where
go = io $ do
ns <- filter f <$> listInterfaces
go = do
p <- asks (f . xpFeatures . xParams)
ns <- filter (T.isPrefixOf p) <$> listInterfaces
case ns of
[] -> return $ Left [Msg LevelError "no interfaces found"]
(x : xs) -> do