File: Main.hs

package info (click to toggle)
haskell-status-notifier-item 0.3.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 148 kB
  • sloc: haskell: 875; xml: 66; makefile: 6
file content (69 lines) | stat: -rw-r--r-- 1,957 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Main where

import Control.Concurrent.MVar
import Control.Monad
import DBus.Client
import Data.Semigroup ((<>))
import Data.Version (showVersion)
import Options.Applicative
import StatusNotifier.Watcher.Constants
import StatusNotifier.Watcher.Service
import System.Log.DBus.Server
import System.Log.Logger
import Text.Printf

import Paths_status_notifier_item (version)

getWatcherParams :: String -> String -> Priority -> IO WatcherParams
getWatcherParams namespace path priority = do
  logger <- getLogger "StatusNotifier"
  saveGlobalLogger $ setLevel priority logger
  client <- connectSession
  startLogServer client
  return $
    defaultWatcherParams
    { watcherNamespace = namespace
    , watcherPath = path
    , watcherDBusClient = Just client
    }

watcherParamsParser :: Parser (IO WatcherParams)
watcherParamsParser = getWatcherParams
  <$> strOption
  (  long "namespace"
  <> short 'n'
  <> metavar "NAMESPACE"
  <> value "org.kde"
  <> help "The namespace the watcher should register at."
  ) <*> strOption
  (  long "path"
  <> short 'p'
  <> metavar "DBUS-PATH"
  <> value "/StatusNotifierWatcher"
  <> help "The path at which to run the watcher."
  ) <*> option auto
  (  long "log-level"
  <> short 'l'
  <> help "Set the log level"
  <> metavar "LEVEL"
  <> value WARNING
  )

versionOption :: Parser (a -> a)
versionOption = infoOption
                (printf "status-notifier-watcher %s" $ showVersion version)
                (  long "version"
                <> help "Show the version number of gtk-sni-tray"
                )

main :: IO ()
main = do
  watcherParams <- join $ execParser $
                   info (helper <*> versionOption <*> watcherParamsParser)
                   (  fullDesc
                   <> progDesc "Run a StatusNotifierWatcher"
                   )
  stop <- newEmptyMVar
  (_, startWatcher) <- buildWatcher watcherParams { watcherStop = putMVar stop () }
  _ <- startWatcher
  takeMVar stop