haskell-gnome-keyring: GNOME Keyring bindings for Haskell

This library is unmaintained and obsolete.

Code: https://john-millikin.com/code/haskell-gnome-keyring (GitHub mirror)


{-# LANGUAGE OverloadedStrings #-}
import Gnome.Keyring as GK
import System.Glib.Utils as GLib
import System.Glib.MainLoop as GLib
import Control.Monad
import System.Exit

main :: IO ()
main = do
	-- the Keyring sometimes prompts the user for information (passwords,
	-- confirmations, etc); when it does so, the GLib application and
	-- program names will be displayed.
	GLib.setApplicationName "GNOME Keyring example"
	GLib.setProgramName "/path/to/binary"
	-- most keyring operations can be run either synchronously or
	-- asynchronously.
	-- synchronous operations can be run without a main loop
	ok <- GK.available
	when (not ok) $ do
		putStrLn "Can't connect to the Keyring; make sure it's running"
	names <- sync_ listKeyringNames
	putStrLn ("Available keyrings: " ++ show names)
	defName <- sync_ getDefaultKeyring
	putStrLn $ case defName of
		Just name -> "  default: " ++ show name
		_ -> "  no default"
	-- async example: a keyring-enabled Cabal might query a username
	-- and password to use when uploading packages.
	putStrLn "Searching for haskell.com passwords"
	let loc = network
		{ networkProtocol = Just "http"
		, networkDomain = Just "haskell.com"
	async (findNetworkPassword loc)
		(\err -> putStrLn ("  error: " ++ show err))
		(\passwords -> putStrLn ("  found: " ++ show passwords))
	-- async operations require a Glib main loop
	loop <- GLib.mainLoopNew Nothing False
	GLib.timeoutAdd (GLib.mainLoopQuit loop << return False) 500
	GLib.mainLoopRun loop
Change Feed