diff options
author | bobtwinkles <srkoser+github@gmail.com> | 2018-10-29 22:04:10 -0400 |
---|---|---|
committer | bobtwinkles <srkoser+github@gmail.com> | 2018-10-29 22:04:10 -0400 |
commit | 51d5535a9b4c513fb96daa2bd8b1bcb71fdebb2f (patch) | |
tree | 5314bb58ca5393e2c50aef6f79befdebff0a8cea | |
parent | 2abc9a8a162de028ec2c0d616182d0c34a54414c (diff) | |
download | xmobar-51d5535a9b4c513fb96daa2bd8b1bcb71fdebb2f.tar.gz xmobar-51d5535a9b4c513fb96daa2bd8b1bcb71fdebb2f.tar.bz2 |
Improved handling of missing thermal zone files
Instead of simply displaying zero when reading the thermal zone file fails,
display whatever we would display when provided with a misconfigured thermal
zone.
-rw-r--r-- | src/Plugins/Monitors/ThermalZone.hs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Plugins/Monitors/ThermalZone.hs b/src/Plugins/Monitors/ThermalZone.hs index 838a7f5..a4744b4 100644 --- a/src/Plugins/Monitors/ThermalZone.hs +++ b/src/Plugins/Monitors/ThermalZone.hs @@ -34,12 +34,16 @@ runThermalZone :: [String] -> Monitor String runThermalZone args = do let zone = head args file = "/sys/class/thermal/thermal_zone" ++ zone ++ "/temp" - handleIOError :: IOException -> IO B.ByteString - handleIOError _ = return (B.pack "-1") + handleIOError :: IOException -> IO (Maybe B.ByteString) + handleIOError _ = return Nothing parse = return . (read :: String -> Int) . B.unpack exists <- io $ fileExist file if exists - then do mdegrees <- io $ catch ( B.readFile file) handleIOError >>= parse - temp <- showWithColors show (mdegrees `quot` 1000) - parseTemplate [ temp ] + then do contents <- io $ catch (fmap Just $ B.readFile file) handleIOError + case contents of + Just d -> do + mdegrees <- parse d + temp <- showWithColors show (mdegrees `quot` 1000) + parseTemplate [ temp ] + Nothing -> getConfigValue naString else getConfigValue naString |